File size: 14,402 Bytes
7889be9
 
32d6c2e
7889be9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
070c708
 
32d6c2e
7889be9
 
 
 
32d6c2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7889be9
 
 
 
 
 
070c708
 
7889be9
 
070c708
 
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<!DOCTYPE html>
<html lang="vi">
<head><script>window.huggingface={variables:{"SPACE_CREATOR_USER_ID":"661b9191e7b0ab12bceb66f3","VAISTUDIO":"HF_TOKEN_REDACTED","REBUILD_TRIGGER":"INLINE"}};</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. Malloca, Eurogold, Grob, Canzy, Demax & Điện Máy Xanh chính hãng.">
<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 | Niềm tin khách hàng là tài sản của chúng tôi">
<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. Malloca, Eurogold, Grob, Canzy, Demax & Điện Máy Xanh.">
<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 property="og:url" id="ogUrl" content="https://bep40-v-aistudio.static.hf.space/">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" id="twTitle" content="V.AI STUDIO">
<meta name="twitter:description" id="twDesc" content="8000+ sản phẩm thiết bị nhà bếp & điện máy chính hãng">
<meta name="twitter:image" id="twImage" content="https://huggingface.co/spaces/bep40/V.AISTUDIO/resolve/main/logo/logo_main.png">
<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}
::-webkit-scrollbar{width:6px}::-webkit-scrollbar-thumb{background:var(--p);border-radius:3px}
img{max-width:100%;display:block}a{text-decoration:none;color:inherit}
.container{max-width:1360px;margin:0 auto;padding:0 20px}
</style>
</head>
<body>
<!-- Libraries for quotation export -->
<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>

