fix(costreview): 历史清单定额展开支持重导后按批次+哈希重定位,并后台预升级过期批次

This commit is contained in:
lianjianwei2024
2026-11-15 10:26:48 +08:00
parent 0e5785f1dc
commit 4b54ee1cfa
5 changed files with 95 additions and 13 deletions

View File

@@ -2703,7 +2703,7 @@ function renderHist(){
// ± 把手:只有历史「清单」行(带 bill_id)可展开定额 —— 同「类似清单」的交互;
// 工料机/信息价/市场价行没有下挂定额,不渲染把手列。
const tg=(!isLme && x.bill_id)
? `<span class="tog" title="展开/收起该历史清单下的定额" onclick="event.stopPropagation();tgHist(this,${x.bill_id})">+</span>`
? `<span class="tog" title="展开/收起该历史清单下的定额" onclick="event.stopPropagation();tgHist(this,${x.bill_id},'${x.bhash||''}',${x.batch_id||0})">+</span>` // 决策 341:带哈希+批次,重导换 id 后展开仍可重定位
: (!isLme && x.norms)
? `<span class="tog" title="展开/收起该清单下的定额" onclick="event.stopPropagation();tgHistSelf(this,${x.self_bill_id})">+</span>`
: '';
@@ -2765,8 +2765,11 @@ let HSEL=-1;
let HINDEP=false; // true=独立检索模式(B 方案):行来自 /api/hist/search,无匹配档位/相似度,精确度不适用
const HNORM={}; // 历史库定额缓存:bill_id → Promise<rows>(6 列:编码/名称/单位/工程量/单价/合价)
const HBATCH={}; // 决策 289 补三:bill_id → batch_id(入库耗浮层的子级组成按批次取数)
function histNorms(bid){
if(!HNORM[bid]) HNORM[bid]=fetch('/api/admin/bill/'+bid+'/norms').then(r=>r.json()).then(d=>{ HBATCH[bid]=d.batch_id||0; return (d&&d.rows)||[]; });
function histNorms(bid, bhash, batch){
/* 决策 341:279 按需重导换 id 后,行里攥的旧 bid 展开会空——随 ± 把手带 bhash+batch,
服务端旧 id 查不到时按 批次+内容哈希 重定位取新 id 的定额(前端缓存键沿用旧 bid 无妨)。 */
const q=(bhash?('?bhash='+encodeURIComponent(bhash)+'&batch='+(batch||0)):'');
if(!HNORM[bid]) HNORM[bid]=fetch('/api/admin/bill/'+bid+'/norms'+q).then(r=>r.json()).then(d=>{ HBATCH[bid]=d.batch_id||0; return (d&&d.rows)||[]; });
return HNORM[bid];
}
function pickHistRow(i,tr){
@@ -2787,7 +2790,7 @@ function hattrShow(x){
: '<div class="empty">(该清单下没有定额)</div>'; return; } // 决策 158:会话源行内联定额
if(!x.bill_id){ n.innerHTML='<div class="empty">(此行无定额)</div>'; return; }
n.innerHTML='<div class="empty">正在读取…</div>';
histNorms(x.bill_id).then(rows=>{
histNorms(x.bill_id, x.bhash, x.batch_id).then(rows=>{ // 决策 341:带哈希+批次可重定位
n.innerHTML = rows.length
? rows.map(r=>`<div class="hnorm-it" title="${esc((r[0]||'')+' '+(r[1]||''))}"><span class="nc">${esc(r[0]||'—')}</span>${esc(r[1]||'—')}</div>`).join('')
: '<div class="empty">(该清单下没有定额)</div>';
@@ -2815,7 +2818,7 @@ function tgHistSelf(el,sbid){
while(frag.firstChild) tr.parentNode.insertBefore(frag.firstChild,n2);
}
/* ± 展开一条历史清单的定额(子行列序跟 C_H 对齐:编码并入名称列,同 tgNorm 的排法) */
async function tgHist(el,bid){
async function tgHist(el,bid,bhash,batch){
const tr=el.closest('tr');
let nx=tr.nextElementSibling;
while(nx&&nx.classList.contains('hsub')){ const n2=nx.nextElementSibling; nx.remove(); nx=n2; }
@@ -2824,7 +2827,7 @@ async function tgHist(el,bid){
const _gen=(parseInt(el.dataset.gen||'0',10)||0)+1; // 决策 289 补四:代次守窗——+−+快速切换时
el.dataset.gen=String(_gen); // 第一次的迟到响应会在重展开后插行→子行重样(工作区老毛病)
try{
const rows=await histNorms(bid);
const rows=await histNorms(bid,bhash,batch); // 决策 341:带哈希+批次,重导换 id 后可重定位
if(el.dataset.gen!==String(_gen)||el.dataset.open!=='1') return; // 换代次/被收起:丢弃迟到响应
const frag=document.createElement('tbody');
frag.innerHTML = rows.length
@@ -2867,7 +2870,7 @@ function showHistTip(x, td, lmeOnly){
return;
}
if(!x.bill_id){ htip.querySelector('.htip-norms').innerHTML='<div class="tip" style="padding:4px 10px">(此行无定额)</div>'; return; }
histNorms(x.bill_id).then(ns=>{
histNorms(x.bill_id, x.bhash, x.batch_id).then(ns=>{ // 决策 341:带哈希+批次可重定位
const box=htip.querySelector('.htip-norms'); if(!box) return;
box.innerHTML = ns.length
? ns.map(n=>'<div class="hnorm-it"><span class="nc">'+esc(n[0]||'—')+'</span>'+esc(n[1]||'—')+'</div>').join('')