harmony.html 13.9 KB
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>鸿蒙生态分析 - 问界门店运营数据分析平台</title>
    <base href="/daw/">
    <link rel="stylesheet" href="static/css/style.css">
</head>
<body>
    <header>
        <div class="logo">问界运营分析平台</div>
        <nav class="nav-links">
            <a class="nav-item" href="/">首页</a>
            <a class="nav-item" href="/ods">ODS 同步任务</a>
            <a class="nav-item" href="/dw">DWS/DWM/DWA 任务</a>
            <a class="nav-item" href="/analysis">问界生态系数分析</a>
            <a class="nav-item active" href="/harmony">鸿蒙生态分析</a>
        </nav>
        <div class="user-info">管理员</div>
    </header>

    <main>
        <section id="content-area">
            <div class="card">
                <h2 id="content-title">鸿蒙生态分析</h2>
                <div id="content-body">

                    <div id="harmony-analysis-section">
                        <div style="display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px;">
                            <!-- 步骤1: 上传门店兜底配置 -->
                            <div style="background: #f8f9fa; padding: 8px 16px; border-radius: 6px; border: 1px solid #e8e8e8; display: flex; align-items: center; gap: 16px;">
                                <span style="font-size:14px; font-weight:600; color:#333; white-space:nowrap;">步骤1: 门店兜底配置</span>
                                <div id="hm-store-drop-zone" style="flex:1; border: 1px dashed #d9d9d9; padding: 6px 12px; border-radius: 4px; cursor: pointer; background: #fff; display: flex; align-items: center; gap: 8px;">
                                    <input type="file" id="hm-store-file-input" style="display:none;" accept=".xlsx,.xls">
                                    <span style="font-size:16px;">&#x1f3ea;</span>
                                    <p id="hm-store-file-name" style="margin:0; font-size:13px; color:#999;">可选:点击选择门店兜底配置文件(不选则使用系统默认模板)</p>
                                </div>
                                <a href="/api/harmony/template/store" style="font-size:12px; color:#1890ff; text-decoration:none; white-space:nowrap;">&#x1f4e5; 下载模板</a>
                            </div>

                            <!-- 步骤2: 上传主机厂数据 -->
                            <div style="background: #f8f9fa; padding: 8px 16px; border-radius: 6px; border: 1px solid #e8e8e8; display: flex; align-items: center; gap: 12px;">
                                <span style="font-size:14px; font-weight:600; color:#333; white-space:nowrap;">步骤2: 主机厂数据</span>
                                <div id="hm-factory-drop-zone" style="flex:1; border: 1px dashed #d9d9d9; padding: 6px 12px; border-radius: 4px; cursor: pointer; background: #fff; display: flex; align-items: center; gap: 8px;">
                                    <input type="file" id="hm-factory-file-input" style="display:none;" accept=".xlsx,.xls">
                                    <span style="font-size:16px;">&#x1f3ed;</span>
                                    <p id="hm-factory-file-name" style="margin:0; font-size:12px; color:#999;">点击选择主机厂数据(含交付数)</p>
                                </div>
                                <a href="/api/harmony/template/factory" style="font-size:12px; color:#1890ff; text-decoration:none; white-space:nowrap;">&#x1f4e5; 下载模板</a>
                            </div>

                            <!-- 步骤3: 上传产值表 -->
                            <div style="background: #f0f5ff; padding: 8px 16px; border-radius: 6px; border: 1px solid #adc6ff; display: flex; align-items: center; gap: 12px;">
                                <span style="font-size:14px; font-weight:600; color:#1890ff; white-space:nowrap;">步骤3: 产值表 (核心数据)</span>
                                <div id="hm-value-drop-zone" style="flex:1; border: 1px dashed #1890ff; padding: 6px 12px; border-radius: 4px; cursor: pointer; background: #fff; display: flex; align-items: center; gap: 8px;">
                                    <input type="file" id="hm-value-file-input" style="display:none;" accept=".xlsx,.xls">
                                    <span style="font-size:16px;">&#x1f4ca;</span>
                                    <p id="hm-value-file-name" style="margin:0; font-size:12px; color:#999;">点击选择鸿蒙产值表(含触客数、成交数、渗透率等)</p>
                                </div>
                            </div>

                            <!-- 日期范围 -->
                            <div style="background: #f8f9fa; padding: 8px 16px; border-radius: 6px; border: 1px solid #e8e8e8; display: flex; align-items: center; gap: 12px;">
                                <span style="font-size:14px; font-weight:600; color:#333; white-space:nowrap;">数据周期</span>
                                <input type="date" id="hm-start-date" style="width:140px; padding: 4px 6px; border: 1px solid #d9d9d9; border-radius: 4px; font-size:12px;">
                                <span style="color:#999; font-size:12px;">~</span>
                                <input type="date" id="hm-end-date" style="width:140px; padding: 4px 6px; border: 1px solid #d9d9d9; border-radius: 4px; font-size:12px;">
                            </div>
                        </div>

                        <!-- 生成报表按钮 -->
                        <div style="text-align: center; margin: 20px 0;">
                            <button id="btn-hm-generate" style="padding: 12px 48px; background: #1890ff; color: white; border: none; border-radius: 6px; font-size: 16px; cursor: pointer; transition: all 0.3s;">
                                &#x1f680; 生成鸿蒙生态分析报表
                            </button>
                            <p style="font-size:12px; color:#999; margin-top:8px;">合并门店兜底配置 + 主机厂交付数据 + 产值表指标,计算渗透率达标系数和赔付金额</p>
                            <p style="font-size:11px; color:#faad14;">&#x1f4cc; 使用模板: 输出-鸿蒙生态系数-模板.xlsx</p>
                        </div>

                        <!-- 结果提示 -->
                        <div id="hm-result" style="display:none; background: #f6ffed; border: 1px solid #b7eb8f; padding: 20px; border-radius: 8px; text-align: center;">
                            <h3 style="color:#52c41a; margin:0 0 10px;">&#x2705; 报表生成成功</h3>
                            <div id="hm-result-info" style="font-size:13px; color:#666; margin-bottom:15px;"></div>
                            <a id="btn-hm-download" href="#"
                               style="display:inline-block; padding: 10px 32px; background: #52c41a; color: white; border: none; border-radius: 4px; font-size: 14px; text-decoration: none; cursor: pointer;">
                                &#x1f4e5; 下载分析报表
                            </a>
                        </div>

                        <div id="hm-error" style="display:none; background: #fff2f0; border: 1px solid #ffccc7; padding: 20px; border-radius: 8px; text-align: center;">
                            <h3 style="color:#f5222d; margin:0 0 10px;">&#x274c; 报表生成失败</h3>
                            <p id="hm-error-msg" style="margin:0; color:#666;"></p>
                        </div>
                    </div>

                </div>
            </div>
        </section>
    </main>

    <script>
    document.addEventListener('DOMContentLoaded', () => {
        const fmt = d => `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')}`;
        const now = new Date();
        const todayStr = fmt(now);
        const firstOfMonth = fmt(new Date(now.getFullYear(), now.getMonth(), 1));

        const startDate = document.getElementById('hm-start-date');
        const endDate = document.getElementById('hm-end-date');
        if (startDate && !startDate.value) startDate.value = firstOfMonth;
        if (endDate && !endDate.value) endDate.value = todayStr;

        // 门店兜底配置上传
        const storeDropZone = document.getElementById('hm-store-drop-zone');
        const storeFileInput = document.getElementById('hm-store-file-input');
        if (storeDropZone) {
            storeDropZone.addEventListener('click', () => storeFileInput.click());
            storeFileInput.addEventListener('change', () => {
                if (storeFileInput.files.length > 0) {
                    document.getElementById('hm-store-file-name').textContent = '\u2705 已选择: ' + storeFileInput.files[0].name;
                    document.getElementById('hm-store-file-name').style.color = '#52c41a';
                }
            });
        }

        // 主机厂数据上传
        const factoryDropZone = document.getElementById('hm-factory-drop-zone');
        const factoryFileInput = document.getElementById('hm-factory-file-input');
        if (factoryDropZone) {
            factoryDropZone.addEventListener('click', () => factoryFileInput.click());
            factoryFileInput.addEventListener('change', () => {
                if (factoryFileInput.files.length > 0) {
                    document.getElementById('hm-factory-file-name').textContent = '\u2705 已选择: ' + factoryFileInput.files[0].name;
                    document.getElementById('hm-factory-file-name').style.color = '#52c41a';
                }
            });
        }

        // 产值表上传
        const valueDropZone = document.getElementById('hm-value-drop-zone');
        const valueFileInput = document.getElementById('hm-value-file-input');
        if (valueDropZone) {
            valueDropZone.addEventListener('click', () => valueFileInput.click());
            valueFileInput.addEventListener('change', () => {
                if (valueFileInput.files.length > 0) {
                    document.getElementById('hm-value-file-name').textContent = '\u2705 已选择: ' + valueFileInput.files[0].name;
                    document.getElementById('hm-value-file-name').style.color = '#52c41a';
                }
            });
        }

        // 生成报表
        const btnGenerate = document.getElementById('btn-hm-generate');
        if (btnGenerate) {
            btnGenerate.addEventListener('click', async () => {
                document.getElementById('hm-result').style.display = 'none';
                document.getElementById('hm-error').style.display = 'none';

                const hasStore = storeFileInput && storeFileInput.files.length > 0;
                const hasFactory = factoryFileInput && factoryFileInput.files.length > 0;
                const hasValue = valueFileInput && valueFileInput.files.length > 0;

                if (!hasFactory && !hasValue) {
                    alert('请至少上传主机厂数据或产值表文件');
                    return;
                }

                btnGenerate.disabled = true;
                btnGenerate.textContent = '\u23f3 正在上传文件...';

                try {
                    // 上传文件
                    const uploadForm = new FormData();
                    if (hasStore) uploadForm.append('store_file', storeFileInput.files[0]);
                    if (hasFactory) uploadForm.append('factory_file', factoryFileInput.files[0]);
                    if (hasValue) uploadForm.append('value_file', valueFileInput.files[0]);

                    const uploadRes = await fetch('/api/harmony/upload', { method: 'POST', body: uploadForm });
                    const uploadData = await uploadRes.json();
                    if (uploadData.status !== 'success') {
                        throw new Error(uploadData.detail || '文件上传失败');
                    }

                    btnGenerate.textContent = '\u23f3 正在分析计算...';

                    // 生成报表
                    const genForm = new FormData();
                    const sd = document.getElementById('hm-start-date').value;
                    const ed = document.getElementById('hm-end-date').value;
                    if (sd) genForm.append('start_date', sd);
                    if (ed) genForm.append('end_date', ed);

                    const genRes = await fetch('/api/harmony/generate', { method: 'POST', body: genForm });
                    const genData = await genRes.json();

                    if (genData.status === 'success') {
                        document.getElementById('hm-result').style.display = 'block';
                        document.getElementById('hm-result-info').innerHTML =
                            '门店数: <strong>' + genData.store_count + '</strong> | ' +
                            '主机厂门店: <strong>' + genData.factory_count + '</strong> | ' +
                            '产值表门店: <strong>' + genData.value_count + '</strong>';
                        document.getElementById('btn-hm-download').href = genData.download_url;
                    } else {
                        throw new Error(genData.detail || '报表生成失败');
                    }
                } catch (err) {
                    console.error('鸿蒙分析失败:', err);
                    document.getElementById('hm-error').style.display = 'block';
                    document.getElementById('hm-error-msg').textContent = err.message || '未知错误';
                } finally {
                    btnGenerate.disabled = false;
                    btnGenerate.textContent = '\u{1f680} 生成鸿蒙生态分析报表';
                }
            });
        }
    });
    </script>
</body>
</html>