<!-- V.AI STUDIO Excel Multi-Download Fix (INLINE - tránh cache CDN) -->
<script>
(function(){
"use strict";

// Registry toàn cục
window.__VAI_BLOB_REG = window.__VAI_BLOB_REG || { blobs: [], isUnloading: false };
var REG = window.__VAI_BLOB_REG;

// Cleanup khi unload
function cleanup() {
    REG.isUnloading = true;
    REG.blobs.forEach(function(e) {
        if (!e.revoked && e.url) { try { URL.revokeObjectURL(e.url); e.revoked = true; } catch(err) {} }
    });
    REG.blobs = [];
}
window.addEventListener('pagehide', cleanup);
window.addEventListener('beforeunload', cleanup);
window.addEventListener('unload', cleanup);

// PATCH URL.revokeObjectURL - KHÔNG REVOKE BLOB
if (!window.__VAI_REVOKE_PATCHED) {
    var _orig = URL.revokeObjectURL;
    URL.revokeObjectURL = function(url) {
        if (REG.isUnloading) return _orig.call(this, url);
        if (!url || typeof url !== 'string' || !url.startsWith('blob:')) {
            return _orig.call(this, url);
        }
        var exists = REG.blobs.find(function(e) { return e.url === url; });
        if (!exists) REG.blobs.push({ url: url, revoked: false });
        return;
    };
    window.__VAI_REVOKE_PATCHED = true;
    console.log('[VAI] REVOKE PATCHED - Multi-download ENABLED');
}

function dl(blob, name) {
    var url = URL.createObjectURL(blob);
    REG.blobs.push({ url: url, revoked: false });
    var a = document.createElement('a');
    a.href = url;
    a.download = name;
    a.style.cssText = 'position:absolute;left:-9999px';
    document.body.appendChild(a);
    a.click();
    setTimeout(function() { try { document.body.removeChild(a); } catch(err) {} }, 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');
    var yy = String(d.getFullYear()).slice(-2), 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 setBtn(b, exporting) {
    if (exporting) {
        b.disabled = true;
        b.dataset.vaiExporting = '1';
        b.dataset.vaiOrig = b.innerHTML;
        b.innerHTML = '<span style="opacity:0.7">⏳</span>';
    } else {
        b.disabled = false;
        b.dataset.vaiExporting = '0';
        b.dataset.vaiOrig && (b.innerHTML = b.dataset.vaiOrig);
    }
}

function getQD() {
    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 em = document.querySelector('#quoteEmail'); if (em && em.value) d.customer.email = em.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;
}

async function exportExcel() {
    var qd = getQD(), code = genCode(qd.customer.name || '');
    if (!qd.items.length || typeof ExcelJS === 'undefined') {
        alert(!qd.items.length ? '⚠️ Không có sản phẩm' : '⚠️ 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('H6').value = 'Ngày:'; ws.mergeCells('I6:J6'); ws.getCell('I6').value = qd.customer.date;
        ws.getCell('A7').value = 'Email:'; ws.mergeCells('B7:E7'); ws.getCell('B7').value = qd.customer.email;
        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, firstRow = cr;
        qd.items.forEach(function(it) {
            var row = ws.getRow(cr); row.height = 50;
            var bg = (cr - 11) % 2 === 0 ? 'FFF8FAFC' : 'FFFFFFFF';
            row.getCell(1).value = it.stt;
            row.getCell(3).value = it.name; row.getCell(3).font = { bold: true };
            row.getCell(4).value = it.model;
            row.getCell(5).value = it.specs;
            row.getCell(6).value = Number(it.qty); row.getCell(6).numFmt = '#,##0';
            row.getCell(7).value = Number(it.price); row.getCell(7).numFmt = '#,##0"đ"';
            row.getCell(8).value = Number(it.discPrice); row.getCell(8).numFmt = '#,##0"đ"';
            row.getCell(9).value = Number(it.total); row.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, color: { argb: 'FFFFFFFF' } };
        ws.getCell('A'+cr).fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FF003F62' } };
        ws.getCell('E'+cr).value = { formula: 'SUM(I'+firstRow+':I'+(cr-1)+')', result: qd.grandTotal };
        ws.getCell('E'+cr).numFmt = '#,##0"đ"'; wb.calcProperties.fullCalcOnLoad = true;
        
        var buf = await wb.xlsx.writeBuffer();
        var blob = new Blob([buf], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
        dl(blob, code + '.xlsx');
        if (typeof showToast === 'function') showToast('✅ Excel tải thành công!');
    } catch(err) {
        alert('❌ Lỗi: ' + err.message);
    }
}

async function exportDelivery() {
    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 || '', price: it.price || 0, discPrice: it.discPrice || it.price || 0 };
    }) } : getQD();
    var code = genCode(qd.customer.name || '');
    
    if (typeof ExcelJS === 'undefined' || !qd.items.length) return;
    try {
        var wb = new ExcelJS.Workbook(), ws = wb.addWorksheet('Giao hàng');
        ws.views = [{ showGridLines: false }];
        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, totalQty = 0;
        qd.items.forEach(function(it) {
            var row = ws.getRow(cr);
            row.getCell(1).value = it.stt;
            row.getCell(2).value = it.name;
            row.getCell(3).value = it.model;
            row.getCell(4).value = it.qty;
            row.getCell(5).value = it.note;
            totalQty += 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 = totalQty;
        
        var buf = await wb.xlsx.writeBuffer();
        var blob = new Blob([buf], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
        dl(blob, 'GH-' + code + '.xlsx');
        if (typeof showToast === 'function') showToast('✅ Excel giao hàng tải thành công!');
    } catch(err) {}
}

function clickHdl(e) {
    var btn = e.target.closest('button, a');
    if (!btn) return;
    var txt = (btn.textContent || '').toLowerCase();
    
    if (txt.includes('excel') && !txt.includes('giao') && !txt.includes('gh-')) {
        e.preventDefault(); e.stopPropagation();
        if (btn.dataset.vaiExporting === '1') return;
        setBtn(btn, true);
        exportExcel().finally(function() { setBtn(btn, false); });
        return false;
    }
    if ((txt.includes('giao hàng') || txt.includes('gh')) && txt.includes('excel')) {
        e.preventDefault(); e.stopPropagation();
        if (btn.dataset.vaiExporting === '1') return;
        setBtn(btn, true);
        exportDelivery().finally(function() { setBtn(btn, false); });
        return false;
    }
}

function init() {
    document.removeEventListener('click', clickHdl, true);
    document.addEventListener('click', clickHdl, true);
    console.log('[VAI INLINE v2] EXCEL MULTI-DOWNLOAD ACTIVE');
}

if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', init);
} else { init(); }
setTimeout(init, 2000);
setTimeout(init, 5000);

window.VAI_EXCEL = { init, exportExcel, exportDelivery };
})();
</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>

<!-- MAIN APP WILL BE INJECTED HERE -->
<div id="app"></div>

<script>
// Minimal stub for testing - full app script continues
console.log('[V.AI STUDIO] App loading...');
</script>
</body>
</html>