Files
ecom-dmb/apps/web/temp/pdd_dashboard(3)(1).html
2026-09-16 22:43:21 +08:00

1192 lines
73 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>拼多多店铺财务运营数据看板</title>
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif; background: #0d0f1a; color: #e0e4f0; min-height: 100vh; }
/* Header */
.header { background: linear-gradient(135deg,#c0392b 0%,#e74c3c 50%,#ff6b6b 100%); padding: 16px 32px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 4px 20px rgba(231,76,60,0.4); }
.header-left { display: flex; align-items: center; gap: 14px; }
.logo { width: 40px; height: 40px; background: #fff; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.header h1 { font-size: 18px; font-weight: 700; color: #fff; letter-spacing: 1px; }
.header p { font-size: 11px; color: rgba(255,255,255,0.8); margin-top: 2px; }
.header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.badge-pill { background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3); border-radius: 20px; padding: 5px 14px; font-size: 12px; color: #fff; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #2ecc71; animation: pulse 2s infinite; display: inline-block; margin-right: 5px; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }
/* Tab Bar */
.tab-bar { background: #141627; border-bottom: 1px solid #1e2235; padding: 0 32px; display: flex; gap: 2px; overflow-x: auto; }
.tab-btn { padding: 13px 20px; font-size: 13px; color: #8890a8; cursor: pointer; border-bottom: 2px solid transparent; transition: all .2s; background: none; border-top: none; border-left: none; border-right: none; white-space: nowrap; }
.tab-btn:hover { color: #e74c3c; }
.tab-btn.active { color: #e74c3c; border-bottom-color: #e74c3c; font-weight: 600; }
/* Toolbar */
.toolbar { background: #141627; padding: 10px 32px; display: flex; align-items: center; gap: 16px; border-bottom: 1px solid #1e2235; flex-wrap: wrap; }
.period-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.period-btn { padding: 5px 14px; border-radius: 14px; font-size: 12px; cursor: pointer; border: 1px solid #2a2f45; background: transparent; color: #8890a8; transition: all .2s; }
.period-btn.active, .period-btn:hover { background: #e74c3c; border-color: #e74c3c; color: #fff; }
.toolbar-right { margin-left: auto; font-size: 12px; color: #5a6080; }
.toolbar-right span { color: #2ecc71; margin: 0 4px; }
/* Content */
.content { padding: 20px 32px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 20px; }
.kpi-card { background: #141627; border: 1px solid #1e2235; border-radius: 12px; padding: 18px; position: relative; overflow: hidden; transition: transform .2s, box-shadow .2s; cursor: default; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(0,0,0,0.3); }
.kpi-card::before { content:''; position:absolute; top:0; left:0; right:0; height:3px; }
.kpi-card.red::before{background:linear-gradient(90deg,#e74c3c,#ff6b6b)}
.kpi-card.orange::before{background:linear-gradient(90deg,#f39c12,#f1c40f)}
.kpi-card.green::before{background:linear-gradient(90deg,#27ae60,#2ecc71)}
.kpi-card.blue::before{background:linear-gradient(90deg,#2980b9,#3498db)}
.kpi-card.purple::before{background:linear-gradient(90deg,#8e44ad,#9b59b6)}
.kpi-card.teal::before{background:linear-gradient(90deg,#16a085,#1abc9c)}
.kpi-card.pink::before{background:linear-gradient(90deg,#c0392b,#e91e63)}
.kpi-card.indigo::before{background:linear-gradient(90deg,#3949ab,#5c6bc0)}
.kpi-label { font-size: 11px; color: #6370a0; margin-bottom: 7px; }
.kpi-value { font-size: 26px; font-weight: 700; color: #e0e4f0; line-height: 1; margin-bottom: 8px; }
.kpi-value .unit { font-size: 13px; font-weight: 400; color: #8890a8; margin-left: 2px; }
.kpi-footer { display: flex; align-items: center; justify-content: space-between; font-size: 11px; }
.kpi-change.up { color: #2ecc71; } .kpi-change.down { color: #e74c3c; }
.kpi-sub { color: #5a6080; }
/* Chart Cards */
.chart-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.chart-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.chart-card { background: #141627; border: 1px solid #1e2235; border-radius: 12px; padding: 18px; margin-bottom: 20px; }
.chart-card.no-mb { margin-bottom: 0; }
.chart-card.full { grid-column: 1 / -1; }
.chart-title { font-size: 14px; font-weight: 600; color: #c0c8e8; margin-bottom: 3px; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.chart-title .badge { font-size: 11px; font-weight: 400; background: rgba(231,76,60,0.15); color: #e74c3c; border-radius: 10px; padding: 2px 9px; }
.chart-sub { font-size: 11px; color: #5a6080; margin-bottom: 14px; }
.echart { width: 100%; }
/* Table */
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th { padding: 9px 12px; text-align: left; font-size: 11px; color: #5a6080; font-weight: 500; border-bottom: 1px solid #1e2235; background: #0d0f1a; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid #1a1e30; color: #c0c8e8; }
.data-table tbody tr:hover { background: rgba(231,76,60,0.04); }
.rank-no { width: 22px; height: 22px; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
.rank-1{background:#f39c12;color:#000} .rank-2{background:#95a5a6;color:#000} .rank-3{background:#c0392b;color:#fff} .rank-n{background:#1e2235;color:#8890a8}
.tag { display: inline-block; padding: 2px 7px; border-radius: 8px; font-size: 11px; }
.tag-up{background:rgba(46,204,113,0.15);color:#2ecc71} .tag-down{background:rgba(231,76,60,0.15);color:#e74c3c} .tag-flat{background:rgba(149,165,166,0.15);color:#95a5a6}
.progress-bar-wrap { display: flex; align-items: center; gap: 6px; }
.progress-bar-bg { flex:1; height: 5px; background: #1e2235; border-radius: 3px; overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 3px; }
/* Stats Row */
.stats-row { display: grid; grid-template-columns: repeat(5,1fr); gap: 1px; background: #1e2235; border-radius: 10px; overflow: hidden; margin-bottom: 20px; }
.stats-cell { background: #141627; padding: 14px; text-align: center; }
.stats-cell .s-val { font-size: 18px; font-weight: 700; color: #e0e4f0; }
.stats-cell .s-lab { font-size: 10px; color: #5a6080; margin-top: 3px; }
.stats-cell .s-rate { font-size: 11px; color: #2ecc71; margin-top: 2px; }
/* Promo Timeline */
.promo-timeline { display: flex; flex-direction: column; gap: 10px; }
.promo-item { display: flex; align-items: center; gap: 12px; background: #0d1020; border-radius: 8px; padding: 10px 14px; border-left: 3px solid #e74c3c; }
.promo-item.completed { border-left-color: #2ecc71; opacity: .75; }
.promo-item.upcoming { border-left-color: #f39c12; }
.promo-date { font-size: 12px; font-weight: 600; color: #c0c8e8; min-width: 52px; }
.promo-name { font-size: 13px; font-weight: 600; color: #e0e4f0; }
.promo-meta { font-size: 11px; color: #6370a0; margin-top: 1px; }
.promo-result { margin-left: auto; text-align: right; }
.promo-result .gmv { font-size: 14px; font-weight: 700; color: #f39c12; }
.promo-result .vs { font-size: 10px; color: #5a6080; }
.promo-status { padding: 2px 9px; border-radius: 8px; font-size: 10px; min-width: 50px; text-align: center; }
.s-done{background:rgba(46,204,113,0.15);color:#2ecc71} .s-live{background:rgba(231,76,60,0.2);color:#e74c3c;animation:pulse 2s infinite} .s-plan{background:rgba(243,156,18,0.15);color:#f39c12}
/* ===== 多维分析专属样式 ===== */
.store-selector { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.store-btn { padding: 8px 20px; border-radius: 20px; font-size: 13px; cursor: pointer; border: 1px solid #2a2f45; background: #141627; color: #8890a8; transition: all .2s; display: flex; align-items: center; gap: 6px; }
.store-btn:hover { border-color: #e74c3c; color: #e0e4f0; }
.store-btn.active { background: #e74c3c; border-color: #e74c3c; color: #fff; font-weight: 600; }
.store-btn .star { color: #f39c12; font-size: 11px; }
.product-selector { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.prod-btn { padding: 5px 14px; border-radius: 12px; font-size: 12px; cursor: pointer; border: 1px solid #2a2f45; background: transparent; color: #8890a8; transition: all .2s; }
.prod-btn:hover { border-color: #3498db; color: #3498db; }
.prod-btn.active { background: #2980b9; border-color: #2980b9; color: #fff; }
.time-selector { display: flex; gap: 6px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.time-label { font-size: 12px; color: #6370a0; margin-right: 4px; }
.time-btn { padding: 4px 12px; border-radius: 10px; font-size: 11px; cursor: pointer; border: 1px solid #2a2f45; background: transparent; color: #8890a8; transition: all .2s; }
.time-btn:hover, .time-btn.active { background: #9b59b6; border-color: #9b59b6; color: #fff; }
.multi-kpi-grid { display: grid; grid-template-columns: repeat(6,1fr); gap: 10px; margin-bottom: 16px; }
.mini-kpi { background: #0d1020; border: 1px solid #1e2235; border-radius: 10px; padding: 12px 14px; }
.mini-kpi .mk-label { font-size: 10px; color: #5a6080; margin-bottom: 4px; }
.mini-kpi .mk-value { font-size: 18px; font-weight: 700; color: #e0e4f0; }
.mini-kpi .mk-value .u { font-size: 11px; color: #8890a8; }
.mini-kpi .mk-change { font-size: 10px; margin-top: 3px; }
.mk-up { color: #2ecc71; } .mk-down { color: #e74c3c; }
.compare-table-wrap { overflow-x: auto; margin-top: 10px; }
.section-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0 14px; }
.section-divider .sd-line { flex: 1; height: 1px; background: #1e2235; }
.section-divider .sd-title { font-size: 13px; font-weight: 600; color: #8890a8; white-space: nowrap; }
/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: #0d0f1a; }
::-webkit-scrollbar-thumb { background: #2a2f45; border-radius: 3px; }
@media (max-width: 1200px) {
.kpi-grid { grid-template-columns: repeat(2,1fr); }
.chart-grid-2, .chart-grid-3 { grid-template-columns: 1fr; }
.multi-kpi-grid { grid-template-columns: repeat(3,1fr); }
}
@media (max-width: 768px) {
.content { padding: 14px 16px; }
.tab-bar { padding: 0 16px; }
.toolbar { padding: 8px 16px; }
.header { padding: 12px 16px; }
.multi-kpi-grid { grid-template-columns: repeat(2,1fr); }
}
</style>
</head>
<body>
<!-- Header -->
<div class="header">
<div class="header-left">
<div class="logo">🛒</div>
<div>
<h1>拼多多店铺财务运营数据看板</h1>
<p>多店铺 · 多产品 · 多时间段 · 全维度运营分析</p>
</div>
</div>
<div class="header-right">
<div class="badge-pill" id="dataSourceBadge" style="display:none">📊 数据源: 本地数据</div>
<div class="badge-pill"><span class="status-dot"></span>2026年3月 实时数据</div>
<div class="badge-pill" id="headerStoreBadge">当前:优品生活旗舰店 ⭐4.87</div>
<button class="badge-pill" onclick="refreshData()" style="cursor:pointer;background:#3498db;color:#fff;border:none" title="刷新数据">🔄 刷新</button>
</div>
</div>
<!-- Tab Bar -->
<div class="tab-bar">
<button class="tab-btn active" onclick="switchTab('finance')">💰 财务概览</button>
<button class="tab-btn" onclick="switchTab('multi')">🔍 多维分析</button>
<button class="tab-btn" onclick="switchTab('traffic')">📈 流量分析</button>
<button class="tab-btn" onclick="switchTab('ads')">🎯 广告投放</button>
<button class="tab-btn" onclick="switchTab('products')">📦 商品排行</button>
<button class="tab-btn" onclick="switchTab('promotions')">🎉 活动复盘</button>
</div>
<!-- Toolbar (全局时间筛选) -->
<div class="toolbar">
<div class="period-btns">
<button class="period-btn" onclick="setGlobalPeriod(this,'today')">今日</button>
<button class="period-btn" onclick="setGlobalPeriod(this,'7d')">近7天</button>
<button class="period-btn active" onclick="setGlobalPeriod(this,'30d')">近30天</button>
<button class="period-btn" onclick="setGlobalPeriod(this,'90d')">近90天</button>
<button class="period-btn" onclick="setGlobalPeriod(this,'month')">本月</button>
<button class="period-btn" onclick="setGlobalPeriod(this,'custom')">自定义</button>
</div>
<div class="toolbar-right">环比上期<span>+18.3%</span>· 同比去年<span>+42.7%</span></div>
</div>
<div class="content">
<!-- ======================== TAB: 财务概览 ======================== -->
<div id="panel-finance" class="tab-panel active">
<div class="kpi-grid">
<div class="kpi-card red"><div class="kpi-label">💰 总GMV</div><div class="kpi-value">286.4<span class="unit">万</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 18.3%</span><span class="kpi-sub">目标250万 完成率114.6%</span></div></div>
<div class="kpi-card orange"><div class="kpi-label">💳 实收金额</div><div class="kpi-value">271.8<span class="unit">万</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 16.2%</span><span class="kpi-sub">退款扣减14.6万</span></div></div>
<div class="kpi-card green"><div class="kpi-label">📊 毛利润</div><div class="kpi-value">68.2<span class="unit">万</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 11.5%</span><span class="kpi-sub">毛利率25.1%</span></div></div>
<div class="kpi-card blue"><div class="kpi-label">🏆 净利润</div><div class="kpi-value">38.9<span class="unit">万</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 8.7%</span><span class="kpi-sub">净利率14.3%</span></div></div>
<div class="kpi-card purple"><div class="kpi-label">🛍️ 订单量</div><div class="kpi-value">18,432<span class="unit">单</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 22.4%</span><span class="kpi-sub">日均614单</span></div></div>
<div class="kpi-card teal"><div class="kpi-label">💵 客单价</div><div class="kpi-value">155.4<span class="unit">元</span></div><div class="kpi-footer"><span class="kpi-change down">▼ 3.2%</span><span class="kpi-sub">类目均价142元</span></div></div>
<div class="kpi-card pink"><div class="kpi-label">📦 退款率</div><div class="kpi-value">5.1<span class="unit">%</span></div><div class="kpi-footer"><span class="kpi-change down">▼ 0.8%</span><span class="kpi-sub">类目基准7.2%</span></div></div>
<div class="kpi-card indigo"><div class="kpi-label">🎯 广告ROI</div><div class="kpi-value">3.68<span class="unit">:1</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 0.31</span><span class="kpi-sub">广告花费73.8万</span></div></div>
</div>
<div class="chart-grid-2">
<div class="chart-card no-mb"><div class="chart-title">GMV & 净利润趋势 <span class="badge">近30天</span></div><div class="chart-sub">橙柱=GMV,绿线=净利润,灰柱=退款</div><div id="chartGMV" class="echart" style="height:250px"></div></div>
<div class="chart-card no-mb"><div class="chart-title">成本结构拆解 <span class="badge">本月</span></div><div class="chart-sub">各费用项占实收比例</div><div id="chartCost" class="echart" style="height:250px"></div></div>
</div>
<div style="margin-bottom:20px"></div>
<div class="chart-card"><div class="chart-title">利润漏斗模型</div><div class="chart-sub">从GMV到净利润全链路拆解</div><div id="chartFunnel" class="echart" style="height:180px"></div></div>
<div class="chart-card"><div class="chart-title">月度GMV & 净利率环比 <span class="badge">近12月</span></div><div class="chart-sub">柱=GMV,折线=净利率(%)</div><div id="chartMonthly" class="echart" style="height:250px"></div></div>
</div>
<!-- ======================== TAB: 多维分析 ======================== -->
<div id="panel-multi" class="tab-panel">
<!-- ① 店铺选择器 -->
<div class="section-divider"><div class="sd-line"></div><div class="sd-title">🏪 选择店铺</div><div class="sd-line"></div></div>
<div class="store-selector" id="storeSelector">
<button class="store-btn active" onclick="selectStore(0,this)">🏪 优品生活旗舰店 <span class="star">⭐4.87</span></button>
<button class="store-btn" onclick="selectStore(1,this)">🏪 时尚保温杯专营店 <span class="star">⭐4.68</span></button>
<button class="store-btn" onclick="selectStore(2,this)">🏪 户外运动水具店 <span class="star">⭐4.81</span></button>
<button class="store-btn" onclick="selectStore(3,this)">🏪 企业定制旗舰店 <span class="star">⭐4.92</span></button>
<button class="store-btn" onclick="selectStore(-1,this)" style="border-color:#9b59b6;color:#9b59b6">📊 全店铺对比</button>
</div>
<!-- ② 当前店铺KPI -->
<div id="storeKpiArea"></div>
<!-- ③ 时间段选择器 -->
<div class="section-divider"><div class="sd-line"></div><div class="sd-title">📅 时间段分析</div><div class="sd-line"></div></div>
<div class="time-selector">
<span class="time-label">粒度:</span>
<button class="time-btn active" onclick="setGranularity('day',this)">按日</button>
<button class="time-btn" onclick="setGranularity('week',this)">按周</button>
<button class="time-btn" onclick="setGranularity('month',this)">按月</button>
<span class="time-label" style="margin-left:16px">范围:</span>
<button class="time-btn active" onclick="setRange('30d',this)">近30天</button>
<button class="time-btn" onclick="setRange('90d',this)">近90天</button>
<button class="time-btn" onclick="setRange('6m',this)">近6月</button>
<button class="time-btn" onclick="setRange('1y',this)">近1年</button>
</div>
<div class="chart-grid-2" style="margin-bottom:0">
<div class="chart-card no-mb"><div class="chart-title" id="storeGmvTitle">店铺GMV时间段趋势<span class="badge">近30天·按日</span></div><div class="chart-sub">选中店铺的GMV、订单量、净利润时间走势</div><div id="chartStoreTrend" class="echart" style="height:260px"></div></div>
<div class="chart-card no-mb"><div class="chart-title">核心指标时间段对比 <span class="badge">环比</span></div><div class="chart-sub">点击切换对比维度</div>
<div style="display:flex;gap:6px;margin-bottom:10px;flex-wrap:wrap">
<button class="prod-btn active" onclick="setMetricLine('gmv',this)">GMV</button>
<button class="prod-btn" onclick="setMetricLine('profit',this)">净利润</button>
<button class="prod-btn" onclick="setMetricLine('roi',this)">广告ROI</button>
<button class="prod-btn" onclick="setMetricLine('cvr',this)">转化率</button>
</div>
<div id="chartMetricLine" class="echart" style="height:220px"></div>
</div>
</div>
<div style="margin-bottom:20px"></div>
<!-- ④ 产品选择器 -->
<div class="section-divider"><div class="sd-line"></div><div class="sd-title">📦 产品时间段分析</div><div class="sd-line"></div></div>
<div style="display:flex;align-items:center;gap:10px;margin-bottom:10px;flex-wrap:wrap">
<span style="font-size:12px;color:#6370a0">选择产品:</span>
<div class="product-selector" id="productSelector"></div>
</div>
<div class="chart-grid-3" style="margin-bottom:0">
<div class="chart-card no-mb"><div class="chart-title" id="prodGmvTitle">产品GMV趋势</div><div class="chart-sub">选中产品的GMV时序走势</div><div id="chartProdGmv" class="echart" style="height:200px"></div></div>
<div class="chart-card no-mb"><div class="chart-title" id="prodProfitTitle">产品利润率趋势</div><div class="chart-sub">毛利率 & 净利率变化</div><div id="chartProdProfit" class="echart" style="height:200px"></div></div>
<div class="chart-card no-mb"><div class="chart-title" id="prodRoiTitle">产品广告ROI趋势</div><div class="chart-sub">广告ROI & 花费趋势</div><div id="chartProdRoi" class="echart" style="height:200px"></div></div>
</div>
<div style="margin-bottom:20px"></div>
<!-- ⑤ 跨店铺对比表 -->
<div class="section-divider"><div class="sd-line"></div><div class="sd-title">📊 跨店铺 × 时间段对比明细</div><div class="sd-line"></div></div>
<div class="chart-card">
<div class="chart-title">四店铺核心指标横向对比 <span class="badge">当前时间段</span></div>
<div class="chart-sub">灰底行为全店平均值,点击表头可排序</div>
<div class="compare-table-wrap">
<table class="data-table" id="storeCompareTable">
<thead><tr>
<th onclick="sortTable('storeCompareTable',0)">店铺名称 ⇅</th>
<th onclick="sortTable('storeCompareTable',1)">GMV(万) ⇅</th>
<th onclick="sortTable('storeCompareTable',2)">订单数 ⇅</th>
<th onclick="sortTable('storeCompareTable',3)">客单价(元) ⇅</th>
<th onclick="sortTable('storeCompareTable',4)">毛利率 ⇅</th>
<th onclick="sortTable('storeCompareTable',5)">净利率 ⇅</th>
<th onclick="sortTable('storeCompareTable',6)">广告ROI ⇅</th>
<th onclick="sortTable('storeCompareTable',7)">退款率 ⇅</th>
<th onclick="sortTable('storeCompareTable',8)">GMV环比 ⇅</th>
</tr></thead>
<tbody id="storeCompareBody"></tbody>
</table>
</div>
<div style="margin-top:16px"><div id="chartStoreCmp" class="echart" style="height:200px"></div></div>
</div>
<!-- ⑥ 产品×时间段明细表 -->
<div class="chart-card">
<div class="chart-title">产品 × 时间段全量明细 <span class="badge" id="prodTableBadge">当前店铺 · 近30天</span></div>
<div class="chart-sub">每行=一个产品,展示各时间分段的GMV</div>
<div class="compare-table-wrap">
<table class="data-table" id="prodTimeTable">
<thead id="prodTimeHead"></thead>
<tbody id="prodTimeBody"></tbody>
</table>
</div>
</div>
</div>
<!-- ======================== TAB: 流量分析 ======================== -->
<div id="panel-traffic" class="tab-panel">
<div class="kpi-grid">
<div class="kpi-card red"><div class="kpi-label">👁️ 总曝光量</div><div class="kpi-value">1,284<span class="unit">万</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 32.1%</span><span class="kpi-sub">日均42.8万</span></div></div>
<div class="kpi-card orange"><div class="kpi-label">🖱️ 点击量</div><div class="kpi-value">98.6<span class="unit">万</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 28.4%</span><span class="kpi-sub">点击率7.68%</span></div></div>
<div class="kpi-card green"><div class="kpi-label">🛒 加购数</div><div class="kpi-value">24.7<span class="unit">万</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 19.2%</span><span class="kpi-sub">加购转化25.1%</span></div></div>
<div class="kpi-card blue"><div class="kpi-label">✅ 成交转化率</div><div class="kpi-value">1.87<span class="unit">%</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 0.23%</span><span class="kpi-sub">类目均值1.42%</span></div></div>
</div>
<div class="stats-row">
<div class="stats-cell"><div class="s-val">1,284万</div><div class="s-lab">曝光</div></div>
<div class="stats-cell"><div class="s-val">98.6万</div><div class="s-lab">点击</div><div class="s-rate">点击率7.68%</div></div>
<div class="stats-cell"><div class="s-val">24.7万</div><div class="s-lab">加购</div><div class="s-rate">加购率25.1%</div></div>
<div class="stats-cell"><div class="s-val">2.84万</div><div class="s-lab">下单</div><div class="s-rate">下单率11.5%</div></div>
<div class="stats-cell"><div class="s-val">1.84万</div><div class="s-lab">付款</div><div class="s-rate">支付率64.8%</div></div>
</div>
<div class="chart-grid-2">
<div class="chart-card no-mb"><div class="chart-title">流量来源结构<span class="badge">近30天</span></div><div class="chart-sub">各渠道流量占比</div><div id="chartTrafficSrc" class="echart" style="height:260px"></div></div>
<div class="chart-card no-mb"><div class="chart-title">每日访客 & 转化率趋势</div><div class="chart-sub">蓝柱=UV,红线=转化率</div><div id="chartUV" class="echart" style="height:260px"></div></div>
</div>
<div style="margin-bottom:20px"></div>
<div class="chart-grid-2">
<div class="chart-card no-mb"><div class="chart-title">访客时段分布</div><div class="chart-sub">24小时UV热力分布</div><div id="chartHour" class="echart" style="height:200px"></div></div>
<div class="chart-card no-mb"><div class="chart-title">新老客占比</div><div class="chart-sub">复购率 & 新客成本分析</div><div id="chartNewOld" class="echart" style="height:200px"></div></div>
</div>
</div>
<!-- ======================== TAB: 广告投放 ======================== -->
<div id="panel-ads" class="tab-panel">
<div class="kpi-grid">
<div class="kpi-card red"><div class="kpi-label">💸 广告总花费</div><div class="kpi-value">73.8<span class="unit">万</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 12.4%</span><span class="kpi-sub">占GMV 25.8%</span></div></div>
<div class="kpi-card orange"><div class="kpi-label">🎯 广告GMV</div><div class="kpi-value">271.6<span class="unit">万</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 21.3%</span><span class="kpi-sub">ROI 3.68</span></div></div>
<div class="kpi-card green"><div class="kpi-label">🖱️ 广告点击量</div><div class="kpi-value">62.4<span class="unit">万</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 18.7%</span><span class="kpi-sub">均价¥1.18/次</span></div></div>
<div class="kpi-card blue"><div class="kpi-label">📈 广告转化率</div><div class="kpi-value">2.94<span class="unit">%</span></div><div class="kpi-footer"><span class="kpi-change up">▲ 0.42%</span><span class="kpi-sub">自然流1.43%</span></div></div>
</div>
<div class="chart-grid-2">
<div class="chart-card no-mb"><div class="chart-title">广告类型ROI对比<span class="badge">多多搜索 vs 场景</span></div><div class="chart-sub">红=多多搜索,蓝=多多场景,橙=品牌专区</div><div id="chartAdsROI" class="echart" style="height:260px"></div></div>
<div class="chart-card no-mb"><div class="chart-title">广告花费 & ROI趋势</div><div class="chart-sub">柱=花费,线=ROI</div><div id="chartAdsTrend" class="echart" style="height:260px"></div></div>
</div>
<div style="margin-bottom:20px"></div>
<div class="chart-card">
<div class="chart-title">TOP关键词ROI明细<span class="badge">多多搜索</span></div>
<div class="chart-sub">按消耗排序</div>
<div style="overflow-x:auto;margin-top:10px">
<table class="data-table"><thead><tr><th>关键词</th><th>曝光量</th><th>点击量</th><th>点击率</th><th>花费(元)</th><th>CPC</th><th>订单数</th><th>GMV(元)</th><th>ROI</th><th>状态</th></tr></thead>
<tbody>
<tr><td>保温杯女款大容量</td><td>186,420</td><td>14,230</td><td>7.63%</td><td>16,804</td><td>1.18</td><td>486</td><td>75,330</td><td><b style="color:#2ecc71">4.48</b></td><td><span class="tag tag-up">优质</span></td></tr>
<tr><td>不锈钢保温杯</td><td>142,680</td><td>10,840</td><td>7.60%</td><td>12,392</td><td>1.14</td><td>352</td><td>52,248</td><td><b style="color:#2ecc71">4.22</b></td><td><span class="tag tag-up">优质</span></td></tr>
<tr><td>316不锈钢杯</td><td>98,320</td><td>6,920</td><td>7.04%</td><td>9,246</td><td>1.34</td><td>218</td><td>32,428</td><td><b style="color:#f39c12">3.51</b></td><td><span class="tag tag-up">良好</span></td></tr>
<tr><td>保温杯男生</td><td>74,200</td><td>4,380</td><td>5.90%</td><td>6,132</td><td>1.40</td><td>124</td><td>17,236</td><td><b style="color:#f39c12">2.81</b></td><td><span class="tag tag-flat">观察</span></td></tr>
<tr><td>学生杯子保温</td><td>68,400</td><td>3,980</td><td>5.82%</td><td>5,970</td><td>1.50</td><td>98</td><td>12,740</td><td><b style="color:#e74c3c">2.13</b></td><td><span class="tag tag-down">暂停</span></td></tr>
<tr><td>礼盒保温杯套装</td><td>52,100</td><td>2,680</td><td>5.14%</td><td>4,824</td><td>1.80</td><td>88</td><td>19,272</td><td><b style="color:#2ecc71">3.99</b></td><td><span class="tag tag-up">良好</span></td></tr>
</tbody></table></div>
</div>
</div>
<!-- ======================== TAB: 商品排行 ======================== -->
<div id="panel-products" class="tab-panel">
<div class="chart-grid-2" style="margin-bottom:0">
<div class="chart-card no-mb"><div class="chart-title">TOP10商品GMV排行<span class="badge">近30天</span></div><div class="chart-sub">橙柱=GMV,绿点=利润率</div><div id="chartTopProducts" class="echart" style="height:300px"></div></div>
<div class="chart-card no-mb"><div class="chart-title">商品分类GMV占比</div><div class="chart-sub">各品类贡献分布</div><div id="chartCategory" class="echart" style="height:300px"></div></div>
</div>
<div style="margin-bottom:20px"></div>
<div class="chart-card">
<div class="chart-title">商品全维度数据明细<span class="badge">近30天</span></div>
<div class="chart-sub">按GMV降序排列</div>
<div style="overflow-x:auto;margin-top:10px">
<table class="data-table"><thead><tr><th>排名</th><th>商品名称</th><th>SKU数</th><th>售价(元)</th><th>销量</th><th>GMV(万)</th><th>GMV占比</th><th>毛利率</th><th>退款率</th><th>转化率</th><th>趋势</th></tr></thead>
<tbody id="productsTableBody"></tbody></table></div>
</div>
</div>
<!-- ======================== TAB: 活动复盘 ======================== -->
<div id="panel-promotions" class="tab-panel">
<div class="chart-grid-2">
<div class="chart-card no-mb"><div class="chart-title">历次活动GMV对比<span class="badge">近6场</span></div><div class="chart-sub">柱=活动GMV,线=完成率</div><div id="chartPromoComp" class="echart" style="height:260px"></div></div>
<div class="chart-card no-mb"><div class="chart-title">活动ROI & 毛利率对比</div><div class="chart-sub">红=ROI,绿=毛利率</div><div id="chartPromoROI" class="echart" style="height:260px"></div></div>
</div>
<div style="margin-bottom:20px"></div>
<div class="chart-card">
<div class="chart-title">2026年活动日历与复盘</div>
<div class="chart-sub">绿=已完成,红=进行中,橙=待启动</div>
<div class="promo-timeline" style="margin-top:14px">
<div class="promo-item completed"><div><div class="promo-date">01/01</div><div class="promo-name">元旦跨年狂欢节</div><div class="promo-meta">预热3天·主推保温杯礼盒</div></div><div class="promo-result"><div class="gmv">¥38.2万</div><div class="vs">目标¥35万·完成率109%</div></div><div class="promo-status s-done">已完成</div></div>
<div class="promo-item completed"><div><div class="promo-date">02/14</div><div class="promo-name">情人节专属活动</div><div class="promo-meta">预热5天·情侣对杯套装</div></div><div class="promo-result"><div class="gmv">¥52.6万</div><div class="vs">目标¥45万·完成率117%</div></div><div class="promo-status s-done">已完成</div></div>
<div class="promo-item completed"><div><div class="promo-date">03/08</div><div class="promo-name">女王节女生节</div><div class="promo-meta">预热7天·主推女款颜值系列</div></div><div class="promo-result"><div class="gmv">¥74.3万</div><div class="vs">目标¥60万·完成率124%</div></div><div class="promo-status s-done">已完成</div></div>
<div class="promo-item"><div><div class="promo-date">03/28</div><div class="promo-name">春季焕新大促</div><div class="promo-meta">预热中·全品类联动</div></div><div class="promo-result"><div class="gmv" style="color:#e74c3c">进行中…</div><div class="vs">目标¥80万</div></div><div class="promo-status s-live">进行中</div></div>
<div class="promo-item upcoming"><div><div class="promo-date">05/20</div><div class="promo-name">520情人节</div><div class="promo-meta">T-51天·备货中</div></div><div class="promo-result"><div class="gmv" style="color:#f39c12">¥—</div><div class="vs">目标¥90万</div></div><div class="promo-status s-plan">筹备中</div></div>
<div class="promo-item upcoming"><div><div class="promo-date">06/18</div><div class="promo-name">618年中大促</div><div class="promo-meta">T-80天·策划阶段</div></div><div class="promo-result"><div class="gmv" style="color:#f39c12">¥—</div><div class="vs">目标¥280万</div></div><div class="promo-status s-plan">筹备中</div></div>
</div>
</div>
<div class="chart-card">
<div class="chart-title">活动核心指标汇总<span class="badge">近6场</span></div>
<div style="overflow-x:auto;margin-top:10px">
<table class="data-table"><thead><tr><th>活动名称</th><th>活动时间</th><th>目标GMV</th><th>实际GMV</th><th>完成率</th><th>广告花费</th><th>ROI</th><th>毛利率</th><th>退款率</th><th>新客占比</th></tr></thead>
<tbody>
<tr><td>元旦跨年狂欢</td><td>01/01-01/03</td><td>35万</td><td><b style="color:#2ecc71">38.2万</b></td><td><span class="tag tag-up">109%</span></td><td>9.2万</td><td>4.15</td><td>24.8%</td><td>4.3%</td><td>62%</td></tr>
<tr><td>情人节专属</td><td>02/14-02/15</td><td>45万</td><td><b style="color:#2ecc71">52.6万</b></td><td><span class="tag tag-up">117%</span></td><td>11.8万</td><td>4.46</td><td>26.2%</td><td>5.1%</td><td>58%</td></tr>
<tr><td>女王节女生节</td><td>03/08-03/10</td><td>60万</td><td><b style="color:#2ecc71">74.3万</b></td><td><span class="tag tag-up">124%</span></td><td>16.4万</td><td>4.53</td><td>27.1%</td><td>4.8%</td><td>65%</td></tr>
</tbody></table></div>
</div>
</div>
</div><!-- /content -->
<script>
// ============================================================
// 全局数据定义
// ============================================================
// 数据加载模式:'local' = 本地数据, 'feishu' = 飞书API, 'json' = JSON文件
const DATA_MODE = 'local'; // 切换数据模式
const FEISHU_API_URL = 'http://localhost:3000/api/stores'; // 飞书同步服务地址
// 默认本地数据(备用)
const DEFAULT_STORES = [
{ name:'优品生活旗舰店', star:4.87, color:'#e74c3c',
gmv:286.4, orders:18432, aov:155.4, grossRate:25.1, netRate:14.3, roi:3.68, refund:5.1, growth:18.3,
products:['316不锈钢保温杯-女款', '大容量保温杯-男款', '情侣对杯礼盒', '儿童保温杯卡通款', '保温壶2.5L', '玻璃内胆杯']
},
{ name:'时尚保温杯专营店', star:4.68, color:'#f39c12',
gmv:182.6, orders:11240, aov:162.4, grossRate:22.8, netRate:11.6, roi:3.12, refund:6.8, growth:12.4,
products:['时尚系列保温杯', '莫兰迪色系杯', '网红ins风水杯', '韩系少女杯', '极简设计师款']
},
{ name:'户外运动水具店', star:4.81, color:'#2ecc71',
gmv:124.8, orders:7680, aov:162.5, grossRate:28.4, netRate:16.2, roi:4.21, refund:3.9, growth:-3.2,
products:['运动健身水壶', '户外登山杯', '骑行专用杯', '越野跑补水包', '户外折叠杯']
},
{ name:'企业定制旗舰店', star:4.92, color:'#3498db',
gmv:68.4, orders:2840, aov:240.8, grossRate:31.6, netRate:19.4, roi:5.14, refund:2.1, growth:24.1,
products:['企业LOGO定制杯', '礼品套装定制', '大批量采购款', '高端礼盒定制', '节日专属定制']
}
];
// 当前使用的数据(会被动态加载覆盖)
let STORES = [...DEFAULT_STORES];
// 从飞书API加载数据
async function loadDataFromFeishu() {
try {
console.log('🔄 正在从飞书加载数据...');
const response = await fetch(FEISHU_API_URL);
const result = await response.json();
if (result.success && result.stores && result.stores.length > 0) {
STORES = result.stores;
console.log(`✅ 飞书数据加载成功: ${STORES.length} 家店铺`);
// 更新页面显示
updateDataSourceBadge('飞书同步', result.lastSync);
// 重新渲染所有组件
renderMultiAll();
renderFunnel();
renderTrend();
renderPie();
return true;
} else {
console.warn('⚠️ 飞书数据为空,使用本地数据');
updateDataSourceBadge('本地数据', null);
return false;
}
} catch (error) {
console.error('❌ 飞书数据加载失败:', error);
console.warn('⚠️ 使用本地备用数据');
updateDataSourceBadge('本地数据(离线)', null);
return false;
}
}
// 从JSON文件加载数据
async function loadDataFromJson() {
try {
const response = await fetch('store_data.json');
const result = await response.json();
if (result.stores && result.stores.length > 0) {
STORES = result.stores;
console.log(`✅ JSON数据加载成功: ${STORES.length} 家店铺`);
updateDataSourceBadge('JSON文件', result.lastSync);
return true;
}
} catch (error) {
console.warn('⚠️ JSON文件加载失败,使用本地数据');
}
return false;
}
// 更新数据源标识
function updateDataSourceBadge(source, syncTime) {
const badge = document.getElementById('dataSourceBadge');
if (badge) {
const timeStr = syncTime ? new Date(syncTime).toLocaleString() : '';
badge.innerHTML = `📊 数据源: ${source} ${timeStr ? `<span style="opacity:0.7;font-size:11px">(${timeStr})</span>` : ''}`;
badge.style.display = 'inline-block';
}
}
// 初始化数据加载
async function initData() {
if (DATA_MODE === 'feishu') {
await loadDataFromFeishu();
} else if (DATA_MODE === 'json') {
await loadDataFromJson();
} else {
console.log('📍 使用本地数据模式');
updateDataSourceBadge('本地数据', null);
}
}
// 每家店铺每产品时间段模拟数据生成
function genDays(n) {
const arr=[];
const base=new Date('2026-03-01');
base.setDate(base.getDate()-(n-30));
for(let i=0;i<n;i++){
const d=new Date(base); d.setDate(d.getDate()+i);
arr.push(`${d.getMonth()+1}/${d.getDate()}`);
}
return arr;
}
function genWeeks(n){return Array.from({length:n},(_,i)=>`W${i+1}`);}
function genMonths(n){const m=['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'];return m.slice(0,n);}
function randArr(n, base, amp) { return Array.from({length:n},()=>+(base+amp*(Math.random()-0.5)*2).toFixed(2)); }
function randArrInt(n, base, amp) { return Array.from({length:n},()=>Math.round(base+amp*(Math.random()-0.5)*2)); }
// 当前选中状态
let curStore = 0; // 0-3 或 -1(全部)
let curProduct = 0; // 产品索引
let curGranularity = 'day';
let curRange = '30d';
let curMetricLine = 'gmv';
// ============================================================
// 颜色 & 图表基础配置
// ============================================================
const C = { red:'#e74c3c',orange:'#f39c12',green:'#2ecc71',blue:'#3498db',purple:'#9b59b6',teal:'#1abc9c',dark:'#141627',grid:'#1e2235',text:'#8890a8',axis:'#2a2f45' };
const baseOpt = {
backgroundColor:'transparent',
textStyle:{color:C.text,fontFamily:'PingFang SC,Microsoft YaHei,sans-serif'},
grid:{top:40,right:20,bottom:36,left:60,containLabel:true},
tooltip:{backgroundColor:'#0d0f1a',borderColor:C.grid,textStyle:{color:'#e0e4f0'},trigger:'axis'}
};
// ============================================================
// Tab & Period 切换
// ============================================================
function switchTab(name){
document.querySelectorAll('.tab-btn').forEach(b=>{
b.classList.toggle('active', b.getAttribute('onclick').includes(`'${name}'`));
});
document.querySelectorAll('.tab-panel').forEach(p=>p.classList.remove('active'));
document.getElementById('panel-'+name).classList.add('active');
setTimeout(()=>window.dispatchEvent(new Event('resize')),60);
if(name==='multi') renderMultiAll();
}
function setGlobalPeriod(btn,key){ document.querySelectorAll('.period-btn').forEach(b=>b.classList.remove('active')); btn.classList.add('active'); }
function setPeriod(btn){ document.querySelectorAll('.period-btn').forEach(b=>b.classList.remove('active')); btn.classList.add('active'); }
// ============================================================
// 工具:获取时间轴
// ============================================================
function getTimeAxis(){
const n = curRange==='30d'?30 : curRange==='90d'?90 : curRange==='6m'?6 : 12;
if(curGranularity==='day') return genDays(Math.min(n,90));
if(curGranularity==='week') return genWeeks(Math.min(Math.ceil(n/7),52));
return genMonths(n);
}
// ============================================================
// 多维分析 渲染总入口
// ============================================================
function renderMultiAll(){
renderStoreKpi();
renderStoreTrend();
renderMetricLine();
renderProductSelector();
renderProdCharts();
renderStoreCompare();
renderProdTimeTable();
}
// ① 店铺KPI小卡片
function renderStoreKpi(){
const area = document.getElementById('storeKpiArea');
if(curStore===-1){
// 全店铺汇总
const totalGmv = STORES.reduce((s,x)=>s+x.gmv,0).toFixed(1);
const totalOrders = STORES.reduce((s,x)=>s+x.orders,0).toLocaleString();
area.innerHTML=`<div class="multi-kpi-grid">
<div class="mini-kpi"><div class="mk-label">🏪 店铺数量</div><div class="mk-value">4<span class="u">家</span></div></div>
<div class="mini-kpi"><div class="mk-label">💰 汇总GMV</div><div class="mk-value">${totalGmv}<span class="u">万</span></div></div>
<div class="mini-kpi"><div class="mk-label">🛍️ 汇总订单</div><div class="mk-value">${totalOrders}<span class="u">单</span></div></div>
<div class="mini-kpi"><div class="mk-label">📈 最高ROI</div><div class="mk-value" style="color:#2ecc71">5.14</div><div class="mk-change mk-up">企业定制旗舰店</div></div>
<div class="mini-kpi"><div class="mk-label">📦 最低退款率</div><div class="mk-value" style="color:#2ecc71">2.1%</div><div class="mk-change mk-up">企业定制旗舰店</div></div>
<div class="mini-kpi"><div class="mk-label">🏆 最高增速</div><div class="mk-value" style="color:#2ecc71">+24.1%</div><div class="mk-change mk-up">企业定制旗舰店</div></div>
</div>`;
} else {
const s = STORES[curStore];
area.innerHTML=`<div class="multi-kpi-grid">
<div class="mini-kpi"><div class="mk-label">💰 GMV</div><div class="mk-value">${s.gmv}<span class="u">万</span></div><div class="mk-change ${s.growth>=0?'mk-up':'mk-down'}">${s.growth>=0?'▲':'▼'}${Math.abs(s.growth)}%</div></div>
<div class="mini-kpi"><div class="mk-label">🛍️ 订单数</div><div class="mk-value">${s.orders.toLocaleString()}<span class="u">单</span></div></div>
<div class="mini-kpi"><div class="mk-label">💵 客单价</div><div class="mk-value">${s.aov}<span class="u">元</span></div></div>
<div class="mini-kpi"><div class="mk-label">📊 毛利率</div><div class="mk-value" style="color:#2ecc71">${s.grossRate}<span class="u">%</span></div></div>
<div class="mini-kpi"><div class="mk-label">🏆 净利率</div><div class="mk-value" style="color:#3498db">${s.netRate}<span class="u">%</span></div></div>
<div class="mini-kpi"><div class="mk-label">🎯 广告ROI</div><div class="mk-value" style="color:#f39c12">${s.roi}<span class="u">:1</span></div></div>
</div>`;
}
}
// ② 店铺GMV时间趋势
function renderStoreTrend(){
const axis = getTimeAxis();
const n = axis.length;
const c = echarts.getInstanceByDom(document.getElementById('chartStoreTrend')) || echarts.init(document.getElementById('chartStoreTrend'));
let series=[];
if(curStore===-1){
STORES.forEach(s=>{
series.push({name:s.name,type:'line',smooth:true,symbolSize:4,data:randArr(n,s.gmv/30*1,(s.gmv/30*1)*0.3),lineStyle:{width:2},itemStyle:{color:s.color}});
});
} else {
const s=STORES[curStore];
const gmv=randArr(n,s.gmv/30*1,(s.gmv/30)*0.25);
const orders=randArrInt(n,s.orders/30,s.orders/30*0.2);
series=[
{name:'GMV(万)',type:'bar',data:gmv,barMaxWidth:14,yAxisIndex:0,
itemStyle:{color:new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:s.color},{offset:1,color:s.color+'33'}])}},
{name:'订单数',type:'line',data:orders,smooth:true,symbolSize:4,yAxisIndex:1,
lineStyle:{color:C.orange,width:2},itemStyle:{color:C.orange}}
];
}
const yAxis = curStore===-1
? [{type:'value',name:'GMV(万)',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text}}]
: [
{type:'value',name:'GMV(万)',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text}},
{type:'value',name:'订单数',splitLine:{show:false},axisLabel:{color:C.text}}
];
c.setOption({...baseOpt,
legend:{top:6,textStyle:{color:C.text}},
xAxis:{type:'category',data:axis,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text,fontSize:10,rotate:axis.length>20?30:0}},
yAxis, series
});
}
// ③ 指标折线
function renderMetricLine(){
const axis=getTimeAxis(), n=axis.length;
const c=echarts.getInstanceByDom(document.getElementById('chartMetricLine'))||echarts.init(document.getElementById('chartMetricLine'));
const metricConf={
gmv:{name:'GMV(万)',base:s=>s.gmv/30,amp:0.25,color:'#e74c3c'},
profit:{name:'净利润(万)',base:s=>s.gmv*s.netRate/100/30,amp:0.3,color:'#2ecc71'},
roi:{name:'广告ROI',base:s=>s.roi,amp:0.15,color:'#f39c12'},
cvr:{name:'转化率%',base:s=>1.8+curStore*0.2,amp:0.1,color:'#3498db'}
};
const m=metricConf[curMetricLine];
const series = curStore===-1
? STORES.map(s=>({name:s.name,type:'line',smooth:true,symbolSize:4,data:randArr(n,m.base(s),m.base(s)*m.amp),lineStyle:{width:2},itemStyle:{color:s.color}}))
: [{name:m.name,type:'line',smooth:true,symbolSize:5,data:randArr(n,m.base(STORES[Math.max(curStore,0)]),m.base(STORES[Math.max(curStore,0)])*m.amp),
lineStyle:{color:m.color,width:2.5},itemStyle:{color:m.color},
areaStyle:{color:new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:m.color+'33'},{offset:1,color:'transparent'}])}}];
c.setOption({...baseOpt,legend:{top:6,textStyle:{color:C.text}},
xAxis:{type:'category',data:axis,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text,fontSize:10,rotate:n>20?30:0}},
yAxis:{type:'value',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text}},
series
});
}
// ④ 产品选择器
function renderProductSelector(){
const products = curStore>=0 ? STORES[curStore].products : STORES[0].products;
const sel=document.getElementById('productSelector');
sel.innerHTML=products.map((p,i)=>
`<button class="prod-btn ${i===curProduct?'active':''}" onclick="selectProduct(${i},this)">${p}</button>`
).join('');
}
function selectProduct(idx, btn){
curProduct=idx;
document.querySelectorAll('#productSelector .prod-btn').forEach(b=>b.classList.remove('active'));
btn.classList.add('active');
renderProdCharts();
}
// ⑤ 产品图表(GMV / 利润率 / ROI)
function renderProdCharts(){
const axis=getTimeAxis(), n=axis.length;
const s=STORES[Math.max(curStore,0)];
const prodName=s.products[curProduct]||s.products[0];
// GMV
const cg=echarts.getInstanceByDom(document.getElementById('chartProdGmv'))||echarts.init(document.getElementById('chartProdGmv'));
const gmvBase=s.gmv/s.products.length/n;
const gmvData=randArr(n,gmvBase*n/n,gmvBase*0.4);
cg.setOption({...baseOpt,grid:{top:30,right:14,bottom:32,left:50,containLabel:true},
xAxis:{type:'category',data:axis,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text,fontSize:9,rotate:axis.length>15?30:0}},
yAxis:{type:'value',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text,fontSize:10}},
series:[{name:prodName,type:'bar',data:gmvData,barMaxWidth:16,
itemStyle:{color:new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:s.color},{offset:1,color:s.color+'33'}])}}]
});
document.getElementById('prodGmvTitle').innerHTML=`${prodName} GMV`;
// 利润率
const cp=echarts.getInstanceByDom(document.getElementById('chartProdProfit'))||echarts.init(document.getElementById('chartProdProfit'));
cp.setOption({...baseOpt,grid:{top:30,right:14,bottom:32,left:50,containLabel:true},
legend:{top:4,textStyle:{color:C.text},itemWidth:12},
xAxis:{type:'category',data:axis,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text,fontSize:9,rotate:axis.length>15?30:0}},
yAxis:{type:'value',name:'%',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text,fontSize:10,formatter:'{value}%'}},
series:[
{name:'毛利率',type:'line',smooth:true,symbolSize:3,data:randArr(n,s.grossRate,2),lineStyle:{color:C.green,width:2},itemStyle:{color:C.green}},
{name:'净利率',type:'line',smooth:true,symbolSize:3,data:randArr(n,s.netRate,1.5),lineStyle:{color:C.teal,width:2},itemStyle:{color:C.teal}}
]
});
// ROI
const cr=echarts.getInstanceByDom(document.getElementById('chartProdRoi'))||echarts.init(document.getElementById('chartProdRoi'));
const roiData=randArr(n,s.roi,0.4);
const costData=randArr(n,s.gmv/30*0.25,0.05);
cr.setOption({...baseOpt,grid:{top:30,right:14,bottom:32,left:50,containLabel:true},
legend:{top:4,textStyle:{color:C.text},itemWidth:12},
xAxis:{type:'category',data:axis,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text,fontSize:9,rotate:axis.length>15?30:0}},
yAxis:[
{type:'value',name:'ROI',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text,fontSize:10}},
{type:'value',name:'花费(万)',splitLine:{show:false},axisLabel:{color:C.text,fontSize:10}}
],
series:[
{name:'广告ROI',type:'line',smooth:true,symbolSize:3,data:roiData,lineStyle:{color:C.orange,width:2},itemStyle:{color:C.orange}},
{name:'广告花费',type:'bar',yAxisIndex:1,data:costData,barMaxWidth:10,itemStyle:{color:'rgba(155,89,182,0.5)'}}
]
});
}
// ⑥ 跨店铺对比表 + 雷达图
function renderStoreCompare(){
const tbody=document.getElementById('storeCompareBody');
const rows=STORES.map(s=>`<tr>
<td><span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:${s.color};margin-right:6px"></span>${s.name}</td>
<td><b style="color:#f39c12">${s.gmv}</b></td>
<td>${s.orders.toLocaleString()}</td>
<td>¥${s.aov}</td>
<td style="color:#2ecc71">${s.grossRate}%</td>
<td style="color:#3498db">${s.netRate}%</td>
<td style="color:${s.roi>=4?'#2ecc71':s.roi>=3?'#f39c12':'#e74c3c'}">${s.roi}</td>
<td style="color:${s.refund<=4?'#2ecc71':s.refund<=6?'#f39c12':'#e74c3c'}">${s.refund}%</td>
<td><span class="tag ${s.growth>=0?'tag-up':'tag-down'}">${s.growth>=0?'▲':'▼'}${Math.abs(s.growth)}%</span></td>
</tr>`);
// 均值行
const avg={gmv:(STORES.reduce((s,x)=>s+x.gmv,0)/4).toFixed(1),orders:Math.round(STORES.reduce((s,x)=>s+x.orders,0)/4),aov:(STORES.reduce((s,x)=>s+x.aov,0)/4).toFixed(1),grossRate:(STORES.reduce((s,x)=>s+x.grossRate,0)/4).toFixed(1),netRate:(STORES.reduce((s,x)=>s+x.netRate,0)/4).toFixed(1),roi:(STORES.reduce((s,x)=>s+x.roi,0)/4).toFixed(2),refund:(STORES.reduce((s,x)=>s+x.refund,0)/4).toFixed(1),growth:(STORES.reduce((s,x)=>s+x.growth,0)/4).toFixed(1)};
rows.push(`<tr style="background:#0d1020;font-style:italic"><td style="color:#6370a0">📊 全店平均</td><td>${avg.gmv}</td><td>${avg.orders.toLocaleString()}</td><td>¥${avg.aov}</td><td>${avg.grossRate}%</td><td>${avg.netRate}%</td><td>${avg.roi}</td><td>${avg.refund}%</td><td>${avg.growth}%</td></tr>`);
tbody.innerHTML=rows.join('');
// 雷达图
const cc=echarts.getInstanceByDom(document.getElementById('chartStoreCmp'))||echarts.init(document.getElementById('chartStoreCmp'));
cc.setOption({
backgroundColor:'transparent',
legend:{top:4,textStyle:{color:C.text},data:STORES.map(s=>s.name)},
radar:{center:['50%','55%'],radius:'65%',
indicator:[{name:'GMV规模',max:350},{name:'毛利率',max:40},{name:'净利率',max:25},{name:'广告ROI',max:6},{name:'客单价',max:280},{name:'增速',max:30}],
axisName:{color:C.text,fontSize:11},splitLine:{lineStyle:{color:C.grid}},splitArea:{show:false},axisLine:{lineStyle:{color:C.axis}}
},
tooltip:{backgroundColor:'#0d0f1a',borderColor:C.grid,textStyle:{color:'#e0e4f0'}},
series:[{type:'radar',data:STORES.map(s=>({name:s.name,value:[s.gmv,s.grossRate,s.netRate,s.roi,s.aov,Math.max(s.growth,0)],
lineStyle:{width:2,color:s.color},itemStyle:{color:s.color},areaStyle:{opacity:0.1,color:s.color}}))}]
});
}
// ⑦ 产品×时间段明细表
function renderProdTimeTable(){
const s=STORES[Math.max(curStore,0)];
const axis=getTimeAxis(); const n=axis.length;
// 最多显示6个时间段
const step=Math.max(1,Math.floor(n/6));
const cols=[];
for(let i=0;i<n;i+=step) cols.push(axis[i]);
const thead=document.getElementById('prodTimeHead');
const tbody=document.getElementById('prodTimeBody');
thead.innerHTML='<tr><th>产品名称</th>'+cols.map(c=>`<th>${c}</th>`).join('')+'<th>区间合计</th><th>趋势</th></tr>';
const badge=document.getElementById('prodTableBadge');
badge.textContent=(curStore>=0?s.name:'全店铺')+' · '+curRange+(curGranularity==='day'?'·按日':curGranularity==='week'?'·按周':'·按月');
tbody.innerHTML=s.products.map((p,pi)=>{
const base=s.gmv/s.products.length/cols.length*(0.8+pi*0.05);
const vals=cols.map(()=>+(base*(0.7+Math.random()*0.6)).toFixed(2));
const total=vals.reduce((a,b)=>a+b,0).toFixed(2);
const trend=vals[vals.length-1]>vals[0];
return `<tr>
<td style="white-space:nowrap">${p}</td>
${vals.map((v,i)=>`<td style="color:${i===vals.indexOf(Math.max(...vals))?'#f39c12':i===vals.indexOf(Math.min(...vals))?'#e74c3c':'#c0c8e8'}">${v}</td>`).join('')}
<td><b style="color:#f39c12">${total}</b></td>
<td><span class="tag ${trend?'tag-up':'tag-down'}">${trend?'↗ 上升':'↘ 下降'}</span></td>
</tr>`;
}).join('');
}
// ============================================================
// 多维分析交互函数
// ============================================================
function selectStore(idx, btn){
curStore=idx;
document.querySelectorAll('#storeSelector .store-btn').forEach(b=>b.classList.remove('active'));
btn.classList.add('active');
const hdr=document.getElementById('headerStoreBadge');
hdr.textContent=idx>=0?`当前:${STORES[idx].name} ⭐${STORES[idx].star}`:'全店铺对比模式';
curProduct=0;
renderStoreKpi();
renderStoreTrend();
renderMetricLine();
renderProductSelector();
renderProdCharts();
renderStoreCompare();
renderProdTimeTable();
}
function setGranularity(g, btn){
curGranularity=g;
document.querySelectorAll('.time-btn').forEach(b=>{
if(['按日','按周','按月'].some(t=>b.textContent.includes(t.slice(1)))) b.classList.remove('active');
});
btn.classList.add('active');
renderStoreTrend(); renderMetricLine(); renderProdCharts(); renderProdTimeTable();
}
function setRange(r, btn){
curRange=r;
// 只对range按钮生效
const rangeBtns=['近30天','近90天','近6月','近1年'];
document.querySelectorAll('.time-btn').forEach(b=>{
if(rangeBtns.some(t=>b.textContent===t)) b.classList.remove('active');
});
btn.classList.add('active');
renderStoreTrend(); renderMetricLine(); renderProdCharts(); renderProdTimeTable();
}
function setMetricLine(m, btn){
curMetricLine=m;
document.querySelectorAll('#panel-multi .prod-btn').forEach(b=>b.classList.remove('active'));
btn.classList.add('active');
renderMetricLine();
}
// ============================================================
// 原有Tab图表初始化
// ============================================================
const days30 = Array.from({length:30},(_,i)=>{const d=new Date('2026-03-01');d.setDate(d.getDate()+i);return`${d.getMonth()+1}/${d.getDate()}`;});
// GMV趋势
(function(){
const c=echarts.init(document.getElementById('chartGMV'));
const gmv=days30.map(()=>+(Math.random()*3+7.5).toFixed(1));
const profit=gmv.map(v=>+(v*(0.12+Math.random()*0.05)).toFixed(2));
const refund=gmv.map(v=>+(v*(0.03+Math.random()*0.03)).toFixed(2));
c.setOption({...baseOpt,
legend:{top:6,textStyle:{color:C.text},data:['GMV(万)','净利润(万)','退款(万)']},
xAxis:{type:'category',data:days30,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text,fontSize:10}},
yAxis:{type:'value',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text}},
series:[
{name:'GMV(万)',type:'bar',data:gmv,barMaxWidth:12,itemStyle:{color:new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:'#e74c3c'},{offset:1,color:'rgba(231,76,60,0.2)'}])}},
{name:'净利润(万)',type:'line',data:profit,smooth:true,symbolSize:4,lineStyle:{color:C.green,width:2},itemStyle:{color:C.green},areaStyle:{color:new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:'rgba(46,204,113,0.2)'},{offset:1,color:'transparent'}])}},
{name:'退款(万)',type:'bar',data:refund,barMaxWidth:6,itemStyle:{color:'rgba(149,165,166,0.4)'}}
]
});
})();
// 成本结构
(function(){
const c=echarts.init(document.getElementById('chartCost'));
c.setOption({...baseOpt,
tooltip:{trigger:'item',backgroundColor:'#0d0f1a',borderColor:C.grid,textStyle:{color:'#e0e4f0'},formatter:'{b}: {c}万 ({d}%)'},
legend:{orient:'vertical',right:8,top:'middle',textStyle:{color:C.text}},
series:[{type:'pie',radius:['40%','70%'],center:['38%','50%'],
label:{show:true,formatter:'{b}\n{d}%',color:'#c0c8e8',fontSize:11},
data:[
{value:68.2,name:'净利润',itemStyle:{color:'#2ecc71'}},{value:50.4,name:'商品成本',itemStyle:{color:'#3498db'}},
{value:73.8,name:'广告花费',itemStyle:{color:'#e74c3c'}},{value:28.6,name:'平台佣金',itemStyle:{color:'#f39c12'}},
{value:18.2,name:'物流费用',itemStyle:{color:'#9b59b6'}},{value:14.6,name:'退款损失',itemStyle:{color:'#95a5a6'}},
{value:18.0,name:'其他费用',itemStyle:{color:'#1abc9c'}}
]
}]
});
})();
// 利润漏斗
(function(){
const c=echarts.init(document.getElementById('chartFunnel'));
c.setOption({...baseOpt,grid:undefined,tooltip:{trigger:'item',formatter:'{b}: {c}万元'},
series:[{type:'funnel',left:'5%',width:'90%',top:10,bottom:10,sort:'descending',
label:{show:true,position:'inside',color:'#fff',fontSize:12,fontWeight:600,formatter:p=>p.name+' ¥'+p.value+'万'},
itemStyle:{borderWidth:0},
data:[
{value:286.4,name:'GMV',itemStyle:{color:'#e74c3c'}},{value:271.8,name:'实收金额',itemStyle:{color:'#e67e22'}},
{value:220.4,name:'扣除成本',itemStyle:{color:'#f39c12'}},{value:170.0,name:'扣除广告',itemStyle:{color:'#27ae60'}},
{value:141.4,name:'扣除佣金',itemStyle:{color:'#2980b9'}},{value:107.8,name:'扣除物流',itemStyle:{color:'#8e44ad'}},
{value:68.2,name:'毛利润',itemStyle:{color:'#16a085'}},{value:38.9,name:'净利润',itemStyle:{color:'#2ecc71'}}
]
}]
});
})();
// 月度GMV
(function(){
const c=echarts.init(document.getElementById('chartMonthly'));
const months=['4月','5月','6月','7月','8月','9月','10月','11月','12月','1月','2月','3月'];
const gmvData=[168,194,282,156,172,188,201,486,218,183,248,286];
const rateData=[12.3,13.1,11.8,12.8,13.4,14.1,13.9,10.2,13.8,14.2,14.8,14.3];
c.setOption({...baseOpt,
legend:{top:6,textStyle:{color:C.text},data:['月GMV(万)','净利率(%)']},
xAxis:{type:'category',data:months,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text}},
yAxis:[
{type:'value',name:'GMV(万)',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text}},
{type:'value',name:'净利率%',min:8,max:20,splitLine:{show:false},axisLabel:{color:C.text,formatter:'{value}%'}}
],
series:[
{name:'月GMV(万)',type:'bar',data:gmvData,barMaxWidth:26,itemStyle:{color:new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:'#e74c3c'},{offset:1,color:'rgba(231,76,60,0.3)'}])},markPoint:{data:[{type:'max',name:'最高',itemStyle:{color:'#f39c12'}}]}},
{name:'净利率(%)',type:'line',yAxisIndex:1,data:rateData,smooth:true,symbolSize:5,lineStyle:{color:C.green,width:2.5},itemStyle:{color:C.green}}
]
});
})();
// 流量来源
(function(){
const c=echarts.init(document.getElementById('chartTrafficSrc'));
c.setOption({...baseOpt,
tooltip:{trigger:'item',formatter:'{b}: {c}万UV ({d}%)',backgroundColor:'#0d0f1a',borderColor:C.grid,textStyle:{color:'#e0e4f0'}},
legend:{orient:'vertical',right:0,top:'middle',textStyle:{color:C.text}},
series:[{type:'pie',radius:['35%','68%'],center:['40%','50%'],roseType:'area',
label:{show:true,formatter:'{d}%',fontSize:11,color:'#c0c8e8'},
data:[
{value:32.4,name:'多多搜索(自然)',itemStyle:{color:'#e74c3c'}},{value:24.8,name:'多多搜索(广告)',itemStyle:{color:'#ff8a80'}},
{value:16.2,name:'多多场景推荐',itemStyle:{color:'#f39c12'}},{value:12.6,name:'活动会场',itemStyle:{color:'#2ecc71'}},
{value:8.4,name:'直播带货',itemStyle:{color:'#3498db'}},{value:5.6,name:'外部引流',itemStyle:{color:'#9b59b6'}}
]
}]
});
})();
// UV趋势
(function(){
const c=echarts.init(document.getElementById('chartUV'));
const uv=days30.map(()=>Math.floor(Math.random()*8000+12000));
const cvr=days30.map(()=>+(Math.random()*0.6+1.5).toFixed(2));
c.setOption({...baseOpt,
legend:{top:6,textStyle:{color:C.text},data:['日UV','转化率%']},
xAxis:{type:'category',data:days30,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text,fontSize:10}},
yAxis:[
{type:'value',name:'UV',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text}},
{type:'value',name:'转化率%',min:0,max:4,splitLine:{show:false},axisLabel:{color:C.text,formatter:'{value}%'}}
],
series:[
{name:'日UV',type:'bar',data:uv,barMaxWidth:10,itemStyle:{color:new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:'#3498db'},{offset:1,color:'rgba(52,152,219,0.2)'}])}},
{name:'转化率%',type:'line',yAxisIndex:1,data:cvr,smooth:true,symbolSize:4,lineStyle:{color:C.red,width:2},itemStyle:{color:C.red}}
]
});
})();
// 时段热力
(function(){
const c=echarts.init(document.getElementById('chartHour'));
const hours=Array.from({length:24},(_,i)=>`${i}:00`);
const data=[120,80,60,45,40,55,180,420,560,480,390,340,520,460,380,410,490,620,740,860,920,780,540,280];
c.setOption({...baseOpt,
xAxis:{type:'category',data:hours,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text,fontSize:10}},
yAxis:{type:'value',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text}},
tooltip:{trigger:'axis'},
series:[{type:'bar',data:data,barMaxWidth:18,
itemStyle:{color:p=>{const v=p.value/920;return new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:`rgba(231,76,60,${0.4+v*0.6})`},{offset:1,color:`rgba(231,76,60,${0.1+v*0.2})`}]);}},
markArea:{silent:true,itemStyle:{color:'rgba(243,156,18,0.05)'},data:[[{xAxis:'19:00'},{xAxis:'23:00'}]]}
}]
});
})();
// 新老客
(function(){
const c=echarts.init(document.getElementById('chartNewOld'));
c.setOption({...baseOpt,
tooltip:{trigger:'item',formatter:'{b}: {d}%',backgroundColor:'#0d0f1a',borderColor:C.grid,textStyle:{color:'#e0e4f0'}},
legend:{bottom:6,textStyle:{color:C.text}},
series:[{type:'pie',radius:['38%','62%'],center:['50%','44%'],
label:{show:true,formatter:'{b}\n{d}%',color:'#c0c8e8'},
data:[{value:62,name:'新客',itemStyle:{color:'#e74c3c'}},{value:38,name:'老客(复购)',itemStyle:{color:'#2ecc71'}}]
}]
});
})();
// 广告ROI对比
(function(){
const c=echarts.init(document.getElementById('chartAdsROI'));
const wk=['第1周','第2周','第3周','第4周'];
c.setOption({...baseOpt,
legend:{top:6,textStyle:{color:C.text}},
xAxis:{type:'category',data:wk,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text}},
yAxis:{type:'value',name:'ROI',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text},min:0,max:7},
series:[
{name:'多多搜索',type:'bar',data:[3.8,4.1,4.4,4.2],barMaxWidth:26,itemStyle:{color:'#e74c3c'},markLine:{data:[{yAxis:3,lineStyle:{color:'#e74c3c',type:'dashed'},label:{formatter:'保本线',color:C.red}}]}},
{name:'多多场景',type:'bar',data:[2.8,3.1,3.4,3.2],barMaxWidth:26,itemStyle:{color:'#3498db'}},
{name:'品牌专区',type:'bar',data:[4.2,4.8,5.1,4.9],barMaxWidth:26,itemStyle:{color:'#f39c12'}}
]
});
})();
// 广告花费趋势
(function(){
const c=echarts.init(document.getElementById('chartAdsTrend'));
const cost=days30.map(()=>+(Math.random()*1+1.8).toFixed(2));
const roi=days30.map(()=>+(Math.random()*1.2+3).toFixed(2));
c.setOption({...baseOpt,
legend:{top:6,textStyle:{color:C.text},data:['日广告花费(万)','当日ROI']},
xAxis:{type:'category',data:days30,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text,fontSize:10}},
yAxis:[
{type:'value',name:'花费(万)',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text}},
{type:'value',name:'ROI',min:1,max:6,splitLine:{show:false},axisLabel:{color:C.text}}
],
series:[
{name:'日广告花费(万)',type:'bar',data:cost,barMaxWidth:10,itemStyle:{color:new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:'#e74c3c'},{offset:1,color:'rgba(231,76,60,0.2)'}])}},
{name:'当日ROI',type:'line',yAxisIndex:1,data:roi,smooth:true,symbolSize:4,lineStyle:{color:C.orange,width:2.5},itemStyle:{color:C.orange},areaStyle:{color:new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:'rgba(243,156,18,0.15)'},{offset:1,color:'transparent'}])}}
]
});
})();
// 商品排行
(function(){
const products=[
{name:'316不锈钢保温杯-女款粉色500ML',sku:6,price:128,sales:2840,gmv:36.4,pct:12.7,margin:28.4,refund:3.2,cvr:2.84},
{name:'大容量保温杯男款军绿1000ML',sku:4,price:148,sales:2180,gmv:32.2,pct:11.2,margin:26.8,refund:4.1,cvr:2.54},
{name:'情侣对杯礼盒装经典款',sku:3,price:268,sales:1020,gmv:27.3,pct:9.5,margin:31.2,refund:5.8,cvr:1.86},
{name:'儿童保温杯卡通图案380ML',sku:8,price:68,sales:3640,gmv:24.7,pct:8.6,margin:22.4,refund:4.8,cvr:3.12},
{name:'316保温壶2.5L大容量家用',sku:3,price:198,sales:1120,gmv:22.2,pct:7.7,margin:29.6,refund:3.9,cvr:1.68},
{name:'玻璃内胆保温杯480ML',sku:5,price:158,sales:1280,gmv:20.2,pct:7.0,margin:24.2,refund:6.2,cvr:2.08},
{name:'运动水壶健身男款700ML',sku:4,price:88,sales:2020,gmv:17.8,pct:6.2,margin:20.8,refund:5.4,cvr:2.32},
{name:'高颜值小众设计师联名杯',sku:2,price:218,sales:720,gmv:15.7,pct:5.5,margin:34.6,refund:4.2,cvr:1.48},
{name:'公司定制LOGO保温杯',sku:1,price:128,sales:1080,gmv:13.8,pct:4.8,margin:18.4,refund:2.8,cvr:4.62},
{name:'钛合金超轻保温杯',sku:3,price:368,sales:320,gmv:11.8,pct:4.1,margin:38.2,refund:3.8,cvr:0.92},
];
const tbody=document.getElementById('productsTableBody');
const colors=['rank-1','rank-2','rank-3'];
tbody.innerHTML=products.map((p,i)=>{
const rankCls=i<3?colors[i]:'rank-n';
const trendCls=Math.random()>0.3?'tag-up':'tag-down';
const trend=trendCls==='tag-up'?`▲${(Math.random()*15+3).toFixed(1)}%`:`▼${(Math.random()*8+1).toFixed(1)}%`;
const w=(p.gmv/36.4*100).toFixed(0);
return `<tr>
<td><span class="rank-no ${rankCls}">${i+1}</span></td>
<td style="max-width:200px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis" title="${p.name}">${p.name}</td>
<td>${p.sku}</td><td>¥${p.price}</td><td>${p.sales.toLocaleString()}</td>
<td><b style="color:#f39c12">${p.gmv}</b></td>
<td><div class="progress-bar-wrap"><div class="progress-bar-bg"><div class="progress-bar-fill" style="width:${w}%;background:#e74c3c"></div></div><span style="font-size:10px;color:#8890a8;min-width:32px">${p.pct}%</span></div></td>
<td style="color:#2ecc71">${p.margin}%</td>
<td style="color:${p.refund>5.5?'#e74c3c':'#95a5a6'}">${p.refund}%</td>
<td>${p.cvr}%</td>
<td><span class="tag ${trendCls}">${trend}</span></td>
</tr>`;
}).join('');
const c=echarts.init(document.getElementById('chartTopProducts'));
c.setOption({...baseOpt,grid:{top:36,right:60,bottom:16,left:16,containLabel:true},
legend:{top:6,textStyle:{color:C.text},data:['GMV(万)','毛利率(%)']},
xAxis:{type:'value',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text}},
yAxis:{type:'category',data:products.map(p=>p.name.substring(0,10)+'…').reverse(),axisLabel:{color:C.text,fontSize:11},axisLine:{lineStyle:{color:C.axis}}},
series:[
{name:'GMV(万)',type:'bar',data:products.map(p=>p.gmv).reverse(),barMaxWidth:18,
itemStyle:{color:p=>{const colors2=['#e74c3c','#e67e22','#f39c12','#f1c40f','#2ecc71','#1abc9c','#3498db','#2980b9','#9b59b6','#8e44ad'];return colors2[9-p.dataIndex];}},
label:{show:true,position:'right',color:'#c0c8e8',fontSize:11,formatter:'{c}万'}},
{name:'毛利率(%)',type:'line',xAxisIndex:0,data:products.map(p=>p.margin).reverse(),symbol:'circle',symbolSize:6,lineStyle:{color:C.green,width:2},itemStyle:{color:C.green}}
]
});
})();
// 商品分类
(function(){
const c=echarts.init(document.getElementById('chartCategory'));
c.setOption({...baseOpt,
tooltip:{trigger:'item',formatter:'{b}: {c}万 ({d}%)',backgroundColor:'#0d0f1a',borderColor:C.grid,textStyle:{color:'#e0e4f0'}},
legend:{bottom:6,textStyle:{color:C.text}},
series:[{type:'pie',radius:['28%','60%'],center:['50%','46%'],
label:{show:true,formatter:'{b}\n{d}%',color:'#c0c8e8'},
data:[
{value:142,name:'不锈钢保温杯',itemStyle:{color:'#e74c3c'}},{value:68,name:'礼盒套装',itemStyle:{color:'#f39c12'}},
{value:42,name:'儿童水杯',itemStyle:{color:'#2ecc71'}},{value:28,name:'运动水壶',itemStyle:{color:'#3498db'}},
{value:16,name:'定制企业版',itemStyle:{color:'#9b59b6'}}
]
}]
});
})();
// 活动GMV对比
(function(){
const c=echarts.init(document.getElementById('chartPromoComp'));
const acts=['双12','元旦','情人节','女王节','618(去年)','双11(去年)'];
const gmv=[68.4,38.2,52.6,74.3,186.2,428.6];
const rate=[96,109,117,124,112,138];
c.setOption({...baseOpt,
legend:{top:6,textStyle:{color:C.text},data:['活动GMV(万)','完成率(%)']},
xAxis:{type:'category',data:acts,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text,rotate:10}},
yAxis:[
{type:'value',name:'GMV(万)',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text}},
{type:'value',name:'完成率%',min:80,max:160,splitLine:{show:false},axisLabel:{color:C.text,formatter:'{value}%'}}
],
series:[
{name:'活动GMV(万)',type:'bar',data:gmv,barMaxWidth:26,itemStyle:{color:p=>p.value>100?'#e74c3c':'#f39c12'}},
{name:'完成率(%)',type:'line',yAxisIndex:1,data:rate,smooth:false,symbolSize:6,lineStyle:{color:C.green,width:2.5},itemStyle:{color:C.green},markLine:{data:[{yAxis:100,lineStyle:{color:C.orange,type:'dashed'},label:{formatter:'100%目标',color:C.orange}}]}}
]
});
})();
// 活动ROI
(function(){
const c=echarts.init(document.getElementById('chartPromoROI'));
const acts=['双12','元旦','情人节','女王节','618(去年)','双11(去年)'];
c.setOption({...baseOpt,
legend:{top:6,textStyle:{color:C.text},data:['广告ROI','毛利率(%)']},
xAxis:{type:'category',data:acts,axisLine:{lineStyle:{color:C.axis}},axisLabel:{color:C.text,rotate:10}},
yAxis:{type:'value',splitLine:{lineStyle:{color:C.grid}},axisLabel:{color:C.text}},
series:[
{name:'广告ROI',type:'bar',data:[3.86,4.15,4.46,4.53,4.02,3.74],barMaxWidth:26,itemStyle:{color:'#e74c3c'},markLine:{data:[{yAxis:3,lineStyle:{color:'#e74c3c',type:'dashed'},label:{formatter:'保本线',color:C.red}}]}},
{name:'毛利率(%)',type:'bar',data:[23.2,24.8,26.2,27.1,24.6,22.8],barMaxWidth:26,itemStyle:{color:'#2ecc71'}}
]
});
})();
// 表格排序
function sortTable(tableId, colIdx){
const table=document.getElementById(tableId);
const tbody=table.querySelector('tbody');
const rows=Array.from(tbody.querySelectorAll('tr'));
const dir=table._sortDir||1;
rows.sort((a,b)=>{
const av=a.cells[colIdx]?.textContent.replace(/[^0-9.\-]/g,'')||'0';
const bv=b.cells[colIdx]?.textContent.replace(/[^0-9.\-]/g,'')||'0';
const n=parseFloat(av)-parseFloat(bv);
return isNaN(n)?(av>bv?dir:-dir):n*dir;
});
table._sortDir=dir*-1;
rows.forEach(r=>tbody.appendChild(r));
}
// Resize
window.addEventListener('resize',()=>{
document.querySelectorAll('[id^="chart"]').forEach(el=>{
echarts.getInstanceByDom(el)?.resize();
});
});
// 页面加载完成后初始化数据
window.addEventListener('DOMContentLoaded', async () => {
console.log('🚀 看板初始化中...');
await initData();
// 初始渲染
renderFunnel();
renderTrend();
renderPie();
renderMultiAll();
});
// 刷新数据函数
async function refreshData() {
const btn = document.querySelector('button[onclick="refreshData()"]');
const originalText = btn.innerHTML;
btn.innerHTML = '⏳ 刷新中...';
btn.disabled = true;
if (DATA_MODE === 'feishu') {
await loadDataFromFeishu();
} else if (DATA_MODE === 'json') {
await loadDataFromJson();
} else {
// 本地模式:重新渲染
renderMultiAll();
renderFunnel();
renderTrend();
renderPie();
}
btn.innerHTML = originalText;
btn.disabled = false;
}
</script>
</body>
</html>