// 商品定价管理模块 class ProductPricingManager { constructor(options = {}) { this.apiBaseUrl = options.apiBaseUrl || 'http://localhost:3000'; // 默认商品配置 this.products = [ { id: 'vip-matting', name: 'VIP抠图', desc: '使用VIP服务进行图片抠图', price: 0 }, { id: 'ai-generate', name: 'AI生图', desc: '使用AI生成图片', price: 0 } ]; this.init(); } init() { this.bindEvents(); this.loadSettings(); } bindEvents() { const productList = document.getElementById('productList'); if (productList) { productList.addEventListener('input', (e) => { if (e.target.classList.contains('price-input')) { const productId = e.target.dataset.productId; const confirmBtn = e.target.closest('.product-item').querySelector('.btn-confirm'); if (confirmBtn) { confirmBtn.classList.add('show'); } } }); productList.addEventListener('click', (e) => { if (e.target.closest('.btn-confirm')) { const button = e.target.closest('.btn-confirm'); const productId = button.dataset.productId; this.saveProduct(productId); } }); } } async loadSettings() { try { const response = await fetch(`${this.apiBaseUrl}/api/admin/product-pricing/settings`); if (response.ok) { const result = await response.json(); if (result.success && result.products) { // 更新产品价格,保持默认产品结构 result.products.forEach(serverProduct => { const localProduct = this.products.find(p => p.id === serverProduct.id); if (localProduct) { localProduct.price = serverProduct.price || 0; } }); } } } catch (error) { console.log('[ProductPricingManager] 使用默认设置'); } this.render(); } render() { const list = document.getElementById('productList'); if (!list) return; list.innerHTML = this.products.map(product => `