File size: 11,908 Bytes
7889be9
 
c91ddb9
7889be9
 
 
c91ddb9
7889be9
 
c91ddb9
 
7889be9
 
 
 
 
 
 
 
 
 
 
 
070c708
 
7889be9
 
 
 
32d6c2e
 
 
 
c91ddb9
 
 
32d6c2e
c91ddb9
 
 
32d6c2e
c91ddb9
 
 
 
 
 
 
 
 
 
 
 
 
32d6c2e
c91ddb9
32d6c2e
 
c8b08ef
32d6c2e
c91ddb9
32d6c2e
 
c91ddb9
32d6c2e
 
 
c8b08ef
32d6c2e
c8b08ef
 
 
c91ddb9
c8b08ef
c91ddb9
32d6c2e
 
c8b08ef
32d6c2e
c91ddb9
 
c8b08ef
32d6c2e
c8b08ef
 
32d6c2e
c91ddb9
 
 
 
 
32d6c2e
c8b08ef
32d6c2e
c91ddb9
32d6c2e
c91ddb9
 
 
 
c8b08ef
32d6c2e
 
 
c91ddb9
 
 
 
 
 
32d6c2e
 
c8b08ef
32d6c2e
 
c8b08ef
32d6c2e
 
 
 
c91ddb9
32d6c2e
c8b08ef
32d6c2e
c8b08ef
 
32d6c2e
c91ddb9
 
c8b08ef
c91ddb9
 
 
 
 
 
 
 
32d6c2e
 
c91ddb9
32d6c2e
c8b08ef
 
c91ddb9
c8b08ef
 
c91ddb9
32d6c2e
c8b08ef
c91ddb9
 
 
 
c8b08ef
32d6c2e
c91ddb9
32d6c2e
c8b08ef
 
c91ddb9
32d6c2e
c91ddb9
 
32d6c2e
 
 
 
c8b08ef
32d6c2e
 
c91ddb9
32d6c2e
c8b08ef
32d6c2e
c8b08ef
 
32d6c2e
c91ddb9
c8b08ef
 
c91ddb9
 
 
 
 
 
c8b08ef
32d6c2e
c8b08ef
c91ddb9
32d6c2e
c8b08ef
c91ddb9
c8b08ef
32d6c2e
c91ddb9
c8b08ef
c91ddb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8b08ef
32d6c2e
c8b08ef
c91ddb9
 
 
c8b08ef
32d6c2e
 
 
 
7889be9
 
 
 
 
 
