// 等级明细页面 - H5版本

let currentStallName = '';

// 获取URL参数
function getUrlParameter(name) {
    const urlParams = new URLSearchParams(window.location.search);
    return urlParams.get(name) || '';
}

// 页面初始化
document.addEventListener('DOMContentLoaded', function() {
    currentStallName = decodeURIComponent(getUrlParameter('stall'));
    
    if (currentStallName) {
        document.getElementById('page-title').textContent = `${currentStallName} - 等级明细`;
        loadLevelDetail();
    } else {
        document.getElementById('page-title').textContent = '等级明细';
        loadLevelDetail();
    }
});

// 加载等级明细数据
function loadLevelDetail() {
    // 使用模拟数据
    const levelData = [
        { name: 'LV1', growth: 100, members: 1250, benefits: '9.5折优惠' },
        { name: 'LV2', growth: 500, members: 850, benefits: '9折优惠, 积分双倍' },
        { name: 'LV3', growth: 1200, members: 450, benefits: '8.5折优惠, 积分双倍, 生日优惠券' },
        { name: 'LV4', growth: 2500, members: 180, benefits: '8折优惠, 积分三倍, 生日优惠券, 专属客服' }
    ];

    const tableBody = document.getElementById('level-detail-table');
    tableBody.innerHTML = levelData.map(level => `
        <tr>
            <td>${level.name}</td>
            <td>${level.growth}</td>
            <td>${level.members}</td>
            <td>${level.benefits}</td>
        </tr>
    `).join('');
}

// 编辑等级
function editLevel() {
    if (currentStallName) {
        const encodedName = encodeURIComponent(currentStallName);
        navigateTo(`level-edit.html?stall=${encodedName}`);
    } else {
        navigateTo('level-edit.html');
    }
}

// 提交明细
function submitDetail() {
    const message = currentStallName ? 
        `${currentStallName} 等级明细已提交` : 
        '等级明细已提交';
    
    submitAndGoBack(message);
}

// 导出函数到全局
window.editLevel = editLevel;
window.submitDetail = submitDetail;