Tin nổi bật

Zalo chat Hotline
document.addEventListener('DOMContentLoaded', function () { // ─── CONFIG ─────────────────────────────────────────────────────────────── // Toàn bộ logic giá + thông số theo nhóm tập trung tại đây // Muốn chỉnh chỉ cần sửa trong GROUP_CONFIG, không đụng code bên dưới var BASE_PRICE = 1800000; var GROUP_CONFIG = { // Nhóm A: H1, H7, H11, 9005/9006/9012 — giá gốc A: { buttons : ['9005/9006/9012', 'H11', 'H7', 'H1'], price : BASE_PRICE, chanBong : 'H1,H4,H7,H11, 9005/9006/9012, D1/D3, D2/D4', congSuat : '~70W (H1,H4,H7,H11, 9005/9006/9012)\n~ 45W (D1/D3, D2/D4)', nhanLed : '12+12 Flip Chip (H4)\n6+6 Flip Chip (Other)\n15 Flip chip (D1/D3, D2/D4)' }, // Nhóm B: H4 — giá gốc + 200.000 B: { buttons : ['H4'], price : BASE_PRICE + 200000, chanBong : 'H1,H4,H7,H11, 9005/9006/9012, D1/D3, D2/D4', congSuat : '~70W (H1,H4,H7,H11, 9005/9006/9012)\n~ 45W (D1/D3, D2/D4)', nhanLed : '12+12 Flip Chip (H4)\n6+6 Flip Chip (Other)\n15 Flip chip (D1/D3, D2/D4)' }, // Nhóm C: D1/D3, D2/D4 — giá cố định + thông số riêng C: { buttons : ['D1/D3', 'D2/D4'], price : 2500000, chanBong : 'D1/D3, D2/D4', congSuat : '~ 45W (D1/D3, D2/D4)', nhanLed : '15 Flip chip (D1/D3, D2/D4)' } }; // ─── UTILS ──────────────────────────────────────────────────────────────── /** * Tìm nút phân loại theo text hiển thị — không cần id/class riêng * @param {string} text - text hiển thị trên nút (vd: 'H4', 'D1/D3') * @returns {Element|undefined} */ function findButtonByText(text) { return Array.from(document.querySelectorAll('.box-classify-item')) .find(function (el) { return el.textContent.trim() === text; }); } /** * Tìm ô .lileft theo text label rồi trả về ô .liright kế tiếp * Dùng class thay vì text-match để tránh vấn đề dấu : hay khoảng trắng * @param {string} labelText - text trong ô label (vd: 'Công Suất Đèn:') * @returns {Element|null} */ function findValueCell(labelText) { var labelCell = Array.from(document.querySelectorAll('td.lileft')) .find(function (el) { return el.textContent.trim() === labelText; }); return labelCell ? labelCell.nextElementSibling : null; } /** * Cập nhật ô giá trị trong bảng thông số * Hỗ trợ text có \n → render thành
* @param {string} labelText * @param {string} newValue */ function updateSpec(labelText, newValue) { var cell = findValueCell(labelText); if (!cell) return; // Render \n thành
cho đúng layout bảng gốc cell.innerHTML = newValue.replace(/\n/g, '
\n'); } /** * Format số thành chuỗi giá tiền VNĐ * @param {number} number * @returns {string} vd: "1.800.000 vnđ / Cặp" */ function formatPrice(number) { return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.') + ' vnđ / Cặp'; } // ─── KHỞI TẠO ──────────────────────────────────────────────────────────── var priceUnit = document.querySelector('.price-unit'); if (!priceUnit) { console.warn('[LED Script] Không tìm thấy .price-unit'); return; } // Gán event listener cho từng nút trong từng nhóm Object.keys(GROUP_CONFIG).forEach(function (groupKey) { var group = GROUP_CONFIG[groupKey]; group.buttons.forEach(function (btnText) { var btn = findButtonByText(btnText); if (!btn) { console.warn('[LED Script] Không tìm thấy nút: "' + btnText + '"'); return; } btn.addEventListener('click', function () { // 1. Cập nhật giá priceUnit.textContent = formatPrice(group.price); // 2. Cập nhật bảng thông số — 3 trường thay đổi theo nhóm updateSpec('Chân Bóng:', group.chanBong); updateSpec('Công Suất Đèn:', group.congSuat); updateSpec('Nhân LED:', group.nhanLed); }); }); }); });