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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// BIG SALE Floating Promotion for V.AI AVATAR2
|
| 2 |
+
// Space: bep40/vai-avatar2
|
| 3 |
+
|
| 4 |
+
// Product data for BIG SALE
|
| 5 |
+
// Format: [STT, Mã sản phẩm, Tên sản phẩm, SL, Giá bán lẻ (VNĐ), Chiết khấu (%), Giá Bigsale (VNĐ), Tình trạng]
|
| 6 |
+
const BIG_SALE_PRODUCTS = [
|
| 7 |
+
[1, "MC-7086HS", "MÁY HÚT", 3, 11389000, 55, 5125050, "HÀNG MỚI"],
|
| 8 |
+
[2, "MH-70SMC", "MÁY HÚT ECO", 2, 4620000, 60, 1848000, "HÀNG MỚI"],
|
| 9 |
+
[3, "MH-90SMC", "MÁY HÚT ECO", 4, 5060000, 60, 2024000, "HÀNG MỚI"],
|
| 10 |
+
[4, "MH-600GT", "MÁY HÚT", 5, 8208000, 50, 4104000, "HÀNG MỚI"],
|
| 11 |
+
[5, "AS-9602DG", "BẾP 2 GAS", 2, 7815000, 50, 3907500, "HÀNG MỚI"],
|
| 12 |
+
[6, "SMART K-450", "CHẬU ĐÁ", 1, 21109000, 55, 9499050, "HÀNG MỚI"],
|
| 13 |
+
[7, "MS-1022D", "CHẊU RỦA", 4, 5852000, 50, 2926000, "HÀNG MỚI"],
|
| 14 |
+
[8, "MS-2025", "CHẊU RỦA", 1, 5700000, 55, 2565000, "HÀNG MỚI"],
|
| 15 |
+
[9, "MS-6070", "CHẊU RỦA", 11, 6464000, 50, 3232000, "HÀNG MỚI"],
|
| 16 |
+
[10, "MS-5066W", "CHẊU RỦA", 8, 4385000, 50, 2192500, "HÀNG MỚI"],
|
| 17 |
+
[11, "MS-5082W", "CHẊU RỦA", 3, 6350000, 50, 3175000, "HÀNG MỚI"],
|
| 18 |
+
[12, "MS-862", "CHẊU RỦA", 3, 12960000, 55, 5832000, "HÀNG MỚI"],
|
| 19 |
+
[13, "MPC-5KCB", "BỘ LỌC NƯỚC", 1, 10702000, 50, 5351000, "HÀNG MỚI"],
|
| 20 |
+
[14, "K061S", "VÒI", 10, 3056000, 50, 1528000, "HÀNG MỚI"],
|
| 21 |
+
[15, "K569SN", "VÒI ECO", 2, 3520000, 55, 1584000, "HÀNG MỚI"],
|
| 22 |
+
[16, "K525B", "VÒI", 2, 2916000, 55, 1312200, "HÀNG MỚI"],
|
| 23 |
+
[17, "K130S", "VÒI", 4, 4104000, 55, 1846800, "HÀNG MỚI"],
|
| 24 |
+
[18, "K136A", "VÒI", 2, 2430000, 55, 1093500, "HÀNG MỚI"],
|
| 25 |
+
[19, "K501B", "VÒI", 2, 5076000, 55, 2284200, "HÀNG MỚI"],
|
| 26 |
+
[20, "MST-6667", "LÓT NỒI", 25, 255000, 70, 76500, "HÀNG MỚI"],
|
| 27 |
+
[21, "MMPM-657A", "XAY TIÊU", 34, 295000, 70, 88500, "HÀNG MỚI"],
|
| 28 |
+
[22, "MOVS-10128", "BỘ ĐỰNG DẦU", 2, 491000, 70, 147300, "HÀNG MỚI"],
|
| 29 |
+
[23, "BỘ LÀM SẠCH NHÀ BẾP", "BỘ LÀM SẠCH NHÀ BẾP", 8, 720000, 70, 216000, "HÀNG MỚI"]
|
| 30 |
+
];
|
| 31 |
+
|
| 32 |
+
(function() {
|
| 33 |
+
'use strict';
|
| 34 |
+
|
| 35 |
+
// Format currency VND
|
| 36 |
+
function formatVND(amount) {
|
| 37 |
+
return new Intl.NumberFormat('vi-VN', {
|
| 38 |
+
style: 'currency',
|
| 39 |
+
currency: 'VND',
|
| 40 |
+
minimumFractionDigits: 0
|
| 41 |
+
}).format(amount);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
// Create the BIG SALE floating button
|
| 45 |
+
function createFloatingButton() {
|
| 46 |
+
var button = document.createElement('button');
|
| 47 |
+
button.id = 'bigSaleToggle';
|
| 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 |
+
// Create the BIG SALE panel
|
| 59 |
+
function createPanel() {
|
| 60 |
+
var panel = document.createElement('div');
|
| 61 |
+
panel.id = 'bigSalePanel';
|
| 62 |
+
panel.className = 'big-sale-panel';
|
| 63 |
+
panel.innerHTML =
|
| 64 |
+
'<div class="big-sale-header">' +
|
| 65 |
+
'<h3><i class="fas fa-bolt" style="margin-right:8px"></i> CHƯƠNG TRÌNH BIG SALE</h3>' +
|
| 66 |
+
'<button class="big-sale-close" id="bigSaleClose" aria-label="Đóng">' +
|
| 67 |
+
'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">' +
|
| 68 |
+
'<line x1="18" y1="6" x2="6" y2="18"></line>' +
|
| 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 |
+
// Render product cards into the panel
|
| 78 |
+
function renderProducts() {
|
| 79 |
+
var container = document.getElementById('bigSaleProducts');
|
| 80 |
+
if (!container) return;
|
| 81 |
+
|
| 82 |
+
var html = '';
|
| 83 |
+
BIG_SALE_PRODUCTS.forEach(function(product) {
|
| 84 |
+
var stt = product[0];
|
| 85 |
+
var maSp = product[1];
|
| 86 |
+
var tenSp = product[2];
|
| 87 |
+
var sl = product[3];
|
| 88 |
+
var giaBan = product[4];
|
| 89 |
+
var chietKhau = product[5];
|
| 90 |
+
var giaBigSale = product[6];
|
| 91 |
+
var tinhTrang = product[7];
|
| 92 |
+
var originalPrice = formatVND(giaBan);
|
| 93 |
+
var bigSalePrice = formatVND(giaBigSale);
|
| 94 |
+
|
| 95 |
+
html +=
|
| 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 |
+
container.innerHTML = html;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// Open product detail from BIG SALE
|
| 117 |
+
window.openBigSaleProduct = function(stt) {
|
| 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 |
+
alert(
|
| 148 |
+
'Sản phẩm: ' + tenSp + '\n' +
|
| 149 |
+
'Mã: ' + maSp + '\n' +
|
| 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 |
+
// Close product detail
|
| 159 |
+
window.closeBigSaleDetail = function() {
|
| 160 |
+
var overlay = document.getElementById('vaistudio-detail-overlay');
|
| 161 |
+
if (overlay) overlay.style.display = 'none';
|
| 162 |
+
};
|
| 163 |
+
|
| 164 |
+
// Initialize BIG SALE
|
| 165 |
+
function initBigSale() {
|
| 166 |
+
// Check if already initialized
|
| 167 |
+
if (document.getElementById('bigSaleToggle')) return;
|
| 168 |
+
|
| 169 |
+
// Create floating button
|
| 170 |
+
var floatingBtn = createFloatingButton();
|
| 171 |
+
document.body.appendChild(floatingBtn);
|
| 172 |
+
|
| 173 |
+
// Create panel
|
| 174 |
+
var panel = createPanel();
|
| 175 |
+
document.body.appendChild(panel);
|
| 176 |
+
|
| 177 |
+
// Wire up events
|
| 178 |
+
var toggleBtn = document.getElementById('bigSaleToggle');
|
| 179 |
+
var salePanel = document.getElementById('bigSalePanel');
|
| 180 |
+
var closeBtn = document.getElementById('bigSaleClose');
|
| 181 |
+
|
| 182 |
+
if (toggleBtn && salePanel) {
|
| 183 |
+
toggleBtn.addEventListener('click', function() {
|
| 184 |
+
salePanel.classList.toggle('open');
|
| 185 |
+
});
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
if (closeBtn && salePanel) {
|
| 189 |
+
closeBtn.addEventListener('click', function() {
|
| 190 |
+
salePanel.classList.remove('open');
|
| 191 |
+
});
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
// Close panel when clicking outside
|
| 195 |
+
if (salePanel) {
|
| 196 |
+
salePanel.addEventListener('click', function(e) {
|
| 197 |
+
if (e.target === salePanel) {
|
| 198 |
+
salePanel.classList.remove('open');
|
| 199 |
+
}
|
| 200 |
+
});
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
// Render products
|
| 204 |
+
renderProducts();
|
| 205 |
+
|
| 206 |
+
console.log('[BIG SALE] Floating promotion initialized with ' + BIG_SALE_PRODUCTS.length + ' products');
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
// Initialize when DOM is ready
|
| 210 |
+
if (document.readyState === 'loading') {
|
| 211 |
+
document.addEventListener('DOMContentLoaded', initBigSale);
|
| 212 |
+
} else {
|
| 213 |
+
initBigSale();
|
| 214 |
+
}
|
| 215 |
+
})();
|