From 76408fda0d40ca7c13bea854022ce77a14f191ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=82=E7=B3=96?= Date: Fri, 15 Aug 2025 17:52:43 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=8D=95=E6=8D=AE=E6=97=B6=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../finance/document/components/Voucher.vue | 64 +++++++++++++------ 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/klp-ui/src/views/finance/document/components/Voucher.vue b/klp-ui/src/views/finance/document/components/Voucher.vue index 221fac69..1e158b39 100644 --- a/klp-ui/src/views/finance/document/components/Voucher.vue +++ b/klp-ui/src/views/finance/document/components/Voucher.vue @@ -21,7 +21,8 @@ - - - {{ amountInWords }} - - - {{ debitAmount.toFixed(2) }} - - - {{ creditAmount.toFixed(2) }} - - + + + + {{ amountInWords }} + + + + {{ (debitAmount || 0).toFixed(2) }} + + + {{ (creditAmount || 0).toFixed(2) }} + + + @@ -115,27 +119,27 @@ export default { } }, computed: { - // 借方总额和贷方总额(过滤空行) + // 借方总额(修复后) debitAmount() { + // 确保reduce的初始值为0,且返回值为数字 return this.tableData.reduce((total, item) => { - // 只计算有内容的行 if (this.isRowNotEmpty(item)) { return total + (Number(item.debitAmount) || 0); } return total; - }, 0); + }, 0) || 0; // 最后确保即使结果为undefined也返回0 }, + // 贷方总额(修复后) creditAmount() { return this.tableData.reduce((total, item) => { if (this.isRowNotEmpty(item)) { return total + (Number(item.creditAmount) || 0); } return total; - }, 0); + }, 0) || 0; // 同样增加默认值0 }, - // 大写金额 + // 大写金额(保持不变) amountInWords() { - // 如果借贷相等则正常显示,不相等则显示借贷不相等 if (Math.abs(this.debitAmount - this.creditAmount) < 0.01) { return this.numberToChinese(this.debitAmount); } else { @@ -147,7 +151,16 @@ export default { initData: { type: Object, required: false, - default: () => ({}) + default: () => ({ + tableData: [{ + voucherNo: '', + accountId: undefined, + debitAmount: 0, + creditAmount: 0, + remark: '', + voucherNo: '' + }] + }) } }, watch: { @@ -155,7 +168,18 @@ export default { handler(newVal) { console.log(newVal, 'watchData'); if (newVal) { - this.tableData = newVal.detailList; + if (newVal.detailList) { + this.tableData = newVal.detailList; + } else { + this.tableData = [{ + voucherNo: '', + accountId: undefined, + debitAmount: 0, + creditAmount: 0, + remark: '', + voucherNo: '' + }] + } this.form.docNo = newVal.docNo; this.form.docDate = newVal.docDate; this.form.relatedOrderId = newVal.relatedOrderId;