128 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
		
		
			
		
	
	
			128 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
| 
								 | 
							
								/**
							 | 
						|||
| 
								 | 
							
								 * 等级明细页面功能模块
							 | 
						|||
| 
								 | 
							
								 * 包含该页面的所有交互逻辑
							 | 
						|||
| 
								 | 
							
								 */
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								// 模拟不同商户的等级数据
							 | 
						|||
| 
								 | 
							
								const merchantLevelData = {
							 | 
						|||
| 
								 | 
							
								    '牛牛蔬菜店': [
							 | 
						|||
| 
								 | 
							
								        { level: 'LV1', growth: 100, members: 1250, benefits: '9.5折优惠' },
							 | 
						|||
| 
								 | 
							
								        { level: 'LV2', growth: 500, members: 850, benefits: '9折优惠, 积分双倍' },
							 | 
						|||
| 
								 | 
							
								        { level: 'LV3', growth: 1200, members: 450, benefits: '8.5折优惠, 积分双倍, 生日优惠券' },
							 | 
						|||
| 
								 | 
							
								        { level: 'LV4', growth: 2500, members: 180, benefits: '8折优惠, 积分三倍, 生日优惠券, 专属客服' }
							 | 
						|||
| 
								 | 
							
								    ],
							 | 
						|||
| 
								 | 
							
								    '羊羊水果店': [
							 | 
						|||
| 
								 | 
							
								        { level: 'LV1', growth: 80, members: 980, benefits: '9.8折优惠' },
							 | 
						|||
| 
								 | 
							
								        { level: 'LV2', growth: 400, members: 650, benefits: '9.2折优惠, 积分双倍' },
							 | 
						|||
| 
								 | 
							
								        { level: 'LV3', growth: 1000, members: 320, benefits: '8.8折优惠, 积分双倍, 生日优惠券' }
							 | 
						|||
| 
								 | 
							
								    ],
							 | 
						|||
| 
								 | 
							
								    '小狗羊肉': [
							 | 
						|||
| 
								 | 
							
								        { level: 'LV1', growth: 120, members: 800, benefits: '9.3折优惠' },
							 | 
						|||
| 
								 | 
							
								        { level: 'LV2', growth: 600, members: 520, benefits: '8.8折优惠, 积分双倍' },
							 | 
						|||
| 
								 | 
							
								        { level: 'LV3', growth: 1500, members: 280, benefits: '8.3折优惠, 积分双倍, 生日优惠券' },
							 | 
						|||
| 
								 | 
							
								        { level: 'LV4', growth: 3000, members: 120, benefits: '7.8折优惠, 积分三倍, 生日优惠券, 专属客服' }
							 | 
						|||
| 
								 | 
							
								    ],
							 | 
						|||
| 
								 | 
							
								    '小马猪蹄': [
							 | 
						|||
| 
								 | 
							
								        { level: 'LV1', growth: 150, members: 600, benefits: '9.5折优惠' },
							 | 
						|||
| 
								 | 
							
								        { level: 'LV2', growth: 800, members: 350, benefits: '9折优惠, 积分双倍' }
							 | 
						|||
| 
								 | 
							
								    ],
							 | 
						|||
| 
								 | 
							
								    '小鱼生鲜': [
							 | 
						|||
| 
								 | 
							
								        { level: 'LV1', growth: 90, members: 1100, benefits: '9.6折优惠' },
							 | 
						|||
| 
								 | 
							
								        { level: 'LV2', growth: 450, members: 750, benefits: '9.1折优惠, 积分双倍' },
							 | 
						|||
| 
								 | 
							
								        { level: 'LV3', growth: 1100, members: 400, benefits: '8.6折优惠, 积分双倍, 生日优惠券' },
							 | 
						|||
| 
								 | 
							
								        { level: 'LV4', growth: 2200, members: 200, benefits: '8.1折优惠, 积分三倍, 生日优惠券, 专属客服' }
							 | 
						|||
| 
								 | 
							
								    ]
							 | 
						|||
| 
								 | 
							
								};
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								// 页面初始化函数(必需)
							 | 
						|||
