Spaces:
Running
Running
Add big_sale.js with BIG SALE floating promotion module (23 products)
Browse files- big_sale.js +237 -188
big_sale.js
CHANGED
|
@@ -1,215 +1,264 @@
|
|
| 1 |
-
// BIG SALE Floating Promotion
|
| 2 |
-
//
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
const BIG_SALE_PRODUCTS = [
|
| 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 |
-
button.className = 'big-sale-floating';
|
| 49 |
-
button.setAttribute('aria-label', 'Mở chương trình BIG SALE');
|
| 50 |
-
button.setAttribute('title', 'BIG SALE - Khuyến mãi hot');
|
| 51 |
-
button.innerHTML =
|
| 52 |
-
'<span class="big-sale-badge">BIG SALE</span>' +
|
| 53 |
-
'<span class="big-sale-title">BIG SALE</span>' +
|
| 54 |
-
'<span class="big-sale-count">' + BIG_SALE_PRODUCTS.length + ' sản phẩm</span>';
|
| 55 |
-
return button;
|
| 56 |
-
}
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
'<line x1="6" y1="6" x2="18" y2="18"></line>' +
|
| 70 |
-
'</svg>' +
|
| 71 |
-
'</button>' +
|
| 72 |
-
'</div>' +
|
| 73 |
-
'<div class="big-sale-products" id="bigSaleProducts"></div>';
|
| 74 |
-
return panel;
|
| 75 |
-
}
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
'<div class="big-sale-product" onclick="window.openBigSaleProduct(' + stt + ')">' +
|
| 97 |
-
'<div class="big-sale-product-info">' +
|
| 98 |
-
'<div class="big-sale-product-name">' + tenSp + '</div>' +
|
| 99 |
-
'<div class="big-sale-product-code">Mã: ' + maSp + '</div>' +
|
| 100 |
-
'<div class="big-sale-product-meta">' +
|
| 101 |
-
'<span class="big-sale-new-badge">SL: ' + sl + '</span>' +
|
| 102 |
-
'<span class="big-sale-new-badge">' + tinhTrang + '</span>' +
|
| 103 |
-
'</div>' +
|
| 104 |
-
'</div>' +
|
| 105 |
-
'<div class="big-sale-product-price-container">' +
|
| 106 |
-
'<div class="big-sale-product-bigprice">' + originalPrice + '</div>' +
|
| 107 |
-
'<div class="big-sale-product-price">' + bigSalePrice + '</div>' +
|
| 108 |
-
'<span class="big-sale-product-discount">' + chietKhau + '% OFF</span>' +
|
| 109 |
-
'</div>' +
|
| 110 |
-
'</div>';
|
| 111 |
-
});
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
var product = BIG_SALE_PRODUCTS.find(function(p) { return p[0] === stt; });
|
| 119 |
-
if (!product) return;
|
| 120 |
-
|
| 121 |
-
var maSp = product[1];
|
| 122 |
-
var tenSp = product[2];
|
| 123 |
-
var sl = product[3];
|
| 124 |
-
var giaBan = product[4];
|
| 125 |
-
var chietKhau = product[5];
|
| 126 |
-
var giaBigSale = product[6];
|
| 127 |
-
var tinhTrang = product[7];
|
| 128 |
-
var originalPrice = formatVND(giaBan);
|
| 129 |
-
var bigSalePrice = formatVND(giaBigSale);
|
| 130 |
-
|
| 131 |
-
// Try to use existing vaistudio detail modal
|
| 132 |
-
var detailOverlay = document.getElementById('vaistudio-detail-overlay');
|
| 133 |
-
if (detailOverlay) {
|
| 134 |
-
document.getElementById('detail-title').textContent = tenSp;
|
| 135 |
-
document.getElementById('detail-brand').textContent = maSp;
|
| 136 |
-
document.getElementById('detail-model').textContent = tinhTrang;
|
| 137 |
-
document.getElementById('detail-price').innerHTML =
|
| 138 |
-
'<div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap">' +
|
| 139 |
-
'<span style="color:#c2410c;font-size:1.2rem;font-weight:800">' + bigSalePrice + '</span>' +
|
| 140 |
-
'<span style="font-size:0.7rem;background:#fee2e2;color:#dc2626;padding:2px 8px;border-radius:8px;font-weight:600">-' + chietKhau + '%</span>' +
|
| 141 |
-
'</div>' +
|
| 142 |
-
'<div style="font-size:0.7rem;text-decoration:line-through;color:#64748b;margin-top:2px">' + originalPrice + '</div>';
|
| 143 |
-
detailOverlay.style.display = 'flex';
|
| 144 |
-
return;
|
| 145 |
-
}
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
'Giá gốc: ' + originalPrice + '\n' +
|
| 151 |
-
'Giá BIG SALE: ' + bigSalePrice + '\n' +
|
| 152 |
-
'Chiết khấu: ' + chietKhau + '%\n' +
|
| 153 |
-
'Số lượng: ' + sl + '\n' +
|
| 154 |
-
'Tình trạng: ' + tinhTrang
|
| 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 |
if (document.readyState === 'loading') {
|
| 211 |
-
document.addEventListener('DOMContentLoaded', initBigSale);
|
| 212 |
} else {
|
| 213 |
initBigSale();
|
| 214 |
}
|
| 215 |
-
}
|
|
|
|
|
|
|
|
|
| 1 |
+
// BIG SALE Floating Promotion Module v1.0
|
| 2 |
+
// Integrates BIG SALE promotion button with product detail modal
|
| 3 |
+
// Compatible with bep40/vai-avatar2 space architecture
|
| 4 |
|
| 5 |
+
console.log('[BIG SALE] Module loaded (v1.0)');
|
| 6 |
+
|
| 7 |
+
// BIG SALE Product Data — 23 products with discount info
|
| 8 |
const BIG_SALE_PRODUCTS = [
|
| 9 |
+
{ stt: 1, code: "MC-7086HS", name: "MÁY HÚT", category: "MÁY HÚT", qty: 3, price: "11.389.000", discount: "55%", bigsale: "5.125.050", status: "HÀNG MỚI" },
|
| 10 |
+
{ stt: 2, code: "MH-70SMC", name: "MÁY HÚT ECO", category: "MÁY HÚT", qty: 2, price: "4.620.000", discount: "60%", bigsale: "1.848.000", status: "HÀNG MỚI" },
|
| 11 |
+
{ stt: 3, code: "MH-90SMC", name: "MÁY HÚT ECO", category: "MÁY HÚT", qty: 4, price: "5.060.000", discount: "60%", bigsale: "2.024.000", status: "HÀNG MỚI" },
|
| 12 |
+
{ stt: 4, code: "MH-600GT", name: "MÁY HÚT", category: "MÁY HÚT", qty: 5, price: "8.208.000", discount: "50%", bigsale: "4.104.000", status: "HÀNG MỚI" },
|
| 13 |
+
{ stt: 5, code: "AS-9602DG", name: "BẾP 2 GAS", category: "BẾP GAS", qty: 2, price: "7.815.000", discount: "50%", bigsale: "3.907.500", status: "HÀNG MỚI" },
|
| 14 |
+
{ stt: 6, code: "SMART K-450",name: "CHẬU ĐÁ", category: "CHẬU ĐÁ", qty: 1, price: "21.109.000", discount: "55%", bigsale: "9.499.050", status: "HÀNG MỚI" },
|
| 15 |
+
{ stt: 7, code: "MS-1022D", name: "CHẬU RỰA", category: "CHẬU RỰA", qty: 4, price: "5.852.000", discount: "50%", bigsale: "2.926.000", status: "HÀNG MỚI" },
|
| 16 |
+
{ stt: 8, code: "MS-2025", name: "CHẬU RỰA", category: "CHẬU RỰA", qty: 1, price: "5.700.000", discount: "55%", bigsale: "2.565.000", status: "HÀNG MỚI" },
|
| 17 |
+
{ stt: 9, code: "MS-6070", name: "CHẬU RỰA", category: "CHẬU RỰA", qty: 11, price: "6.464.000", discount: "50%", bigsale: "3.232.000", status: "HÀNG MỚI" },
|
| 18 |
+
{ stt: 10, code: "MS-5066W", name: "CHẬU RỰA", category: "CHẬU RỰA", qty: 8, price: "4.385.000", discount: "50%", bigsale: "2.192.500", status: "HÀNG MỚI" },
|
| 19 |
+
{ stt: 11, code: "MS-5082W", name: "CHẬU RỰA", category: "CHẬU RỰA", qty: 3, price: "6.350.000", discount: "50%", bigsale: "3.175.000", status: "HÀNG MỚI" },
|
| 20 |
+
{ stt: 12, code: "MS-862", name: "CHẬU RỰA", category: "CHẬU RỰA", qty: 3, price: "12.960.000", discount: "55%", bigsale: "5.832.000", status: "HÀNG MỚI" },
|
| 21 |
+
{ stt: 13, code: "MPC-5KCB", name: "BỘ LỌC NƯỚC", category: "LỌC NƯỚC", qty: 1, price: "10.702.000", discount: "50%", bigsale: "5.351.000", status: "HÀNG MỚI" },
|
| 22 |
+
{ stt: 14, code: "K061S", name: "VÒI", category: "VÒI", qty: 10, price: "3.056.000", discount: "50%", bigsale: "1.528.000", status: "HÀNG MỚI" },
|
| 23 |
+
{ stt: 15, code: "K569SN", name: "VÒI ECO", category: "VÒI", qty: 2, price: "3.520.000", discount: "55%", bigsale: "1.584.000", status: "HÀNG MỚI" },
|
| 24 |
+
{ stt: 16, code: "K525B", name: "VÒI", category: "VÒI", qty: 2, price: "2.916.000", discount: "55%", bigsale: "1.312.200", status: "HÀNG MỚI" },
|
| 25 |
+
{ stt: 17, code: "K130S", name: "VÒI", category: "VÒI", qty: 4, price: "4.104.000", discount: "55%", bigsale: "1.846.800", status: "HÀNG MỚI" },
|
| 26 |
+
{ stt: 18, code: "K136A", name: "VÒI", category: "VÒI", qty: 2, price: "2.430.000", discount: "55%", bigsale: "1.093.500", status: "HÀNG MỚI" },
|
| 27 |
+
{ stt: 19, code: "K501B", name: "VÒI", category: "VÒI", qty: 2, price: "5.076.000", discount: "55%", bigsale: "2.284.200", status: "HÀNG MỚI" },
|
| 28 |
+
{ stt: 20, code: "MST-6667", name: "LÓT NỒI", category: "PHỤ KIỆN", qty: 25, price: "255.000", discount: "70%", bigsale: "76.500", status: "HÀNG MỚI" },
|
| 29 |
+
{ stt: 21, code: "MMPM-657A", name: "XAY TIÊU", category: "PHỤ KIỆN", qty: 34, price: "295.000", discount: "70%", bigsale: "88.500", status: "HÀNG MỚI" },
|
| 30 |
+
{ stt: 22, code: "MOVS-10128",name: "BỘ ĐỰNG DẦU", category: "PHỤ KIỆN", qty: 2, price: "491.000", discount: "70%", bigsale: "147.300", status: "HÀNG MỚI" },
|
| 31 |
+
{ stt: 23, code: "BỘ LÀM SẠCH NHÀ BẾP", name: "BỘ LÀM SẠCH NHÀ BẾP", category: "PHỤ KIỆN", qty: 8, price: "720.000", discount: "70%", bigsale: "216.000", status: "HÀNG MỚI" }
|
| 32 |
];
|
| 33 |
|
| 34 |
+
// Format VND currency
|
| 35 |
+
function formatVND(price) {
|
| 36 |
+
const num = parseInt(price.replace(/\./g, ''));
|
| 37 |
+
if (isNaN(num)) return price;
|
| 38 |
+
return new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' }).format(num);
|
| 39 |
+
}
|
| 40 |
|
| 41 |
+
// Build a product card HTML string
|
| 42 |
+
function buildProductCard(p) {
|
| 43 |
+
const discountClass = p.discount.includes('7') ? 'discount-high' : 'discount-mid';
|
| 44 |
+
return `
|
| 45 |
+
<div class="big-sale-product" data-code="${p.code}" data-stt="${p.stt}">
|
| 46 |
+
<div class="big-sale-product-header">
|
| 47 |
+
<span class="big-sale-stt">S${p.stt}</span>
|
| 48 |
+
<span class="big-sale-discount ${discountClass}">-${p.discount}</span>
|
| 49 |
+
</div>
|
| 50 |
+
<div class="big-sale-product-name">${p.name}</div>
|
| 51 |
+
<div class="big-sale-product-code">${p.code}</div>
|
| 52 |
+
<div class="big-sale-product-meta">
|
| 53 |
+
<span class="big-sale-qty">SL: ${p.qty}</span>
|
| 54 |
+
<span class="big-sale-status">HÀNG MỚI</span>
|
| 55 |
+
</div>
|
| 56 |
+
<div class="big-sale-price-row">
|
| 57 |
+
<span class="big-sale-price-original">${formatVND(p.price)}</span>
|
| 58 |
+
<span class="big-sale-price-new">${formatVND(p.bigsale)}</span>
|
| 59 |
+
</div>
|
| 60 |
+
</div>`;
|
| 61 |
+
}
|
| 62 |
|
| 63 |
+
// Create the floating button + panel
|
| 64 |
+
function createBigSaleElements() {
|
| 65 |
+
// Check if already exists
|
| 66 |
+
if (document.getElementById('big-sale-floating')) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
const floating = document.createElement('button');
|
| 69 |
+
floating.id = 'big-sale-floating';
|
| 70 |
+
floating.setAttribute('aria-label', 'Chương trình BIG SALE');
|
| 71 |
+
floating.setAttribute('title', 'Chương trình BIG SALE');
|
| 72 |
+
floating.innerHTML = `
|
| 73 |
+
<div class="big-sale-btn-content">
|
| 74 |
+
<span class="big-sale-badge">BIG SALE</span>
|
| 75 |
+
<span class="big-sale-count">${BIG_SALE_PRODUCTS.length} SP</span>
|
| 76 |
+
</div>
|
| 77 |
+
<div class="big-sale-chevron">▼</div>
|
| 78 |
+
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
const panel = document.createElement('div');
|
| 81 |
+
panel.id = 'big-sale-panel';
|
| 82 |
+
panel.setAttribute('role', 'dialog');
|
| 83 |
+
panel.setAttribute('aria-label', 'Chương trình khuyến mãi BIG SALE');
|
| 84 |
+
panel.innerHTML = `
|
| 85 |
+
<div class="big-sale-panel-header">
|
| 86 |
+
<div class="big-sale-panel-title">
|
| 87 |
+
<span class="big-sale-panel-icon">🔥</span>
|
| 88 |
+
<span>CHƯƠNG TRÌNH BIG SALE</span>
|
| 89 |
+
</div>
|
| 90 |
+
<span class="big-sale-product-count">${BIG_SALE_PRODUCTS.length} sản phẩm</span>
|
| 91 |
+
</div>
|
| 92 |
+
<div class="big-sale-product-list">
|
| 93 |
+
${BIG_SALE_PRODUCTS.map(p => buildProductCard(p)).join('')}
|
| 94 |
+
</div>
|
| 95 |
+
<div class="big-sale-panel-footer">
|
| 96 |
+
<button class="big-sale-view-all-btn">Xem tất cả sản phẩm</button>
|
| 97 |
+
</div>
|
| 98 |
+
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
document.body.appendChild(floating);
|
| 101 |
+
document.body.appendChild(panel);
|
| 102 |
|
| 103 |
+
attachBigSaleEventListeners(floating, panel);
|
| 104 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
+
// Event listeners
|
| 107 |
+
function attachBigSaleEventListeners(floating, panel) {
|
| 108 |
+
let isOpen = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
floating.addEventListener('click', function(e) {
|
| 111 |
+
e.stopPropagation();
|
| 112 |
+
isOpen = !isOpen;
|
| 113 |
+
panel.classList.toggle('open', isOpen);
|
| 114 |
+
floating.classList.toggle('open', isOpen);
|
| 115 |
+
});
|
| 116 |
|
| 117 |
+
// Close when clicking outside
|
| 118 |
+
document.addEventListener('click', function(e) {
|
| 119 |
+
if (isOpen && !panel.contains(e.target) && !floating.contains(e.target)) {
|
| 120 |
+
panel.classList.remove('open');
|
| 121 |
+
floating.classList.remove('open');
|
| 122 |
+
isOpen = false;
|
| 123 |
+
}
|
| 124 |
+
});
|
| 125 |
|
| 126 |
+
// Product click → open detail modal
|
| 127 |
+
const products = panel.querySelectorAll('.big-sale-product');
|
| 128 |
+
products.forEach(card => {
|
| 129 |
+
card.addEventListener('click', function(e) {
|
| 130 |
+
e.stopPropagation();
|
| 131 |
+
const stt = parseInt(this.getAttribute('data-stt'));
|
| 132 |
+
const product = BIG_SALE_PRODUCTS.find(p => p.stt === stt);
|
| 133 |
+
if (product) {
|
| 134 |
+
openBigSaleDetail(product);
|
| 135 |
+
}
|
| 136 |
+
});
|
| 137 |
+
});
|
| 138 |
|
| 139 |
+
// "Xem tất cả" button
|
| 140 |
+
const viewAllBtn = panel.querySelector('.big-sale-view-all-btn');
|
| 141 |
+
if (viewAllBtn) {
|
| 142 |
+
viewAllBtn.addEventListener('click', function(e) {
|
| 143 |
+
e.stopPropagation();
|
| 144 |
+
closeBigSalePanel();
|
| 145 |
+
if (window.vaistudioToggle && typeof window.vaistudioToggle === 'function') {
|
| 146 |
+
window.vaistudioToggle();
|
| 147 |
+
} else {
|
| 148 |
+
const toggle = document.getElementById('vaistudio-toggle');
|
| 149 |
+
if (toggle) toggle.click();
|
| 150 |
+
}
|
| 151 |
+
});
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
|
| 155 |
+
// Open vaistudio detail modal with BIG SALE product info
|
| 156 |
+
function openBigSaleDetail(product) {
|
| 157 |
+
const overlay = document.getElementById('vaistudio-detail-overlay');
|
| 158 |
+
const modal = document.getElementById('vaistudio-detail-modal');
|
| 159 |
+
if (!overlay || !modal) return;
|
| 160 |
|
| 161 |
+
// Set product title and code
|
| 162 |
+
const titleEl = document.getElementById('detail-title');
|
| 163 |
+
const modelEl = document.getElementById('detail-model');
|
| 164 |
+
const brandEl = document.getElementById('detail-brand');
|
| 165 |
+
const priceEl = document.getElementById('detail-price');
|
| 166 |
|
| 167 |
+
if (titleEl) titleEl.textContent = product.name;
|
| 168 |
+
if (modelEl) modelEl.textContent = `Mã: ${product.code}`;
|
| 169 |
+
if (brandEl) {
|
| 170 |
+
brandEl.textContent = product.category;
|
| 171 |
+
brandEl.style.background = '#fff1f2';
|
| 172 |
+
brandEl.style.color = '#e11d48';
|
| 173 |
+
}
|
| 174 |
+
if (priceEl) {
|
| 175 |
+
priceEl.innerHTML = `
|
| 176 |
+
<div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap">
|
| 177 |
+
<span style="color:#c2410c">${formatVND(product.bigsale)}</span>
|
| 178 |
+
<span style="font-size:0.8rem;color:#64748b;text-decoration:line-through">${formatVND(product.price)}</span>
|
| 179 |
+
<span style="font-size:0.85rem;background:#fef3c7;color:#92400e;padding:4px 10px;border-radius:8px;font-weight:700">-${product.discount}</span>
|
| 180 |
+
</div>
|
| 181 |
+
`;
|
| 182 |
+
}
|
| 183 |
|
| 184 |
+
// Set images (show placeholder with category emoji)
|
| 185 |
+
const imagesEl = document.getElementById('detail-images');
|
| 186 |
+
if (imagesEl) {
|
| 187 |
+
imagesEl.innerHTML = `
|
| 188 |
+
<div style="flex:1;min-width:120px;height:120px;background:linear-gradient(135deg,#f1f5f9,#e2e8f0);border-radius:10px;display:flex;align-items:center;justify-content:center;font-size:2.5rem">
|
| 189 |
+
${getCategoryEmoji(product.category)}
|
| 190 |
+
</div>
|
| 191 |
+
<div style="flex:1;min-width:120px;height:120px;background:linear-gradient(135deg,#fef3c7,#fef9c3);border-radius:10px;display:flex;align-items:center;justify-content:center;font-size:2.5rem">
|
| 192 |
+
${getCategoryEmoji(product.category)}
|
| 193 |
+
</div>
|
| 194 |
+
`;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
// Show BIG SALE pricing info in summary
|
| 198 |
+
const summaryEl = document.getElementById('detail-summary');
|
| 199 |
+
if (summaryEl) {
|
| 200 |
+
summaryEl.style.display = 'block';
|
| 201 |
+
summaryEl.innerHTML = `
|
| 202 |
+
<div style="margin-bottom:8px"><strong>🔥 Giá BigSale:</strong> ${formatVND(product.bigsale)}</div>
|
| 203 |
+
<div style="margin-bottom:8px"><strong>💰 Giá bán lẻ:</strong> ${formatVND(product.price)} → <span style="color:#c2410d;font-weight:700">${formatVND(product.bigsale)}</span></div>
|
| 204 |
+
<div style="margin-bottom:8px"><strong>🏷️ Chiết khấu:</strong> <span style="color:#dc2626;font-weight:700">-${product.discount}</span></div>
|
| 205 |
+
<div style="margin-bottom:8px"><strong>📦 Tình trạng:</strong> <span style="color:#16a34a;font-weight:600">${product.status}</span></div>
|
| 206 |
+
<div><strong>💡 Danh mục:</strong> ${product.category}</div>
|
| 207 |
+
`;
|
| 208 |
+
}
|
| 209 |
|
| 210 |
+
// Hide features and specs sections
|
| 211 |
+
const featuresEl = document.getElementById('detail-features');
|
| 212 |
+
const specsEl = document.getElementById('detail-specs');
|
| 213 |
+
if (featuresEl) featuresEl.style.display = 'none';
|
| 214 |
+
if (specsEl) specsEl.style.display = 'none';
|
| 215 |
|
| 216 |
+
overlay.style.display = 'flex';
|
| 217 |
+
|
| 218 |
+
// Close vaistudio panel if open
|
| 219 |
+
const vaistudioPanel = document.getElementById('vaistudio-panel');
|
| 220 |
+
if (vaistudioPanel && vaistudioPanel.classList.contains('open')) {
|
| 221 |
+
vaistudioPanel.classList.remove('open');
|
| 222 |
+
const toggle = document.getElementById('vaistudio-toggle');
|
| 223 |
+
if (toggle) toggle.classList.remove('open');
|
| 224 |
}
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
// Get emoji for category
|
| 228 |
+
function getCategoryEmoji(category) {
|
| 229 |
+
const map = {
|
| 230 |
+
"MÁY HÚT": "🧹",
|
| 231 |
+
"BẾP GAS": "🔥",
|
| 232 |
+
"CHẬU ĐÁ": "🧊",
|
| 233 |
+
"CHẬU RỰA": "🚰",
|
| 234 |
+
"LỌC NƯỚC": "💧",
|
| 235 |
+
"VÒI": "🚿",
|
| 236 |
+
"PHỤ KIỆN": "🧰"
|
| 237 |
+
};
|
| 238 |
+
return map[category] || "📦";
|
| 239 |
+
}
|
| 240 |
|
| 241 |
+
// Close BIG SALE panel
|
| 242 |
+
function closeBigSalePanel() {
|
| 243 |
+
const panel = document.getElementById('big-sale-panel');
|
| 244 |
+
const floating = document.getElementById('big-sale-floating');
|
| 245 |
+
if (panel) panel.classList.remove('open');
|
| 246 |
+
if (floating) floating.classList.remove('open');
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
// Initialize when DOM is ready
|
| 250 |
+
function initBigSale() {
|
| 251 |
+
createBigSaleElements();
|
| 252 |
+
console.log('[BIG SALE] Floating promotion initialized with 23 products');
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
// Handle dynamic DOM changes
|
| 256 |
+
function tryInitBigSale(retries = 20) {
|
| 257 |
if (document.readyState === 'loading') {
|
| 258 |
+
document.addEventListener('DOMContentLoaded', () => initBigSale());
|
| 259 |
} else {
|
| 260 |
initBigSale();
|
| 261 |
}
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
tryInitBigSale();
|