feat(lme): 决策185-190落地——动态工料机现算、并集视野重组、同码异价拆行、子级改价收严

This commit is contained in:
lianjianwei2024
2026-10-24 23:42:44 +08:00
parent c0b01b15a8
commit ac28658889
13 changed files with 1275 additions and 135 deletions

View File

@@ -959,28 +959,27 @@ function mTog(tr){
if (box) Array.from(box.querySelectorAll('tr.mrow')).forEach(r => { r.style.display = open ? 'none' : ''; });
}
function renderMergeTree(){
// 决策 171(2026-10-22 主人定):视野=单位工程×n+项目级——组内行含 项目级行(lvl=proj)
// 与 单位级按码聚合行(lvl=uw,标注 N 个单位工程);**编码只读**(主人定「合并工料机里面的
// 编码就不可编辑」,原编码输入框撤除);价格仍可编辑(仅项目级行)。
// 列=勾选/序号/编码/来源/名称/规格型号/单位/数量/除税编制价/税率/含税编制价;固定顶部表头;
// 不过滤带子数据的工料机(决策78 废止口径不变)。
// 决策 186 v3(2026-10-23 主人定「合并逻辑1」):视野=**各单位工程品类并集**——项目级行
// 不再显示(并集由单位级聚合呈现,不依赖项目级层);「来源」列去掉(全部来自单位工程汇总,
// 标注 N 个单位工程);**编码只读**;全部字段只读(决策 184:改价在外面·行级改价/原数据)。
// 列=勾选/序号/编码/名称/规格型号/单位/数量/除税编制价/税率/含税编制价;固定顶部表头。
// 决策 173(2026-10-22 主人定):弹框加宽(1120px)+ 列宽可拖(公共 .rs 拖列逻辑)——
// 名称 200 / 规格 150,其余列宽不变;全 px 列 → data-sumw(表宽=列宽和),拖完 colwSave 记忆。
let h = '<table class="mtbl" data-sumw="1" style="width:1062px"><colgroup>'
+ '<col style="width:34px"><col style="width:36px"><col style="width:44px"><col style="width:104px"><col style="width:92px"><col style="width:200px"><col style="width:150px">'
+ '<col style="width:48px"><col style="width:86px"><col style="width:104px"><col style="width:60px"><col style="width:104px">'
let h = '<table class="mtbl" data-sumw="1" style="width:1018px"><colgroup>'
+ '<col style="width:34px"><col style="width:36px"><col style="width:44px"><col style="width:150px"><col style="width:200px"><col style="width:150px">'
+ '<col style="width:48px"><col style="width:96px"><col style="width:100px"><col style="width:60px"><col style="width:100px">'
+ '</colgroup><thead><tr><th></th><th title="单选:合并后按此行的编码与三价替换全组">✓<span class="rs"></span></th><th>序号<span class="rs"></span></th><th>编码<span class="rs"></span></th>'
+ '<th>来源<span class="rs"></span></th><th>名称<span class="rs"></span></th><th>规格型号<span class="rs"></span></th><th>单位<span class="rs"></span></th><th>数量<span class="rs"></span></th><th>除税编制价<span class="rs"></span></th><th>税率<span class="rs"></span></th><th>含税编制价<span class="rs"></span></th></tr></thead>';
+ '<th>名称<span class="rs"></span></th><th>规格型号<span class="rs"></span></th><th>单位<span class="rs"></span></th><th>数量<span class="rs"></span></th><th>除税编制价<span class="rs"></span></th><th>税率<span class="rs"></span></th><th>含税编制价<span class="rs"></span></th></tr></thead>';
let no = 0;
MDATA.groups.forEach((g, gi) => {
const qty = g.rows.reduce((s, r) => s + (Number(r.qty) || 0), 0);
h += '<tbody class="mgrp" data-gi="' + gi + '">'
+ '<tr class="mhead2" onclick="mTog(this)"><td><span class="tog" data-open="1">−</span></td>'
+ '<td></td><td></td>'
+ '<td class="gtitle" colspan="6" title="名称|规格|单位">' + esc(g.name || '—') + ' | ' + esc(g.spec || '—') + ' | ' + esc(g.unit || '—')
+ '<td class="gtitle" colspan="7" title="名称|规格|单位">' + esc(g.name || '—') + ' | ' + esc(g.spec || '—') + ' | ' + esc(g.unit || '—')
+ ' <span style="color:#8a97a8;font-weight:400">' + g.rows.length + ' 条</span></td>'
+ '<td class="r"><b>' + num(qty, 3) + '</b></td>'
+ '<td></td><td></td><td></td></tr>';
+ '<td></td><td></td></tr>';
g.rows.forEach(r => {
no++;
const isUw = r.lvl === 'uw';
@@ -996,7 +995,6 @@ function renderMergeTree(){
+ (r.def ? ' checked' : '') + ' title="单选:合并后全组按此行归并(数值=行现值;改价在外面·行级改价/原数据)"></td>'
+ '<td class="c">' + no + '</td>'
+ '<td class="c">' + esc(r.code || '—') + '</td>'
+ '<td class="c" style="color:#6b7a8d">' + (isUw ? (r.units + '个单位工程') : '项目级') + '</td>'
+ '<td class="l" title="' + esc(g.name || '') + '">' + esc(g.name || '—') + (r.sub
? ' <span class="subtag" title="带子级组成(台班/配合比):合并后各单位工程的子级以保留行为准,原软件按子级重算母价">子级</span>' : '') + '</td>'
+ '<td class="l" title="' + esc(g.spec || '') + '">' + esc(g.spec || '—') + '</td>'
@@ -1152,7 +1150,7 @@ function pageSearchGo(key, val){
格位对应 rawTreeHTML:0把手 1序号 2编码 3类型 4名称 5特征 6单位 7工程量 8单价 9合价 10取消采纳 11备注 */
document.addEventListener('click', function(e){
if(!SID) return;
const td = e.target.closest && e.target.closest('#rawbody td, #tb0 td');
const td = e.target.closest && e.target.closest('#rawbody td, #tb0 td, .haopop td');
if(!td || td.querySelector('input')) return;
const tr = td.closest('tr'); if(!tr) return;
const idx = Array.prototype.indexOf.call(tr.children, td);
@@ -1163,12 +1161,30 @@ document.addEventListener('click', function(e){
} else if(tr.classList.contains('sub') && tr.dataset.nid){
const F = {4:'Name',7:'Quantity'};
if(F[idx]){ api='norm'; id=tr.dataset.nid; field=F[idx]; }
} else if(tr.classList.contains('haorow') && tr.dataset.code && SID){
// 决策 188 补:浮层主行(定额下的工料机)——单条行 含量(消耗量)/除税/税率/含税 可编辑;
// 带子级行单价锁死(只能改含量/去改子数据)
const _sub = tr.dataset.sub === '1';
if(idx === 5){ haoEdit(td, tr, 'content'); }
else if(!_sub && (idx === 6 || idx === 7 || idx === 8)){ haoEdit(td, tr, ({6:'ntp',7:'taxrate',8:'taxp'})[idx]); }
else if(_sub){ $('msg').textContent = '带子级的单价不可编辑:请修改它的子数据(单价=Σ子级联动)'; }
} else if(tr.classList.contains('resk') && tr.dataset.ccode && SID){
// 决策 188(2026-10-24 主人定):子级组成行——含量/除税价/含税价 单击可编辑(母行Σ联动)
const F = {5:'content', 6:'ntp', 7:'taxrate', 8:'taxp'};
if(F[idx]){ reskEdit(td, tr, F[idx]); }
} else if((tr.classList.contains('lmerow') || tr.closest('#tb0')) && (tr.dataset.lmeid || tr.dataset.id)){
// 2026-10-16 主人口径:项目级工料机汇总 除税编制价|税率|含税编制价 三格可改(单位级行无 data-lmeid=只读)。
// 决策 147 补落实(2026-10-21):「项目工料机」页签同码同形——单击改价同卡;两处布局同构,
// 视图下标=数据下标(6=除税编制价 7=税率 8=含税编制价),卡侧走 RV_LME_DS(恒等映射)兜底。
const dk = tr.closest('#tb0') ? idx : (RV_LME_DS ? RV_LME_DS[idx] : null);
if(dk===6 || dk===7 || dk===8){ api='lme'; field=({6:'ntp',7:'taxrate',8:'taxp'})[dk]; }
if(dk===6 || dk===7 || dk===8){
// 决策 188 收严(2026-10-24 主人定):带子级的工料机单价不可编辑,只能通过子数据修改
if((typeof LME_SUB!=='undefined'&&LME_SUB.has(tr.dataset.code))||
(typeof RV_LME_SUBS!=='undefined'&&RV_LME_SUBS&&RV_LME_SUBS.has(tr.dataset.code))){
$('msg').textContent='带子级的单价不可编辑:请修改它的子数据(单价=Σ子级联动)'; return;
}
api='lme'; field=({6:'ntp',7:'taxrate',8:'taxp'})[dk];
}
// 2026-10-22 主人定:名称/规格/单位行内编辑(数据下标 2/3/4;编码=1 永不可改;
// 两处同码同形同此入口,单位级行无 data-lmeid 进不来=只读)
else if(dk===2 || dk===3 || dk===4){ api='lmefield'; field=({2:'name',3:'spec',4:'unit'})[dk]; }
@@ -1207,6 +1223,7 @@ function editCell(td, api, id, field, cur){
const fin = async save => {
if(done) return; done = true;
const v = inp.value.trim();
td.classList.remove('editing'); td.style.height = '';
if(!save || v === cur){ td.textContent = cur; return; }
const body = {session_id:SID, fields:{}};
body.fields[field] = v;
@@ -1255,6 +1272,7 @@ function grpBillQtyEdit(td, tr, cur0){
const fin = async save => {
if(done) return; done = true;
const v = inp.value.trim();
td.classList.remove('editing'); td.style.height = '';
if(!save || v === cur0.replace(/,/g, '')){ td.textContent = cur0; return; }
if(!/^-?\d+(\.\d+)?$/.test(v)){ $('msg').textContent = '清单工程量只能输入数字'; td.textContent = cur0; return; }
const r = await J('/api/session/bill/op',{method:'POST',headers:{'Content-Type':'application/json'},
@@ -1287,6 +1305,7 @@ function grpNormQtyEdit(td, tr, cur0){
const fin = async save => {
if(done) return; done = true;
const v = inp.value.trim();
td.classList.remove('editing'); td.style.height = '';
if(!save || v === pre){ td.textContent = cur0; return; }
const r = await J('/api/session/norm/op',{method:'POST',headers:{'Content-Type':'application/json'},
body:JSON.stringify({session_id:SID, norm_id:nid, fields:{Quantity:v}})});
@@ -1328,6 +1347,154 @@ document.addEventListener('click', function(e){
交互沿用 editCell 口径(失焦/Enter 提交、Esc 取消、无防抖);提交成功后本地行原位
同步三个格(序号/排序不动),RV_LME_ROWS 同步改,本会话其余视图缓存撤掉(单位级
汇总按编码同步过,不能读旧值),当前视图 DOM 写回缓存。 */
/* 决策 188 补:浮层主行编辑——content=定额消耗量(/norm/content);三价=按码(/lme/price)。
保存后浮层整层重开(值全部刷新,含 Σ 母行价)。 */
async function haoEdit(td, tr, field){
if(td.querySelector('input')) return;
const cur = td.textContent.trim();
const inp = document.createElement('input');
inp.className = 'cellin'; inp.value = (cur==='—'||cur==='' ? '' : cur); inp.spellcheck = false;
inp.addEventListener('input', function(){
const f = this.value.replace(/[^\d.]/g, ''), pp = f.split('.');
this.value = pp.length > 2 ? pp[0] + '.' + pp.slice(1).join('') : f;
});
cellEditFill(td);
td.textContent = ''; td.appendChild(inp); inp.focus(); inp.select();
let done = false;
const fin = async save => {
if(done) return; done = true;
td.classList.remove('editing'); td.style.height = '';
const v = inp.value.trim();
if(!save || v === cur || v === ''){ td.textContent = cur; return; }
const nv = Number(v.replace(/,/g, ''));
if(!isFinite(nv) || nv < 0){ $('msg').textContent = '请输入非负数字'; td.textContent = cur; return; }
const pop = tr.closest('.haopop');
const nid = pop ? Number(pop.dataset.nid) : 0;
let url, body;
if(field === 'content'){ url = '/api/session/norm/content'; body = { session_id: SID, norm_id: nid, res_code: tr.dataset.code, qty: nv }; }
else { url = '/api/session/lme/price'; body = { session_id: SID, code: tr.dataset.code }; body[field] = nv; }
const r = await J(url, { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(body) });
if(!r || !r.ok){ $('msg').textContent = (r && r.msg) || '保存失败'; td.textContent = cur; return; }
$('msg').textContent = '已保存(各级汇总已实时联动)';
// 浮层整层重开=全部行刷新(Σ 母行价/兄弟行联动可见)——延后一拍;
// 先调 haoPopClose() 清模块级引用(let 不挂 window)——否则 haoPop 对同 nid 走「收起」分支(实测根因);
// 重开后自动钉住,免回车引发的滚动/blur 误关(钉住浮层仍可点空白关闭)。
try{
const _nid = Number(pop.dataset.nid), _btn = HAO_BTN;
if(typeof haoPopClose === 'function') haoPopClose();
setTimeout(() => {
try{
const _b2 = document.querySelector('#tb1 .haobtn') || _btn;
if(_b2) haoPop(_b2, _nid);
if(typeof HAO_POP !== 'undefined' && HAO_POP){ HAO_POP.dataset.pinned = '1'; }
}catch(e){}
}, 250);
}catch(e){}
};
inp.addEventListener('keydown', ev => {
if(ev.key === 'Enter'){ ev.preventDefault(); fin(true); }
else if(ev.key === 'Escape'){ fin(false); }
});
inp.addEventListener('blur', () => fin(true));
}
/* 决策 188:子级组成行内编辑(含量→/lme/content;除税/含税→/lme/price 按码定位)。
保存后重拉该母行子级列表原位重画,并把母行除税/含税两格更新为 Σ(含量×价)——联动立即可见。 */
async function reskEdit(td, tr, field){
if(td.querySelector('input')) return;
const cur = td.textContent.trim();
const inp = document.createElement('input');
inp.className = 'cellin'; inp.value = (cur==='—'?'':cur); inp.spellcheck = false;
inp.addEventListener('input', function(){
const f = this.value.replace(/[^\d.]/g, ''), pp = f.split('.');
this.value = pp.length > 2 ? pp[0] + '.' + pp.slice(1).join('') : f;
});
cellEditFill(td);
td.textContent = ''; td.appendChild(inp); inp.focus(); inp.select();
let done = false;
const fin = async save => {
if(done) return; done = true;
td.classList.remove('editing'); td.style.height = '';
const v = inp.value.trim();
if(!save || v === cur || v === ''){ td.textContent = cur; return; }
const nv = Number(v.replace(/,/g, ''));
if(!isFinite(nv) || nv < 0){ $('msg').textContent = '请输入非负数字'; td.textContent = cur; return; }
const body = { session_id: SID, p_code: tr.dataset.pcode, res_code: tr.dataset.ccode };
if(field === 'content'){ body.qty = nv; }
else { body.code = tr.dataset.ccode; body[field] = nv; } // 价格接口按 code 定位(2026-10-24 修:此前漏带 code→行不存在)
const r = await J('/api/session/lme/' + (field === 'content' ? 'content' : 'price'),
{ method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(body) });
if(!r || !r.ok){ $('msg').textContent = (r && r.msg) || '保存失败'; td.textContent = cur; return; }
td.textContent = String(nv);
$('msg').textContent = '已保存(母行单价已按 Σ 子级联动)';
await reskRefresh(tr);
};
inp.addEventListener('keydown', ev => {
if(ev.key === 'Enter'){ ev.preventDefault(); fin(true); }
else if(ev.key === 'Escape'){ fin(false); }
});
inp.addEventListener('blur', () => fin(true));
}
/* 重拉某母行的子级并原位重画 + 母行两价格更新为 Σ */
async function reskRefresh(tr){
const motherTr = tr.previousElementSibling && tr.previousElementSibling.classList.contains('lmerow')
? tr.previousElementSibling : null;
// 找母行:向上跳过连续 resk 行——浮层母行无 lmerow 类(2026-10-24 实测踩坑:按类找会落到 null)
let m = tr.previousElementSibling;
while(m && m.classList.contains('resk')) m = m.previousElementSibling;
if(!m || m.tagName !== 'TR') m = null;
const pcode = tr.dataset.pcode;
const base = (typeof RVO !== 'undefined' && RVO && (typeof RVO.lmeApi === 'function' ? RVO.lmeApi() : RVO.lmeApi)) || ('/api/session/lme/res?session_id=' + SID);
try{
const d = await J(base + '&code=' + encodeURIComponent(pcode));
const rows = (d && d.rows) || [];
let snt = 0, stx = 0;
const html = rows.map(x => {
const q = Number(x[5]) || 0, np = Number(x[6]) || 0, tp = Number(x[7]) || 0;
snt += q * np; stx += q * tp;
return '<tr class="resk" data-pcode="' + esc(pcode) + '" data-ccode="' + esc(x[0]) + '"'
+ ' title="单击 含量/除税价/税率/含税价 可编辑(除税×(1+税率)=含税 恒成立;母行单价=Σ子级自动联动)">'
+ '<td class="c"></td><td class="c">' + ell(x[0], '—') + '</td>'
+ '<td class="l">' + ell(x[1], '—') + '</td>'
+ '<td class="l">' + ell(x[2], '—') + '</td><td class="c u">' + esc(x[3] || '—') + '</td>'
+ '<td class="r">' + r3(x[5]) + '</td><td class="r">' + rm(x[6]) + '</td>'
+ '<td class="r">' + (x[8] == null ? '—' : num(x[8], 2)) + '</td>'
+ '<td class="r">' + rm(x[7]) + '</td></tr>';
}).join('') || '<tr class="resk"><td colspan="9" style="text-align:left">(没有下一级组成)</td></tr>';
// 原位替换本母行下的旧子级行(含被编辑的 tr 自己——否则旧行残留重复,2026-10-24 实测)
let nx = tr, cnt = 0;
const tmp = document.createElement('tbody'); tmp.innerHTML = html;
while(nx && nx.classList.contains('resk')){ const n2 = nx.nextElementSibling; nx.remove(); nx = n2; }
if(m && m.parentNode){
let ref = m.nextElementSibling;
while(tmp.firstChild) m.parentNode.insertBefore(tmp.firstChild, ref);
}
// 母行两价格 = Σ(视图格位 6=除税 8=含税;税率格保持 —)
if(m){
const inPop = !!tr.closest('.haopop'); // 浮层布局=直下标;原数据卡走 RV_LME_DS 映射
const tds = Array.prototype.slice.call(m.children);
const find = want => { const vi = inPop ? want : tds.findIndex((_, i) => (typeof RV_LME_DS !== 'undefined' && RV_LME_DS ? RV_LME_DS[i] : i) === want); return vi >= 0 ? tds[vi] : null; };
const cN = find(6), cT = find(8);
if(cN) cN.textContent = rm(Math.round((snt + Number.EPSILON) * 100) / 100);
if(cT) cT.textContent = rm(Math.round((stx + Number.EPSILON) * 100) / 100);
}
if(typeof RV_LME_ROWS !== 'undefined' && RV_LME_ROWS && m){
// 同步缓存里的母行值(防排序回显旧值)
const key = m.dataset.lmeid != null ? Number(m.dataset.lmeid) : null;
if(key != null){ const ri = (RV_LME_IDS||[]).indexOf(key);
if(ri >= 0 && RV_LME_ROWS[ri]){ RV_LME_ROWS[ri][6] = Math.round((snt + Number.EPSILON) * 100) / 100;
RV_LME_ROWS[ri][8] = Math.round((stx + Number.EPSILON) * 100) / 100; } }
if(typeof rvCachePut === 'function') rvCachePut();
}
// 同步「项目工料机」页签内存(LME_ROWS)里的同码行
if(typeof LME_ROWS !== 'undefined' && LME_ROWS){
const li = LME_ROWS.findIndex(x => x[1] === pcode);
if(li >= 0){ LME_ROWS[li][6] = Math.round((snt + Number.EPSILON) * 100) / 100;
LME_ROWS[li][8] = Math.round((stx + Number.EPSILON) * 100) / 100; }
}
}catch(e){ /* 重拉失败不挡保存 */ }
}
const LME_FIELDS = { ntp: 6, taxrate: 7, taxp: 8 }; // 字段 → 数据 r[] 下标
function lmePriceCells(tr){
const out = {};
@@ -1360,6 +1527,7 @@ function lmeEditCell(td, tr, field, cur){
const fin = async save => {
if(done) return; done = true;
const v = inp.value.trim();
td.classList.remove('editing'); td.style.height = '';
if(!save || v === cur){ td.textContent = cur; return; }
const nv = lmeParseNum(v);
if(nv !== null && Number.isNaN(nv)){ $('msg').textContent = '请输入数字'; td.textContent = cur; return; }
@@ -1421,6 +1589,7 @@ function lmeEditField(td, tr, field){
const fin = async save => {
if(done) return; done = true;
const v = inp.value.trim();
td.classList.remove('editing'); td.style.height = '';
if(!save || v === cur){ td.textContent = cur; return; }
if(field === 'name' && !v){ $('msg').textContent = '名称不能为空'; td.textContent = cur; return; }
const body = {session_id: SID, id: Number(tr.dataset.lmeid || tr.dataset.id)};
@@ -1626,6 +1795,7 @@ async function inqBatchDl(){
async function loadLme(){
const d=await J(`/api/session/rows?session_id=${SID}&type=lme`);
LME_ROWS=d.rows||[]; LME_SORT={k:-1,dir:1}; // 新数据:排序复位
LME_SUB=new Set(d.sub||[]); // 决策 188 收严:带子级集——三价格前端先拦(服务端同款拒)
colg('cg0',C_LME_WB); $('th0').innerHTML=lmeHeadHTML();
lmeRenderRows();
}