From d627a72aea615949d964079e924eefc36241fce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=82=E7=B3=96?= <2178503051@qq.com> Date: Thu, 25 Jun 2026 16:08:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor(cost=20views):=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=95=B0=E5=80=BC=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E7=B2=BE=E5=BA=A6=E4=B8=BA=E4=B8=A4=E4=BD=8D=E5=B0=8F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改了三个成本相关页面的数值格式化逻辑: 1. energy.vue和assised.vue的formatNum方法,将保留小数位数从4位改为2位 2. comprehensive.vue的多位置数值处理逻辑,统一将计算结果格式化为两位小数 --- klp-ui/src/views/cost/comprehensive.vue | 8 ++++---- klp-ui/src/views/cost/views/assised.vue | 2 +- klp-ui/src/views/cost/views/enegry.vue | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/klp-ui/src/views/cost/comprehensive.vue b/klp-ui/src/views/cost/comprehensive.vue index 738b9696b..1719a2926 100644 --- a/klp-ui/src/views/cost/comprehensive.vue +++ b/klp-ui/src/views/cost/comprehensive.vue @@ -735,7 +735,7 @@ export default { if (!d.detailDate) return if (!map[d.detailDate]) map[d.detailDate] = { detailDate: d.detailDate } const sfx = d.shift && d.shift !== '0' ? '_' + d.shift : '' - map[d.detailDate]['q' + d.itemId + sfx] = d.quantity + map[d.detailDate]['q' + d.itemId + sfx] = d.quantity != null && d.quantity !== '' ? Number(d.quantity).toFixed(2) : d.quantity }) this.gridRows = Object.values(map).sort((a,b) => a.detailDate.localeCompare(b.detailDate)) }, @@ -780,7 +780,7 @@ export default { }) }) }, - evalF(f) { const s = f.replace(/[^0-9+\-*/.()\s]/g,''); if(!s) return null; try { const r = new Function('return ('+s+')')(); return isFinite(r)?Math.round(r*10000)/10000:null } catch(e){ return null } }, + evalF(f) { const s = f.replace(/[^0-9+\-*/.()\s]/g,''); if(!s) return null; try { const r = new Function('return ('+s+')')(); return isFinite(r)?(Math.round(r*100)/100).toFixed(2):null } catch(e){ return null } }, sortGrid() { this.gridRows.sort((a,b)=>{if(!a.detailDate)return 1;if(!b.detailDate)return -1;return a.detailDate.localeCompare(b.detailDate)}) }, async saveGrid() { const rid = this.activeReport.reportId; if (!rid) return; this.saving = true @@ -860,7 +860,7 @@ export default { try { const val = await handler(col.queryCondition, row, col, this.activeReport, shift) if (val != null) { - const round3 = n => Math.round(n * 1000) / 1000 + const round3 = n => (Math.round(n * 100) / 100).toFixed(2) if (Array.isArray(val)) { this.$set(row, 'q' + col.itemId + '_1', round3(val[0])) this.$set(row, 'q' + col.itemId + '_2', round3(val[1])) @@ -946,7 +946,7 @@ export default { if (!col.queryCondition) return const handler = queryHandlers[col.category] || queryHandlers['default'] if (!handler) { this.$modal.msgWarning(`类别 "${col.category}" 未注册查询处理器`); return } - const round3 = n => Math.round(n * 1000) / 1000 + const round3 = n => (Math.round(n * 100) / 100).toFixed(2) const tasks = [] for (const row of this.gridRows) { if (!row.detailDate) continue diff --git a/klp-ui/src/views/cost/views/assised.vue b/klp-ui/src/views/cost/views/assised.vue index 9d13b37e0..ca0804452 100644 --- a/klp-ui/src/views/cost/views/assised.vue +++ b/klp-ui/src/views/cost/views/assised.vue @@ -130,7 +130,7 @@ export default { else return row.lineType || '-' } }, - formatNum(val) { if (val === null || val === undefined || val === '') return ''; const n = Number(val); if (isNaN(n)) return val; return parseFloat(n.toFixed(4)) }, + formatNum(val) { if (val === null || val === undefined || val === '') return ''; const n = Number(val); if (isNaN(n)) return val; return parseFloat(n.toFixed(2)) }, async loadItems() { if (!this.allItems.length) { const r = await listItem({ pageNum:1, pageSize:999 }); this.allItems = r.rows || [] } }, async enter(row) { const r = await getProdReport(row.reportId); if (r.data) this.activeReport = r.data; else this.activeReport = row; this.loadGrid() } } diff --git a/klp-ui/src/views/cost/views/enegry.vue b/klp-ui/src/views/cost/views/enegry.vue index 134237155..cce34ad09 100644 --- a/klp-ui/src/views/cost/views/enegry.vue +++ b/klp-ui/src/views/cost/views/enegry.vue @@ -130,7 +130,7 @@ export default { else return row.lineType || '-' } }, - formatNum(val) { if (val === null || val === undefined || val === '') return ''; const n = Number(val); if (isNaN(n)) return val; return parseFloat(n.toFixed(4)) }, + formatNum(val) { if (val === null || val === undefined || val === '') return ''; const n = Number(val); if (isNaN(n)) return val; return parseFloat(n.toFixed(2)) }, async loadItems() { if (!this.allItems.length) { const r = await listItem({ pageNum:1, pageSize:999 }); this.allItems = r.rows || [] } }, async enter(row) { const r = await getProdReport(row.reportId); if (r.data) this.activeReport = r.data; else this.activeReport = row; this.loadGrid() } }