门店商品周转分析报表 (海鼎 1:1 复刻 · 左商品/右分门店 · 数据源:聚水潭)
每页
条
补货目标
天
数据更新中…
/* ---- 数据刷新编排 ---- */
var STAGE_TEXT={
init:'正在连接聚水潭…', open:'打开进销存报表页…',
export:'正在从聚水潭导出数据', download:'等待聚水潭生成文件…',
build:'正在合成报表数据…', done:'数据已更新 ✓', error:'拉取失败'
};
function showOverlay(on){document.getElementById('overlay').style.display=on?'flex':'none';}
function setStage(st,detail){
var t=STAGE_TEXT[st]||st;
if(st==='export'&&detail)t=detail;
document.getElementById('ovstage').textContent=t;
document.getElementById('ovdetail').textContent=(st==='done')?'':(detail||'');
}
function setPill(on,txt){
var p=document.getElementById('pill');
p.style.display=on?'block':'none';
if(txt)document.getElementById('pilltext').textContent=txt;
}
function refreshData(){
showOverlay(true);
fetch('/api/refresh',{method:'POST'}).then(function(r){return r.json();}).then(function(j){
if(!j.started&&j.running){/* 已有任务在跑,继续轮询 */}
poll();
}).catch(function(e){setStage('error','无法连接刷新服务');});
}
function poll(){
var timer=setInterval(function(){
fetch('/api/status').then(function(r){return r.json();}).then(function(j){
var st=j.status||{};
setStage(st.stage,st.detail);
if(st.stage==='done'){
clearInterval(timer);
setPill(false);
fetch('data.json?ts='+Date.now()).then(function(r){return r.json();}).then(function(j2){
META=j.meta;COLS=j.cols;TEXT_COLS=j.textCols||[];DATA=j.items;
RCOLS=j.rcols||[];DETAIL=j.detail||{};META.detailCount=j.detailCount;
document.getElementById('meta').textContent=META.total+' 个商品 · '+META.detailCount+' 条门店明细 · 更新于 '+META.generated;
colFilters={};markBtns();theadInit();sortBy('总销量');render();
showOverlay(false);
document.getElementById('refreshBtn').disabled=false;
});
} else if(st.stage==='error'){
clearInterval(timer);
setStage('error',st.detail);
setPill(false);
setTimeout(function(){showOverlay(false);},4000);
document.getElementById('refreshBtn').disabled=false;
} else {
setPill(true,(STAGE_TEXT[st.stage]||st.stage));
}
}).catch(function(){});
},3000);
}
document.getElementById('refreshBtn').onclick=function(){this.disabled=true;refreshData();};
document.getElementById('ovskip').onclick=function(){showOverlay(false);};
// 页面加载完成即自动拉最新数据(每次查询每次最新)
window.addEventListener('load',function(){
document.getElementById('refreshBtn').disabled=true;
refreshData();
});