🐞 fix: 修复创建单据时的bug

This commit is contained in:
砂糖
2025-08-15 17:52:43 +08:00
parent 20b69078dc
commit 76408fda0d

View File

@@ -21,7 +21,8 @@
<el-table-column label="序号" type="index" width="50" align="center" />
<el-table-column prop="voucherNo" label="摘要">
<template slot-scope="scope">
<el-input v-model="scope.row.voucherNo" placeholder="请输入摘要" @input="handleCreditInput(scope.row)" @change="handleRowChange(scope.row)" />
<el-input v-model="scope.row.voucherNo" placeholder="请输入摘要" @input="handleCreditInput(scope.row)"
@change="handleRowChange(scope.row)" />
</template>
</el-table-column>
<!-- <el-table-column prop="voucherNo" label="单号">
@@ -67,17 +68,20 @@
<!-- 合计部分 -->
<el-row>
<el-descriptions>
<el-descriptions-item label="大写金额">
<span>{{ amountInWords }}</span>
</el-descriptions-item>
<el-descriptions-item label="借方合计">
<span>{{ debitAmount.toFixed(2) }}</span>
</el-descriptions-item>
<el-descriptions-item label="贷方合计">
<span>{{ creditAmount.toFixed(2) }}</span>
</el-descriptions-item>
</el-descriptions>
<el-row>
<el-descriptions>
<el-descriptions-item label="大写金额">
<span>{{ amountInWords }}</span>
</el-descriptions-item>
<el-descriptions-item label="借方合计">
<!-- 增加空值处理确保toFixed调用安全 -->
<span>{{ (debitAmount || 0).toFixed(2) }}</span>
</el-descriptions-item>
<el-descriptions-item label="贷方合计">
<span>{{ (creditAmount || 0).toFixed(2) }}</span>
</el-descriptions-item>
</el-descriptions>
</el-row>
</el-row>
<el-row>
@@ -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;