070c708
7889be9
c91ddb9
7889be9
070c708
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE html>
<html lang="vi">
<head><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":"HF_TOKEN_REDACTED","REBUILD_TRIGGER":"FINAL-2025"}};</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>V.AI STUDIO | Niềm tin khách hàng là tài sản của chúng tôi</title>
<meta name="description" content="V.AI STUDIO — 8000+ sản phẩm thiết bị nhà bếp & điện máy.">
<meta property="og:type" content="website">
<meta property="og:site_name" content="V.AI STUDIO">
<meta property="og:title" id="ogTitle" content="V.AI STUDIO">
<meta property="og:description" id="ogDesc" content="8000+ sản phẩm thiết bị nhà bếp & điện máy chính hãng.">
<meta property="og:image" id="ogImage" content="https://huggingface.co/spaces/bep40/V.AISTUDIO/resolve/main/logo/logo_main.png">
<link rel="canonical" id="canonicalUrl" href="https://bep40-v-aistudio.static.hf.space/">
<meta name="twitter:card" content="summary_large_image">
<link rel="icon" href="https://huggingface.co/spaces/bep40/V.AISTUDIO/resolve/main/logo/favicon.png">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<style>
*{margin:0;padding:0;box-sizing:border-box}
:root{--p:#003f62;--pl:#005a8c;--a:#db9815;--al:#f0b840;--d:#0f172a;--l:#f8fafc;--g:#64748b;--gl:#e2e8f0;--w:#fff;--r:14px;--t:all .25s ease}
body{font-family:'Inter',system-ui,sans-serif;color:var(--d);background:var(--l);overflow-x:hidden}
.container{max-width:1360px;margin:0 auto;padding:0 20px}
</style>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/exceljs@4.4.0/dist/exceljs.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>

<script>
(function(){
"use strict";

// ===== BLOB REGISTRY NGAY ======
window.__VAI_EXCEL_BLOB = { blobs: [], isUnload: false };
var REG = window.__VAI_EXCEL_BLOB;

function cleanup() { REG.isUnload = true; REG.blobs.forEach(function(e){ try{URL.revokeObjectURL(e.url);}catch(r){} }); }
window.addEventListener('pagehide', cleanup);
window.addEventListener('beforeunload', cleanup);

// PATCH URL.revokeObjectURL NGAY
if (!window._va_rev_patched) {
    var _rev = URL.revokeObjectURL;
    URL.revokeObjectURL = function(u) {
        if (REG.isUnload) return _rev.call(this, u);
        if (u && typeof u === 'string' && u.indexOf('blob:') === 0) {
            if (!REG.blobs.find(function(e){return e.url===u;})) REG.blobs.push({url:u});
            return;
        }
        return _rev.call(this, u);
    };
    window._va_rev_patched = true;
}

// ===== UTILITIES =====
function dl(blob, name) {
    var url = URL.createObjectURL(blob);
    REG.blobs.push({url:url});
    var a = document.createElement('a');
    a.href = url; a.download = name;
    document.body.appendChild(a);
    a.click();
    setTimeout(function(){ try{document.body.removeChild(a);}catch(r){} }, 100);
}

function fmt(n) { return n && !isNaN(n) ? Number(n).toLocaleString('vi-VN') + 'đ' : '0đ'; }
function strip(s) { return (s||'').normalize('NFD').replace(/[\u0300-\u036f]/g,'').replace(/[Đđ]/g,'D'); }
function genCode(name) {
    var d = new Date(), dd = String(d.getDate()).padStart(2,'0');
    var mm = String(d.getMonth()+1).padStart(2,'0'), yy = String(d.getFullYear()).slice(-2);
    var ini = '';
    if (name && name.trim()) {
        name.trim().split(/\s+/).forEach(function(w){
            if (w) { var c = strip(w.charAt(0)).toUpperCase(); if (/[A-Z]/.test(c)) ini += c; }
        });
    }
    return 'VAS' + (ini||'X') + dd + mm + yy;
}

function getQuoteData() {
    var d = { customer:{name:'',phone:'',email:'',addr:'',date:new Date().toLocaleDateString('vi-VN')}, items:[], grandTotal:0 };
    var cart = window.cart || [], prods = window.D || [];
    cart.forEach(function(item,i){
        var p = prods[item.idx] || (prods.find ? prods.find(function(x){return x.id===item.id;}) : null);
        var pr = item.priceNum || item.price || (p ? p.price : 0) || 0;
        d.items.push({
            stt:i+1, name:p ? (p.name||p.n||'') : (item.name||''),
            model:p ? (p.sku||p.mod||'') : (item.sku||item.model||''),
            qty:item.qty||1, price:pr, discPrice:pr, total:(item.qty||1)*pr
        });
    });
    ['#quoteName','#quoteCustomerName','#checkoutName'].forEach(function(sel){
        var el = document.querySelector(sel);
        if (el && el.value && el.value.trim()) { d.customer.name = el.value.trim(); return; }
    });
    var ph = document.querySelector('#quotePhone,#checkoutPhone');
    if (ph && ph.value) d.customer.phone = ph.value.trim();
    var ad = document.querySelector('#quoteAddr,#checkoutAddr');
    if (ad && ad.value) d.customer.addr = ad.value.trim();
    d.grandTotal = d.items.reduce(function(s,i){return s+(i.total||0);},0);
    return d;
}

// ===== EXPORT FUNCTIONS =====
window.VAI_DO_EXCEL = async function() {
    var qd = getQuoteData(), code = genCode(qd.customer.name || '');
    if (!qd.items.length) { alert('⚠️ Giỏ trống'); return; }
    if (typeof ExcelJS === 'undefined') { alert('⚠️ Chưa có ExcelJS'); return; }
    
    try {
        var wb = new ExcelJS.Workbook(), ws = wb.addWorksheet('Báo giá');
        ws.views = [{showGridLines:false}];
        ws.columns = [{width:5},{width:11},{width:28},{width:13},{width:20},{width:6},{width:13},{width:13},{width:15},{width:14}];
        ws.mergeCells('A3:J3'); ws.getCell('A3').value = 'BẢNG BÁO GIÁ';
        ws.getCell('A3').font = {bold:true,size:18,color:{argb:'FFDB9815'}};
        ws.getCell('A5').value = 'Khách hàng:'; ws.mergeCells('B5:E5'); ws.getCell('B5').value = qd.customer.name;
        ws.getCell('H5').value = 'Mã đơn:'; ws.mergeCells('I5:J5'); ws.getCell('I5').value = code;
        ws.getCell('A6').value = 'SĐT:'; ws.mergeCells('B6:E6'); ws.getCell('B6').value = qd.customer.phone;
        ws.getCell('A8').value = 'Địa chỉ:'; ws.mergeCells('B8:J8'); ws.getCell('B8').value = qd.customer.addr;
        
        var hr = ws.getRow(10);
        ['STT','Hình','Tên sản phẩm','Mã SP','Thông tin','SL','Đơn giá','Giá CK','Thành tiền','Ghi chú'].forEach(function(h,i){
            var c = hr.getCell(i+1); c.value = h;
            c.font = {bold:true,color:{argb:'FFFFFFFF'}};
            c.fill = {type:'pattern',pattern:'solid',fgColor:{argb:'FF003F62'}};
        });
        
        var cr = 11, first = cr;
        qd.items.forEach(function(it){
            var r = ws.getRow(cr); r.height = 50;
            r.getCell(1).value = it.stt;
            r.getCell(3).value = it.name; r.getCell(3).font = {bold:true};
            r.getCell(4).value = it.model;
            r.getCell(6).value = Number(it.qty); r.getCell(6).numFmt = '#,##0';
            r.getCell(7).value = Number(it.price); r.getCell(7).numFmt = '#,##0"đ"';
            r.getCell(8).value = Number(it.discPrice); r.getCell(8).numFmt = '#,##0"đ"';
            r.getCell(9).value = Number(it.total); r.getCell(9).numFmt = '#,##0"đ"';
            cr++;
        });
        
        ws.getRow(cr).height = 28; ws.mergeCells(cr,1,cr,5); ws.getCell('A'+cr).value = 'TỔNG CỘNG';
        ws.getCell('A'+cr).font = {bold:true};
        ws.getCell('A'+cr).fill = {type:'pattern',pattern:'solid',fgColor:{argb:'FF003F62'}};
        ws.getCell('E'+cr).value = {formula:'SUM(I'+first+':I'+(cr-1)+')',result:qd.grandTotal};
        ws.getCell('E'+cr).numFmt = '#,##0"đ"';
        wb.calcProperties.fullCalcOnLoad = true;
        
        var buf = await wb.xlsx.writeBuffer();
        dl(new Blob([buf],{type:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}), code + '.xlsx');
        if (typeof showToast === 'function') showToast('✅ Excel OK');
    } catch(e) {
        alert('❌ Lỗi: ' + e.message);
    }
};

window.VAI_DO_GH = async function() {
    var order = window.VAI_CURRENT_ORDER;
    var qd = order && order.items ? { customer:{name:order.customer||'',phone:order.phone||'',addr:order.addr||''}, items:order.items.map(function(it,i){
        return { stt:i+1, name:it.name||'', model:it.model||'', qty:it.qty||1, note:it.note||'' };
    }) } : getQuoteData();
    var code = genCode(qd.customer.name || '');
    if (typeof ExcelJS === 'undefined') return;
    
    try {
        var wb = new ExcelJS.Workbook(), ws = wb.addWorksheet('Giao hàng');
        ws.columns = [{width:5},{width:34},{width:14},{width:8},{width:20}];
        ws.mergeCells('A1:E1'); ws.getCell('A1').value = 'PHIẾU GIAO HÀNG';
        ws.getCell('A1').font = {bold:true,size:16};
        ws.getCell('A2').value = 'KH: ' + qd.customer.name;
        ws.getCell('D2').value = 'Mã: ' + code;
        
        var hr = ws.getRow(6);
        ['STT','Tên sản phẩm','Mã SP','SL','Ghi chú'].forEach(function(h,i){
            var c = hr.getCell(i+1); c.value = h;
            c.font = {bold:true,color:{argb:'FFFFFFFF'}};
            c.fill = {type:'pattern',pattern:'solid',fgColor:{argb:'FF003F62'}};
        });
        
        var cr = 7, tq = 0;
        qd.items.forEach(function(it){
            var r = ws.getRow(cr);
            r.getCell(1).value = it.stt;
            r.getCell(2).value = it.name;
            r.getCell(3).value = it.model;
            r.getCell(4).value = it.qty;
            r.getCell(5).value = it.note;
            tq += Number(it.qty); cr++;
        });
        ws.mergeCells(cr,1,cr,3); ws.getCell('A'+cr).value = 'TỔNG CỘNG SỐ LƯỢNG'; ws.getCell('D'+cr).value = tq;
        
        var buf = await wb.xlsx.writeBuffer();
        dl(new Blob([buf],{type:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}), 'GH-' + code + '.xlsx');
    } catch(e){}
};

// ===== UNIVERSAL CLICK HANDLER =====
(function(){
    function handleExcelClick(e) {
        var el = e.target;
        // Bắt mọi element - không chỉ button
        while (el && el !== document) {
            var txt = (el.textContent || el.innerText || '').toLowerCase();
            
            // EXCEL BÁO GIÁ
            if (txt.includes('excel') && !txt.includes('giao') && !txt.includes('gh-')) {
                e.preventDefault(); e.stopImmediatePropagation();
                // Set loading state
                var orig = el.innerHTML;
                el.innerHTML = '<span style="opacity:0.7">⏳</span>';
                // Call export
                window.VAI_DO_EXCEL().then(function(){ el.innerHTML = orig; });
                return false;
            }
            
            // GH EXCEL  
            if ((txt.includes('giao hàng') || txt.includes('gh')) && txt.includes('excel')) {
                e.preventDefault(); e.stopImmediatePropagation();
                var orig2 = el.innerHTML;
                el.innerHTML = '<span style="opacity:0.7">⏳</span>';
                window.VAI_DO_GH().then(function(){ el.innerHTML = orig2; });
                return false;
            }
            
            el = el.parentElement;
        }
    }
    
    // GÁN CLICK HANDLER NGAY LẬP TỨC
    document.addEventListener('click', handleExcelClick, true);
    console.log('[VAI EXCEL] UNIVERSAL CLICK HANDLER ACTIVE');
})();

})();
</script>

<div class="topbar"><div class="container">
<div class="topbar-item"><i class="fas fa-truck-fast"></i> Miễn phí vận chuyển</div>
<div class="topbar-item"><i class="fas fa-shield-halved"></i> Bảo hành chính hãng</div>
<div class="topbar-item"><i class="fas fa-headset"></i> Hỗ trợ 24/7</div>
</div></div>

<div id="app"></div>

<script>console.log('[V.AI STUDIO] App loading...');</script>
</body>
</html>