fix(报表): 修复全年日历报表中金额计算逻辑错误

修复 getAmount 函数中 d.val 为 "other" 时的匹配逻辑,正确结果为支付方式为空或为"其他"的和。
This commit is contained in:
2026-02-03 16:38:45 +08:00
parent 7943cf2cb5
commit 2a457fc076
2 changed files with 23 additions and 13 deletions

View File

@@ -212,25 +212,36 @@ export default {
},
methods: {
getAmount(d, index, month) {
// 定义所有可能的匹配规则
if (!month || !month.total || !Array.isArray(month.total)) {
return "0";
}
if (d.val === "other") {
const list = month.total.filter(item => {
return (
item.type === d.realTitle &&
(item.payMethod === "" || item.payMethod === "其他")
);
});
if (!list.length) {
return "0";
}
return list.reduce((sum, item) => {
const val = Number(item.amount || 0);
return sum + (isNaN(val) ? 0 : val);
}, 0);
}
const matchRules = [
item => {
// 例如:当类型是特定值时,启用特殊匹配
if (d.val == "other" && item.payMethod == "") {
return `${item.type}` === d.realTitle;
}
return false;
},
item => item.type === d.title,
item => item.type === d.realTitle,
item => `${item.payMethod}${item.type}` === d.realTitle,
item => `${item.type}${item.payMethod}` === d.realTitle,
item => `${item.type}${item.goodsType}` === d.realTitle
// 更复杂的条件组合
];
// 依次检查每个规则,返回第一个匹配项
for (const rule of matchRules) {
const matchedItem = month.total.find(rule);
if (matchedItem) {
@@ -238,7 +249,6 @@ export default {
}
}
// 没有匹配项时返回空字符串
return "0";
},
async handleExportAll() {