analysis.html
14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!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 active" href="/analysis">问界生态系数分析</a>
<a class="nav-item" 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="data-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="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="store-file-input" style="display:none;" accept=".xlsx,.xls">
<span style="font-size:16px;">🏪</span>
<p id="store-file-name" style="margin:0; font-size:13px; color:#999;">可选:点击选择门店列表文件(不选则使用系统默认模板)</p>
</div>
<a href="/api/analysis/template/store" style="font-size:12px; color:#1890ff; text-decoration:none; white-space:nowrap;">📥 下载模板</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: 生态(26日)</span>
<div id="ecology-drop-zone" style="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="ecology-factory-input" style="display:none;" accept=".xlsx,.xls">
<span style="font-size:16px;">🏭</span>
<p id="ecology-file-name" style="margin:0; font-size:12px; color:#999;">点击选择生态主机厂数据</p>
</div>
<input type="date" id="ecology-start-date" style="width:130px; padding: 4px 6px; border: 1px solid #d9d9d9; border-radius: 4px; font-size:12px;" placeholder="开始">
<span style="color:#999; font-size:12px;">~</span>
<input type="date" id="ecology-end-date" style="width:130px; padding: 4px 6px; border: 1px solid #d9d9d9; border-radius: 4px; font-size:12px;" placeholder="结束">
</div>
<!-- 步骤3: 自然月主机厂数据 -->
<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;">步骤3: 自然月(1日)</span>
<div id="nature-drop-zone" style="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="nature-factory-input" style="display:none;" accept=".xlsx,.xls">
<span style="font-size:16px;">📅</span>
<p id="nature-file-name" style="margin:0; font-size:12px; color:#999;">点击选择自然月主机厂数据</p>
</div>
<input type="date" id="nature-start-date" style="width:130px; padding: 4px 6px; border: 1px solid #d9d9d9; border-radius: 4px; font-size:12px;" placeholder="开始">
<span style="color:#999; font-size:12px;">~</span>
<input type="date" id="nature-end-date" style="width:130px; padding: 4px 6px; border: 1px solid #d9d9d9; border-radius: 4px; font-size:12px;" placeholder="结束">
</div>
</div>
<!-- 步骤4: 生成报表 -->
<div style="text-align: center; margin: 20px 0;">
<button id="btn-generate-report" style="padding: 12px 48px; background: #1890ff; color: white; border: none; border-radius: 6px; font-size: 16px; cursor: pointer; transition: all 0.3s;">
🚀 开始生成分析报表
</button>
<p style="font-size:12px; color:#999; margin-top:8px;">门店按兜底截止日期分组:月底/25日→生态数据sheet,其余→自然月sheet</p>
<p style="font-size:11px; color:#faad14;">📌 使用模板: 问界门店数据模板(最新序号)</p>
</div>
<!-- 生成结果提示 -->
<div id="analysis-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;">✅ 报表生成成功</h3>
<div id="analysis-result-info" style="font-size:13px; color:#666; margin-bottom:15px;"></div>
<a id="btn-download-report" href="/api/analysis/download"
style="display:inline-block; padding: 10px 32px; background: #52c41a; color: white; border: none; border-radius: 4px; font-size: 14px; text-decoration: none; cursor: pointer;">
📥 下载分析报表
</a>
</div>
<div id="analysis-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;">❌ 报表生成失败</h3>
<p id="analysis-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 lastMonth26 = new Date(now.getFullYear(), now.getMonth()-1, 26);
const startStr = fmt(lastMonth26);
const firstOfMonth = fmt(new Date(now.getFullYear(), now.getMonth(), 1));
const ecoStart = document.getElementById('ecology-start-date');
const ecoEnd = document.getElementById('ecology-end-date');
if (ecoStart && !ecoStart.value) ecoStart.value = startStr;
if (ecoEnd && !ecoEnd.value) ecoEnd.value = todayStr;
const natStart = document.getElementById('nature-start-date');
const natEnd = document.getElementById('nature-end-date');
if (natStart && !natStart.value) natStart.value = firstOfMonth;
if (natEnd && !natEnd.value) natEnd.value = todayStr;
// 门店列表上传
const storeDropZone = document.getElementById('store-drop-zone');
const storeFileInput = document.getElementById('store-file-input');
if (storeDropZone) {
storeDropZone.addEventListener('click', () => storeFileInput.click());
storeFileInput.addEventListener('change', () => {
if (storeFileInput.files.length > 0) {
document.getElementById('store-file-name').textContent = '✅ 已选择: ' + storeFileInput.files[0].name;
document.getElementById('store-file-name').style.color = '#52c41a';
}
});
}
// 生态主机厂数据上传
const ecologyDropZone = document.getElementById('ecology-drop-zone');
const ecologyFactoryInput = document.getElementById('ecology-factory-input');
if (ecologyDropZone && ecologyFactoryInput) {
ecologyDropZone.addEventListener('click', () => ecologyFactoryInput.click());
ecologyFactoryInput.addEventListener('change', () => {
if (ecologyFactoryInput.files.length > 0) {
document.getElementById('ecology-file-name').textContent = '✅ 已选择: ' + ecologyFactoryInput.files[0].name;
document.getElementById('ecology-file-name').style.color = '#52c41a';
}
});
}
// 自然月主机厂数据上传
const natureDropZone = document.getElementById('nature-drop-zone');
const natureFactoryInput = document.getElementById('nature-factory-input');
if (natureDropZone && natureFactoryInput) {
natureDropZone.addEventListener('click', () => natureFactoryInput.click());
natureFactoryInput.addEventListener('change', () => {
if (natureFactoryInput.files.length > 0) {
document.getElementById('nature-file-name').textContent = '✅ 已选择: ' + natureFactoryInput.files[0].name;
document.getElementById('nature-file-name').style.color = '#52c41a';
}
});
}
// 生成报表按钮
const btnGenerateReport = document.getElementById('btn-generate-report');
if (btnGenerateReport) {
btnGenerateReport.addEventListener('click', async () => {
document.getElementById('analysis-result').style.display = 'none';
document.getElementById('analysis-error').style.display = 'none';
const hasStore = storeFileInput && storeFileInput.files.length > 0;
const hasEcology = ecologyFactoryInput && ecologyFactoryInput.files.length > 0;
const hasNature = natureFactoryInput && natureFactoryInput.files.length > 0;
if (!hasEcology && !hasNature) {
alert('请至少上传一个主机厂数据文件(步骤2或步骤3)');
return;
}
btnGenerateReport.disabled = true;
btnGenerateReport.textContent = '⏳ 正在生成报表...';
try {
const uploadForm = new FormData();
if (hasStore) uploadForm.append('store_file', storeFileInput.files[0]);
if (hasEcology) uploadForm.append('ecology_factory_file', ecologyFactoryInput.files[0]);
if (hasNature) uploadForm.append('nature_factory_file', natureFactoryInput.files[0]);
const uploadRes = await fetch('/api/analysis/upload', { method: 'POST', body: uploadForm });
const uploadData = await uploadRes.json();
if (uploadData.status !== 'success') {
throw new Error(uploadData.detail || '文件上传失败');
}
btnGenerateReport.textContent = '⏳ 正在分析计算...';
const genForm = new FormData();
const ecoStart = document.getElementById('ecology-start-date').value;
const ecoEnd = document.getElementById('ecology-end-date').value;
const natStart = document.getElementById('nature-start-date').value;
const natEnd = document.getElementById('nature-end-date').value;
if (ecoStart) genForm.append('ecology_start_date', ecoStart);
if (ecoEnd) genForm.append('ecology_end_date', ecoEnd);
if (natStart) genForm.append('nature_start_date', natStart);
if (natEnd) genForm.append('nature_end_date', natEnd);
const genRes = await fetch('/api/analysis/generate', { method: 'POST', body: genForm });
const genData = await genRes.json();
if (genData.status === 'success') {
document.getElementById('analysis-result').style.display = 'block';
document.getElementById('analysis-result-info').innerHTML =
'生态数据门店: <strong>' + genData.ecology_store_count + '</strong> 家 | ' +
'自然月门店: <strong>' + genData.nature_store_count + '</strong> 家';
document.getElementById('btn-download-report').href = genData.download_url;
} else {
throw new Error(genData.detail || '报表生成失败');
}
} catch (err) {
console.error('分析失败:', err);
document.getElementById('analysis-error').style.display = 'block';
document.getElementById('analysis-error-msg').textContent = err.message || '未知错误';
} finally {
btnGenerateReport.disabled = false;
btnGenerateReport.textContent = '🚀 开始生成分析报表';
}
});
}
});
</script>
</body>
</html>