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;