/** * File: lottery-orders.js * Version: v3.1.4 * Author: CHEN YONGZAI * Created: 2025-07-20 * Updated: 2025-07-28 14:46 (HKT) * Description: Fixed real-time update for Original Total, Discounted Total, and Pay Now to sync with Discount Applied; resolved parseFloat issue with comma-separated numbers. */ class LotteryOrders { constructor() { this.config = null; this.selections = []; this.type = null; this.lotteryConfig = null; this.currentOrderId = null; this.currentTotal = 0; // 存储原始总额(无逗号) this.currentDiscounted = 0; // 存储优惠后总额(无逗号) } init() { const lottery = this; const type = document.querySelector('.lottery-orders')?.dataset.type || '3d'; lottery.type = type; lottery.config = window.lotteryConfig || {}; lottery.lotteryConfig = lottery.config.lottery_types?.[type] || {}; console.log('Initializing LotteryOrders for type:', type, 'with config:', lottery.lotteryConfig); if (!window.lottery_orders_params) { console.error('lottery_orders_params not defined'); lottery.showAlert('Initialization failed, please refresh the page', 'error'); return; } lottery.initializeSelections(); lottery.bindEvents(); lottery.bindModalEvents(); lottery.updateAllModules(); lottery.updateBuyButton(); // Initialize all modules with random numbers setTimeout(() => { document.querySelectorAll('.lottery-card[data-module]').forEach(module => { const index = parseInt(module.dataset.module) - 1; if (index < lottery.lotteryConfig.bets) { lottery.randomizeNumbers(module, index); lottery.updateModule(module, index); // 确保更新显示 console.log('Auto Quick Pick executed for module', index + 1); } }); }, 300); setTimeout(() => { lottery.updateCartCount(); }, 500); // 强制重新加载CSS(开发阶段用,后期移除) document.querySelectorAll('link[rel="stylesheet"]').forEach(link => { link.href = link.href.replace(/\?.*$/, '') + '?t=' + Date.now(); }); // 绑定 radio change 事件以更新支付按钮 document.querySelectorAll('input[name="price-option"]').forEach(radio => { radio.addEventListener('change', () => lottery.updatePayButton()); }); // 初始化支付按钮 lottery.updatePayButton(); // 新增:绑定手动填写推广代码提交按钮 const submitReferral = document.getElementById('submit-referral'); if (submitReferral) { submitReferral.addEventListener('click', () => lottery.showReferralConfirm()); } } // 新增:显示填写推广代码确认弹窗 showReferralConfirm() { const lottery = this; const input = document.getElementById('referral-input'); const refCode = input.value.trim().toUpperCase(); if (!refCode || refCode.length !== 4) { lottery.showAlert('请输入有效的四位推广代码', 'error'); return; } const referralModal = document.getElementById('referral-confirm'); if (referralModal) { const message = referralModal.querySelector('#referral-confirm-message'); message.textContent = `确认提交推广代码: ${refCode}?`; referralModal.style.display = 'flex'; referralModal.style.opacity = '0'; setTimeout(() => referralModal.style.opacity = '1', 50); } } // 新增:确认提交推广代码 submitReferralCode() { const lottery = this; const input = document.getElementById('referral-input'); const refCode = input.value.trim().toUpperCase(); const nonce = '