| 
								 | 
							
								function initLevelDetails() {
							 | 
						|||
| 
								 | 
							
								    console.log('等级明细页面已初始化');
							 | 
						|||
| 
								 | 
							
								    
							 | 
						|||
| 
								 | 
							
								    // 从URL参数或全局变量获取商户名称
							 | 
						|||
| 
								 | 
							
								    const merchantName = getCurrentMerchantName();
							 | 
						|||
| 
								 | 
							
								    if (merchantName) {
							 | 
						|||
| 
								 | 
							
								        updatePageContent(merchantName);
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								// 获取当前商户名称
							 | 
						|||
| 
								 | 
							
								function getCurrentMerchantName() {
							 | 
						|||
| 
								 | 
							
								    // 可以从tab标题中提取商户名称
							 | 
						|||
| 
								 | 
							
								    const activeTab = document.querySelector('.tab.active');
							 | 
						|||
| 
								 | 
							
								    if (activeTab) {
							 | 
						|||
| 
								 | 
							
								        const tabTitle = activeTab.textContent.trim();
							 | 
						|||
| 
								 | 
							
								        // 提取商户名称(去掉" - 等级设置明细"后缀)
							 | 
						|||
| 
								 | 
							
								        const merchantName = tabTitle.replace(' - 等级设置明细', '');
							 | 
						|||
| 
								 | 
							
								        // 如果标题中包含了商户名称,则返回商户名称
							 | 
						|||
| 
								 | 
							
								        if (merchantName !== tabTitle) {
							 | 
						|||
| 
								 | 
							
								            return merchantName;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        // 否则尝试从关闭按钮的 × 前面获取标题文本
							 | 
						|||
| 
								 | 
							
								        const tabTextContent = activeTab.querySelector('.tab-text');
							 | 
						|||
| 
								 | 
							
								        if (tabTextContent) {
							 | 
						|||
| 
								 | 
							
								            return tabTextContent.textContent.replace(' - 等级设置明细', '');
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								    return '时尚服装店'; // 默认值
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								// 更新页面内容
							 | 
						|||
| 
								 | 
							
								function updatePageContent(merchantName) {
							 | 
						|||
| 
								 | 
							
								    // 更新页面标题
							 | 
						|||
| 
								 | 
							
								    const merchantNameElement = document.getElementById('merchantName');
							 | 
						|||
| 
								 | 
							
								    if (merchantNameElement) {
							 | 
						|||
| 
								 | 
							
								        merchantNameElement.textContent = merchantName;
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								    
							 | 
						|||
| 
								 | 
							
								    // 更新表格数据
							 | 
						|||
| 
								 | 
							
								    const levelData = merchantLevelData[merchantName];
							 | 
						|||
| 
								 | 
							
								    if (levelData) {
							 | 
						|||
| 
								 | 
							
								        updateLevelTable(levelData);
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								// 更新等级表格数据
							 | 
						|||
| 
								 | 
							
								function updateLevelTable(levelData) {
							 | 
						|||
| 
								 | 
							
								    const tbody = document.getElementById('levelDetailsBody');
							 | 
						|||
| 
								 | 
							
								    if (!tbody) return;
							 | 
						|||
| 
								 | 
							
								    
							 | 
						|||
| 
								 | 
							
								    tbody.innerHTML = '';
							 | 
						|||
| 
								 | 
							
								    
							 | 
						|||
| 
								 | 
							
								    levelData.forEach(level => {
							 | 
						|||
| 
								 | 
							
								        const row = document.createElement('tr');
							 | 
						|||
| 
								 | 
							
								        row.innerHTML = `
							 | 
						|||
| 
								 | 
							
								            <td>${level.level}</td>
							 | 
						|||
| 
								 | 
							
								            <td>${level.growth}</td>
							 | 
						|||
| 
								 | 
							
								            <td>${level.members}</td>
							 | 
						|||
| 
								 | 
							
								            <td>${level.benefits}</td>
							 | 
						|||
| 
								 | 
							
								        `;
							 | 
						|||
| 
								 | 
							
								        tbody.appendChild(row);
							 | 
						|||
| 
								 | 
							
								    });
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								// 等级编辑功能
							 | 
						|||
| 
								 | 
							
								function addLevel() {
							 | 
						|||
| 
								 | 
							
								    // 获取当前商户名称
							 | 
						|||
| 
								 | 
							
								    const merchantName = getCurrentMerchantName();
							 | 
						|||
| 
								 | 
							
								    // 打开新的tab页面显示该商户的等级编辑
							 | 
						|||
| 
								 | 
							
								    const tabTitle = `${merchantName} - 等级编辑`;
							 | 
						|||
| 
								 | 
							
								    if (typeof window.openTab === 'function') {
							 | 
						|||
| 
								 | 
							
								        window.openTab(tabTitle, 'level-edit');
							 | 
						|||
| 
								 | 
							
								    } else {
							 | 
						|||
| 
								 | 
							
								        console.error('openTab函数未找到');
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								// 保存等级设置
							 | 
						|||
| 
								 | 
							
								function saveLevelSettings() {
							 | 
						|||
| 
								 | 
							
								    alert('等级设置已保存!');
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								// 将需要在HTML中调用的函数暴露到全局作用域
							 | 
						|||
| 
								 | 
							
								window.addLevel = addLevel;
							 | 
						|||
| 
								 | 
							
								window.saveLevelSettings = saveLevelSettings;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								// 页面清理函数(可选)
							 | 
						|||
| 
								 | 
							
								function cleanupLevelDetails() {
							 | 
						|||
| 
								 | 
							
								    // 清理事件监听器等
							 | 
						|||
| 
								 | 
							
								}
							 |