🐞 fix: 修复创建单据时的bug
This commit is contained in:
@@ -21,7 +21,8 @@
|
|||||||
<el-table-column label="序号" type="index" width="50" align="center" />
|
<el-table-column label="序号" type="index" width="50" align="center" />
|
||||||
<el-table-column prop="voucherNo" label="摘要">
|
<el-table-column prop="voucherNo" label="摘要">
|
||||||
<template slot-scope="scope">
|
<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>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<!-- <el-table-column prop="voucherNo" label="单号">
|
<!-- <el-table-column prop="voucherNo" label="单号">
|
||||||
@@ -67,17 +68,20 @@
|
|||||||
|
|
||||||
<!-- 合计部分 -->
|
<!-- 合计部分 -->
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-descriptions>
|
<el-row>
|
||||||
<el-descriptions-item label="大写金额">
|
<el-descriptions>
|
||||||
<span>{{ amountInWords }}</span>
|
<el-descriptions-item label="大写金额">
|
||||||
</el-descriptions-item>
|
<span>{{ amountInWords }}</span>
|
||||||
<el-descriptions-item label="借方合计">
|
</el-descriptions-item>
|
||||||
<span>{{ debitAmount.toFixed(2) }}</span>
|
<el-descriptions-item label="借方合计">
|
||||||
</el-descriptions-item>
|
<!-- 增加空值处理,确保toFixed调用安全 -->
|
||||||
<el-descriptions-item label="贷方合计">
|
<span>{{ (debitAmount || 0).toFixed(2) }}</span>
|
||||||
<span>{{ creditAmount.toFixed(2) }}</span>
|
</el-descriptions-item>
|
||||||
</el-descriptions-item>
|
<el-descriptions-item label="贷方合计">
|
||||||
</el-descriptions>
|
<span>{{ (creditAmount || 0).toFixed(2) }}</span>
|
||||||
|
</el-descriptions-item>
|
||||||
|
</el-descriptions>
|
||||||
|
</el-row>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-row>
|
<el-row>
|
||||||
@@ -115,27 +119,27 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
// 借方总额和贷方总额(过滤空行)
|
// 借方总额(修复后)
|
||||||
debitAmount() {
|
debitAmount() {
|
||||||
|
// 确保reduce的初始值为0,且返回值为数字
|
||||||
return this.tableData.reduce((total, item) => {
|
return this.tableData.reduce((total, item) => {
|
||||||
// 只计算有内容的行
|
|
||||||
if (this.isRowNotEmpty(item)) {
|
if (this.isRowNotEmpty(item)) {
|
||||||
return total + (Number(item.debitAmount) || 0);
|
return total + (Number(item.debitAmount) || 0);
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}, 0);
|
}, 0) || 0; // 最后确保即使结果为undefined也返回0
|
||||||
},
|
},
|
||||||
|
// 贷方总额(修复后)
|
||||||
creditAmount() {
|
creditAmount() {
|
||||||
return this.tableData.reduce((total, item) => {
|
return this.tableData.reduce((total, item) => {
|
||||||
if (this.isRowNotEmpty(item)) {
|
if (this.isRowNotEmpty(item)) {
|
||||||
return total + (Number(item.creditAmount) || 0);
|
return total + (Number(item.creditAmount) || 0);
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}, 0);
|
}, 0) || 0; // 同样增加默认值0
|
||||||
},
|
},
|
||||||
// 大写金额
|
// 大写金额(保持不变)
|
||||||
amountInWords() {
|
amountInWords() {
|
||||||
// 如果借贷相等则正常显示,不相等则显示借贷不相等
|
|
||||||
if (Math.abs(this.debitAmount - this.creditAmount) < 0.01) {
|
if (Math.abs(this.debitAmount - this.creditAmount) < 0.01) {
|
||||||
return this.numberToChinese(this.debitAmount);
|
return this.numberToChinese(this.debitAmount);
|
||||||
} else {
|
} else {
|
||||||
@@ -147,7 +151,16 @@ export default {
|
|||||||
initData: {
|
initData: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: false,
|
required: false,
|
||||||
default: () => ({})
|
default: () => ({
|
||||||
|
tableData: [{
|
||||||
|
voucherNo: '',
|
||||||
|
accountId: undefined,
|
||||||
|
debitAmount: 0,
|
||||||
|
creditAmount: 0,
|
||||||
|
remark: '',
|
||||||
|
voucherNo: ''
|
||||||
|
}]
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@@ -155,7 +168,18 @@ export default {
|
|||||||
handler(newVal) {
|
handler(newVal) {
|
||||||
console.log(newVal, 'watchData');
|
console.log(newVal, 'watchData');
|
||||||
if (newVal) {
|
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.docNo = newVal.docNo;
|
||||||
this.form.docDate = newVal.docDate;
|
this.form.docDate = newVal.docDate;
|
||||||
this.form.relatedOrderId = newVal.relatedOrderId;
|
this.form.relatedOrderId = newVal.relatedOrderId;
|
||||||
|
|||||||
Reference in New Issue
Block a user