refactor(ui): 决策213补记:取消会话统计列并优化清单排序与定位

This commit is contained in:
lianjianwei2024
2026-10-26 17:09:19 +08:00
parent 5de58b49ad
commit 5d9eaf774b
9 changed files with 587 additions and 562 deletions

View File

@@ -201,23 +201,27 @@ function sortRows(rows, k, dir, numSet) {
let BILL_SORT = { k: -1, dir: 1 };
const BILL_ATTR_IDX = COLS.bill.findIndex(c => c[3] === 'attr'); // 项目特征列(显示下标)
const BILL_SORT_DS = { 1: 8, 2: 1, 4: 9, 5: 2, 6: 3, 7: 4, 8: 5, 9: 6, 10: 7 };
const BILL_SORT_BY_NAME = { '序号': 8, '编码': 1, '名称': 2, '项目特征': 3, '单位': 4,
'工程量': 5, '单价': 6, '合价': 7, '单位工程名称': 9 }; // 决策 213 补记六:按列名直取数据键(隐藏列安全)
const BILL_SORT_NUM = new Set([8, 5, 6, 7]); // 序号/工程量/单价/合价 按数值比
function billHeadHTML(opts) {
const cols = billColsO(opts);
const off = (opts && opts.checkbox) ? 1 : 0;
return '<tr>' + cols.map((c, i) => {
const can = BILL_SORT_DS[i - off] != null;
const mark = (can && BILL_SORT.k === i) ? (BILL_SORT.dir > 0 ? ' ▲' : ' ▼') : '';
const dk = BILL_SORT_BY_NAME[c[0]] != null ? BILL_SORT_BY_NAME[c[0]] : null;
const can = dk != null;
const mark = (can && BILL_SORT.k === dk) ? (BILL_SORT.dir > 0 ? ' ▲' : ' ▼') : '';
const click = can
? ' onclick="if(event.target.closest(\'.rs\'))return;billSort(this,' + i + ')"'
? ' onclick="if(event.target.closest(\'.rs\'))return;billSort(this,' + i + ',' + dk + ')"'
+ ' style="cursor:pointer" title="点击在组内按本列排序"'
: '';
return `<th class="${c[2] === 'attr' ? 'l' : c[2]}"${click}>${esc(c[0])}${mark}<span class="rs"></span></th>`;
}).join('') + '</tr>';
}
function billSort(th, i) {
if (BILL_SORT.k === i) BILL_SORT.dir = -BILL_SORT.dir;
else { BILL_SORT.k = i; BILL_SORT.dir = 1; }
function billSort(th, i, dk) {
const k = (dk != null) ? dk : i; // 决策 213 补记六:dk=数据下标(按列名直取,隐藏列安全)
if (BILL_SORT.k === k) BILL_SORT.dir = -BILL_SORT.dir;
else { BILL_SORT.k = k; BILL_SORT.dir = 1; }
const tb = th.closest('table');
billSortDOM(tb);
const ck = tb && tb.dataset.ck === '1'; // 决策 153③:附件复选框表重画表头带选项
@@ -234,8 +238,7 @@ function _grpByKey(key) {
}
function billSortDOM(tb) {
if (!tb || BILL_SORT.k < 0) return;
const off = billCkOff(tb); // 决策 153③:复选框列偏移
const rk = BILL_SORT_DS[BILL_SORT.k - off];
const rk = BILL_SORT.k; // 决策 213 补记六:k 已是数据下标
const tbody = tb && tb.tBodies[0];
if (rk == null || !tbody) return;
tbody.querySelectorAll('tr.grp[data-grp],tr.grp2[data-grp]').forEach(hdr => {
@@ -654,11 +657,9 @@ function billCols() {
backend=批次侧剔除 wb 列)。既有调用 billHeadHTML()/billCols() 行为不变。 */
function billColsO(opts) {
opts = opts || {};
const base = opts.backend ? noWB(COLS.bill) : billCols().slice();
// 决策 213(2026-10-26 主人定):opts.attach=后台附件标签页组表加「附件」列——默认 56px
//(213 补记:主人看 100px 偏宽改 56,徽章只留📎)、不锁宽(共享拖列可自由拖动,列宽按
// 表头指纹记忆),仅传 attach 的表输出,工作台零影响。
if (opts.attach) base.push(['附件', 56, 'c']);
let base = opts.backend ? noWB(COLS.bill) : billCols().slice();
// 决策 213 补记六:opts.hideCols=['工程量','合价']…按列名隐藏(表头/行/列宽/组头跨列同走本函数)
if (opts.hideCols) base = base.filter(c => !opts.hideCols.includes(c[0]));
return opts.checkbox ? [['', 36, 'c', 'F']].concat(base) : base;
}
/* 复选框列导致的显示下标偏移:优先读渲染时存下的 GRP_DATA.opts,其次表上的 data-ck 标记 */
@@ -677,6 +678,7 @@ function grpTitle(tag, g) {
return t;
}
function billTR(r, grp, hide, opts) {
const skipCol = n => !!(opts && opts.hideCols && opts.hideCols.includes(n));
opts = opts || (typeof WB_OPTS !== 'undefined' ? WB_OPTS : {}) || {};
const st = hide ? ' style="display:none"' : '';
const clk = opts.rowClick ? ' onclick="' + opts.rowClick + "('bill'," + r[0] + ',this)"' : '';
@@ -690,26 +692,27 @@ function billTR(r, grp, hide, opts) {
+ '<td class="c">' + ((r[8] == null || r[8] === '') ? '—' : esc(r[8])) + '</td>'
+ '<td class="c">' + ell(r[1], '—') + '</td>'
+ '<td class="c"><span class="kind">清单</span></td>'
+ '<td>' + ell(r[9], '—') + '</td>'
+ '<td>' + ell(r[2], '—') + '</td>'
+ '<td>' + ((opts.locate && r[14])
? '<a class="lk" title="定位到原始数据中的这条清单" onclick="event.stopPropagation();return locBill(' + r[0] + ',' + r[14] + ')">' + ell(r[9], '—') + '</a>'
: ell(r[9], '—')) + '</td>'
+ '<td>' + ell(r[2], '—') + billBindTagHTML(r[0], opts.attach) + '</td>'
+ '<td class="attr">' + ell(fmtAttr(r[3])) + '</td>'
+ '<td class="c u">' + esc(r[4] || '—') + '</td>'
+ '<td class="r">' + num(r[5], 3) + '</td>'
+ (skipCol('工程量') ? '' : '<td class="r">' + num(r[5], 3) + '</td>')
+ '<td class="r">' + num(r[6]) + '</td>'
+ '<td class="r">' + num(r[7]) + '</td>'
+ (skipCol('合价') ? '' : '<td class="r">' + num(r[7]) + '</td>')
+ (opts.backend ? '' : '<td class="c">' + billAdoptCellHTML(r) + '</td>'
+ '<td class="rmk">' + billRemarkCell(r) + '</td>') // 决策 204:备注格自动换行,与原数据页同款
+ (opts.attach ? '<td class="c">' + billAttachCellHTML(r, opts.attach) + '</td>' : '')
+ '</tr>';
}
/* 清单「附件」格(决策 213,2026-10-26 主人定):opts.attach = {清单id:{name,fid}} 时输出——
已绑=淡蓝📎徽章(点击走共享 saveAs 另存该询价文件,悬停显示附件名),未绑=灰—。 */
function billAttachCellHTML(r, attach) {
const a = r && attach && attach[r[0]];
if (!a) return '<span style="color:#c3cad4">—</span>';
return '<a href="javascript:void(0)" class="tg tg-att" data-fid="' + a.fid + '" data-n="' + esc(a.name || '') + '"'
+ ' title="已绑附件:' + esc(a.name || '') + '(点击另存)"'
+ ' onclick="return saveAs(\'/api/admin/inq/file/\' + this.dataset.fid, this.dataset.n)">&#128206;</a>';
/* 清单「绑定标识」(决策 213 补记三,2026-10-26 主人定):与后台「项目工料机」页签同款——
徽标放**名称上**(qtag「已绑:附件名」截 18 字),不再用独立附件列。
opts.attach = {清单id:{name,fid}} 时输出,工作台不传恒不显示。 */
function billBindTagHTML(id, attach) {
const a = attach && attach[id];
if (!a) return '';
return '<span class="qtag bnd" style="margin-left:6px" title="已绑附件:' + esc(a.name || '') + '(左侧目录点选附件可改绑/解绑)">已绑:'
+ esc((a.name || '其他').slice(0, 18)) + '</span>';
}
/* 清单「取消采纳」列(2026-10-11 决策 39;2026-10-13 主人定:**工作台独有**,wb 标记、
后台 noWB() 整列隐藏——后台批次库只是存有价值的不变数据,交互列不占列):
@@ -728,7 +731,7 @@ function billRemarkCell(r) {
function grpTR(cls, key, title, sum, open) {
// 2026-10-13 主人定:组汇总金额对齐「合价」列——原来固定放倒数第 2 格,
// 工作台落在「取消采纳」列、后台落在「单价」列。现按列名找 合价 下标动态排版。
const cols = billCols();
const cols = (typeof GRP_DATA !== 'undefined' && GRP_DATA && GRP_DATA.opts) ? billColsO(GRP_DATA.opts) : billCols();
const si = cols.findIndex(c => c[0] === '合价');
const gt = si > 2 ? si - 2 : cols.length - 4; // 标题从第 3 格跨到合价前一列
const tail = Math.max(0, cols.length - si - 1); // 合价之后的列(取消采纳/备注)留空
@@ -775,8 +778,7 @@ function grpRowsHTML(g, key, opts) {
let rows = g.rows || [];
// 组内排序激活时,懒展开的组也按同一排序出(2026-10-10 主人定);复选框表偏移同步(决策 153③)
if (BILL_SORT.k >= 0) {
const off = (opts && opts.checkbox) ? 1 : billCkOff(null);
const rk = BILL_SORT_DS[BILL_SORT.k - off];
const rk = BILL_SORT.k; // 决策 213 补记六:k 已是数据下标
if (rk != null) rows = sortRows(rows, rk, BILL_SORT.dir, BILL_SORT_NUM);
}
return rows.map(r => billTR(r, key, false, opts)).join('');
@@ -947,7 +949,7 @@ function tgNorm(el, billId) {
const rows = (d && d.rows) || [];
if (!rows.length) {
frag.innerHTML = '<tr class="sub" data-grp="' + gp + '"><td class="tg"></td>'
+ '<td colspan="' + CB_LAST() + '">(该清单下没有定额)</td></tr>';
+ '<td colspan="' + (billColsO((typeof GRP_DATA !== 'undefined' && GRP_DATA && GRP_DATA.opts) || {}).length - 1) + '">(该清单下没有定额)</td></tr>';
} else {
// 定额 0=编码 1=名称 2=单位 3=工程量 4=单价 5=合价,其余列按清单的对应位置排空(含取消采纳/备注两空位)
// 决策 68 批次B:会话侧 r[6]=x_tdel(原定额转临删→浅灰横线)、r[7]=x_adopt;批次侧恒 0