Commit b88d5e0d by chenwq

新增市场费下载参数构建函数,并更新相关逻辑和单元测试

1 parent cfceedc0
......@@ -91,6 +91,15 @@ export function buildMarketTransferSubmitParams(form = {}, excludeExpenseCategor
return params;
}
export function buildMarketTransferDownloadParams(form = {}, excludeExpenseCategoryIds = []) {
const expenseCategoryIds = Array.isArray(form.expenseCategoryIds) ? form.expenseCategoryIds : [];
return {
reconciliationBillId: form.reconciliationBillId,
expenseCategoryIds: expenseCategoryIds.filter(id => !excludeExpenseCategoryIds.includes(id)),
};
}
export function normalizeApprovedMarketTransferFees(list = []) {
const amountMap = {};
const expenseCategoryIds = [];
......@@ -122,6 +131,6 @@ export function mapMarketFeeResults(data = {}) {
return {
amountMap,
totalAmount: data.expenseCategoryTotalResult || 0,
totalAmount: data?.expenseCategoryTotalResult || 0,
};
}
......@@ -124,6 +124,7 @@ import { deepClone } from "@/common/util";
import util from "@/libs/util";
import { baseConfig } from "@/main";
import {
buildMarketTransferDownloadParams,
buildMarketTransferFormData,
buildMarketTransferSubmitParams,
EXPENSE_CATEGORY_OPTIONS,
......@@ -289,7 +290,7 @@ export default {
// value: item.merchantId || item.id || item.bankAccountNo,
// label: this.formatBankAccountLabel(item),
value: item.merchantId,
label: item.bankAccountName,
label: item.bankAccountName + " / " + item.bankAccountNo,
}));
});
},
......@@ -345,7 +346,7 @@ export default {
}
});
},
applyExpenseAmountMap(amountMap = {}) {
applyExpenseAmountMap(amountMap = {}, totalAmount) {
EXPENSE_CATEGORY_OPTIONS.forEach((item) => {
if (!this.transferForm.expenseCategoryIds.includes(item.id)) {
this.$set(this.transferForm, `amount_${item.id}`, "");
......@@ -353,9 +354,7 @@ export default {
}
this.$set(this.transferForm, `amount_${item.id}`, amountMap[item.id] ?? "");
});
this.transferForm.transferTotalAmount = this.transferForm.expenseCategoryIds.reduce((total, id) => {
return total + (Number(amountMap[id]) || 0);
}, 0);
this.transferForm.transferTotalAmount = totalAmount || 0;
},
handleExpenseChange(value) {
const expenseCategoryIds = this.mergeLockedExpenseCategoryIds(value);
......@@ -379,14 +378,18 @@ export default {
this.applyExpenseAmountMap({
...result.amountMap,
...this.lockedExpenseAmountMap,
});
}, result.totalAmount);
});
},
handleDownloadDetail() {
const params = {
const params = buildMarketTransferDownloadParams({
reconciliationBillId: this.info.id,
expenseCategoryIds: this.transferForm.expenseCategoryIds,
};
}, this.lockedExpenseCategoryIds);
if (!params.expenseCategoryIds.length) {
this.$message.error("请选择新的费用类型");
return;
}
downloadMarketTransferDetail(params).then((res) => {
console.log("下载任务已创建", res);
util.open(res);
......
......@@ -3,6 +3,7 @@ import {
EXPENSE_CATEGORY_OPTIONS,
FORM_COMPONENT_RULE,
buildMarketTransferFormData,
buildMarketTransferDownloadParams,
buildMarketTransferSubmitParams,
getVisibleAmountFields,
normalizeApprovedMarketTransferFees,
......@@ -22,11 +23,11 @@ describe("marketTransfer helpers", () => {
{ expenseCategoryId: 706, expenseCategoryResult: 11 },
{ expenseCategoryId: 900, expenseCategoryResult: 22 }
],
expenseCategoryTotalResult: 33
expenseCategoryTotalResult: 1.17
})
expect(result.amountMap).toEqual({ 706: 11, 900: 22 })
expect(result.totalAmount).toBe(33)
expect(result.totalAmount).toBe(1.17)
})
it("normalizes approved market transfer fees for default checked readonly categories", () => {
......@@ -98,4 +99,16 @@ describe("marketTransfer helpers", () => {
expect(params.id).toBe("bill-1")
expect(params.remark).toBe("ok")
})
it("downloads details only for unchecked approval expense categories", () => {
const params = buildMarketTransferDownloadParams({
reconciliationBillId: "bill-1",
expenseCategoryIds: [706, 808, 900]
}, [706, 900])
expect(params).toEqual({
reconciliationBillId: "bill-1",
expenseCategoryIds: [808]
})
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!