Commit d37f0935 by chenwq

feat: 添加市场费转账查询功能,优化相关数据处理逻辑

1 parent 943fb272
...@@ -200,6 +200,12 @@ export function downloadMarketTransferDetail(data) { ...@@ -200,6 +200,12 @@ export function downloadMarketTransferDetail(data) {
return request(data, "post"); return request(data, "post");
} }
// 市场费转账 - 查询对账单已发起审批或审批通过的费用类型
export function queryMarketTransferFee(data) {
data.method = "dj.api.smartcarlife.reconciliationBill.transfer.market.fee.query";
return request(data, "post");
}
// 市场费转账-收款账户 // 市场费转账-收款账户
export function getMarketTransferBankAccounts(data) { export function getMarketTransferBankAccounts(data) {
data.method = "dj.api.smartcarlife.merchantBankEnterpriseAccount.listWithPage"; data.method = "dj.api.smartcarlife.merchantBankEnterpriseAccount.listWithPage";
......
...@@ -89,6 +89,25 @@ export function buildMarketTransferSubmitParams(form = {}) { ...@@ -89,6 +89,25 @@ export function buildMarketTransferSubmitParams(form = {}) {
return params; return params;
} }
export function normalizeApprovedMarketTransferFees(list = []) {
const amountMap = {};
const expenseCategoryIds = [];
(list || []).forEach((item) => {
const id = item && item.expenseCategoryId;
if (id === undefined || id === null)
return;
if (!expenseCategoryIds.includes(id))
expenseCategoryIds.push(id);
amountMap[id] = item.expenseCategoryResult;
});
return {
expenseCategoryIds,
amountMap,
totalAmount: Object.keys(amountMap).reduce((total, id) => total + (Number(amountMap[id]) || 0), 0),
};
}
export function getVisibleAmountFields(expenseCategoryIds = []) { export function getVisibleAmountFields(expenseCategoryIds = []) {
return EXPENSE_CATEGORY_OPTIONS.filter(item => expenseCategoryIds.includes(item.id)); return EXPENSE_CATEGORY_OPTIONS.filter(item => expenseCategoryIds.includes(item.id));
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
@change="handleExpenseChange"> @change="handleExpenseChange">
<el-checkbox v-for="item in expenseCategoryOptions" <el-checkbox v-for="item in expenseCategoryOptions"
:key="item.id" :key="item.id"
:disabled="isExpenseCategoryDisabled(item.id)"
:label="item.id"> :label="item.id">
{{ item.label }} {{ item.label }}
</el-checkbox> </el-checkbox>
...@@ -114,6 +115,7 @@ import { ...@@ -114,6 +115,7 @@ import {
getMarketTransferBankAccounts, getMarketTransferBankAccounts,
getMarketTransferFeeShow, getMarketTransferFeeShow,
getMarketTransferPlatformMerchants, getMarketTransferPlatformMerchants,
queryMarketTransferFee,
submitMarketTransferFee, submitMarketTransferFee,
} from "@api/accountManage"; } from "@api/accountManage";
import GlOssApi from "glsk-oss-jssdk"; import GlOssApi from "glsk-oss-jssdk";
...@@ -128,6 +130,7 @@ import { ...@@ -128,6 +130,7 @@ import {
getVisibleAmountFields, getVisibleAmountFields,
mapMarketFeeResults, mapMarketFeeResults,
MARKET_TRANSFER_UPLOAD_RULE, MARKET_TRANSFER_UPLOAD_RULE,
normalizeApprovedMarketTransferFees,
} from "../accountStateManage/marketTransfer"; } from "../accountStateManage/marketTransfer";
export default { export default {
...@@ -151,6 +154,8 @@ export default { ...@@ -151,6 +154,8 @@ export default {
platformMerchantList: [], platformMerchantList: [],
bankAccountList: [], bankAccountList: [],
expenseCategoryOptions: EXPENSE_CATEGORY_OPTIONS, expenseCategoryOptions: EXPENSE_CATEGORY_OPTIONS,
lockedExpenseCategoryIds: [],
lockedExpenseAmountMap: {},
uploadRule: MARKET_TRANSFER_UPLOAD_RULE, uploadRule: MARKET_TRANSFER_UPLOAD_RULE,
uploadFileList: [], uploadFileList: [],
detailInfo: {}, detailInfo: {},
...@@ -303,6 +308,7 @@ export default { ...@@ -303,6 +308,7 @@ export default {
// this.getTransferDetail(); // this.getTransferDetail();
this.getBankAccountList(); this.getBankAccountList();
this.step = 2; this.step = 2;
this.queryApprovedMarketTransferFee();
}); });
return; return;
} }
...@@ -315,23 +321,64 @@ export default { ...@@ -315,23 +321,64 @@ export default {
const formRef = this.$refs.transferFormRef?.$refs?.[this.transferChildRef]; const formRef = this.$refs.transferFormRef?.$refs?.[this.transferChildRef];
formRef && formRef.clearValidate(field); formRef && formRef.clearValidate(field);
}, },
isExpenseCategoryDisabled(id) {
return this.lockedExpenseCategoryIds.includes(id);
},
mergeLockedExpenseCategoryIds(ids = []) {
return [...new Set([...this.lockedExpenseCategoryIds, ...ids])];
},
getUnlockedExpenseCategoryIds(ids = []) {
return ids.filter(id => !this.lockedExpenseCategoryIds.includes(id));
},
queryApprovedMarketTransferFee() {
queryMarketTransferFee({
reconciliationBillId: this.info.id,
}).then((res) => {
const result = normalizeApprovedMarketTransferFees(res || []);
this.lockedExpenseCategoryIds = result.expenseCategoryIds;
this.lockedExpenseAmountMap = result.amountMap;
const expenseCategoryIds = this.mergeLockedExpenseCategoryIds(this.transferForm.expenseCategoryIds);
this.transferForm.expenseCategoryIds = expenseCategoryIds;
this.applyExpenseAmountMap(this.lockedExpenseAmountMap);
if (this.getUnlockedExpenseCategoryIds(expenseCategoryIds).length) {
this.handleExpenseChange(expenseCategoryIds);
}
});
},
applyExpenseAmountMap(amountMap = {}) {
EXPENSE_CATEGORY_OPTIONS.forEach((item) => {
if (!this.transferForm.expenseCategoryIds.includes(item.id)) {
this.$set(this.transferForm, `amount_${item.id}`, "");
return;
}
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);
},
handleExpenseChange(value) { handleExpenseChange(value) {
const expenseCategoryIds = this.mergeLockedExpenseCategoryIds(value);
if (expenseCategoryIds.length !== value.length)
this.transferForm.expenseCategoryIds = expenseCategoryIds;
this.clearTransferValidate("expenseCategoryIds"); this.clearTransferValidate("expenseCategoryIds");
this.visibleAmountFields.forEach((item) => { const unlockedExpenseCategoryIds = this.getUnlockedExpenseCategoryIds(expenseCategoryIds);
this.$set(this.transferForm, `amount_${item.id}`, ""); if (!expenseCategoryIds.length) {
});
if (!value.length) {
this.transferForm.transferTotalAmount = ""; this.transferForm.transferTotalAmount = "";
return; return;
} }
if (!unlockedExpenseCategoryIds.length) {
this.applyExpenseAmountMap(this.lockedExpenseAmountMap);
return;
}
getMarketTransferFeeShow({ getMarketTransferFeeShow({
reconciliationBillId: this.info.id, reconciliationBillId: this.info.id,
expenseCategoryIds: value, expenseCategoryIds: unlockedExpenseCategoryIds,
}).then((res) => { }).then((res) => {
const result = mapMarketFeeResults(res || {}); const result = mapMarketFeeResults(res || {});
this.transferForm.transferTotalAmount = result.totalAmount; this.applyExpenseAmountMap({
Object.keys(result.amountMap).forEach((id) => { ...result.amountMap,
this.$set(this.transferForm, `amount_${id}`, result.amountMap[id]); ...this.lockedExpenseAmountMap,
}); });
}); });
}, },
......
...@@ -5,8 +5,8 @@ import { ...@@ -5,8 +5,8 @@ import {
buildMarketTransferFormData, buildMarketTransferFormData,
buildMarketTransferSubmitParams, buildMarketTransferSubmitParams,
getVisibleAmountFields, getVisibleAmountFields,
mapMarketFeeResults, normalizeApprovedMarketTransferFees,
buildMarketFeeDownloadTask mapMarketFeeResults
} from "@/views/financeManage/accountStateManage/marketTransfer" } from "@/views/financeManage/accountStateManage/marketTransfer"
describe("marketTransfer helpers", () => { describe("marketTransfer helpers", () => {
...@@ -14,7 +14,6 @@ describe("marketTransfer helpers", () => { ...@@ -14,7 +14,6 @@ describe("marketTransfer helpers", () => {
const fields = getVisibleAmountFields([706, 900]) const fields = getVisibleAmountFields([706, 900])
expect(fields.map(item => item.id)).toEqual([706, 900]) expect(fields.map(item => item.id)).toEqual([706, 900])
expect(fields.map(item => item.amountLabel)).toEqual(["管理层市场费1金额", "资源费金额"])
}) })
it("maps market fee result rows by expense category id", () => { it("maps market fee result rows by expense category id", () => {
...@@ -30,24 +29,21 @@ describe("marketTransfer helpers", () => { ...@@ -30,24 +29,21 @@ describe("marketTransfer helpers", () => {
expect(result.totalAmount).toBe(33) expect(result.totalAmount).toBe(33)
}) })
it("builds one async download task for all selected categories", () => { it("normalizes approved market transfer fees for default checked readonly categories", () => {
const task = buildMarketFeeDownloadTask({ id: "bill-1" }, [706, 808]) const result = normalizeApprovedMarketTransferFees([
const exportParam = JSON.parse(task.exportParam) { expenseCategoryId: 706, expenseCategoryResult: 11 },
{ expenseCategoryId: 706, expenseCategoryResult: 12 },
{ expenseCategoryId: 900, expenseCategoryResult: 22 },
{ expenseCategoryId: null, expenseCategoryResult: 33 }
])
expect(task.name).toBe("市场费转账明细") expect(result.expenseCategoryIds).toEqual([706, 900])
expect(exportParam.id).toBe("bill-1") expect(result.amountMap).toEqual({ 706: 12, 900: 22 })
expect(exportParam.expenseCategoryIds).toEqual([706, 808]) expect(result.totalAmount).toBe(34)
expect(exportParam.method).toBe("dj.api.smartcarlife.reconciliationBill.transfer.market.fee.download")
}) })
it("keeps the expense category options fixed", () => { it("keeps the expense category ids fixed", () => {
expect(EXPENSE_CATEGORY_OPTIONS).toEqual([ expect(EXPENSE_CATEGORY_OPTIONS.map(item => item.id)).toEqual([706, 808, 809, 901, 900])
{ id: 706, label: "管理层市场费1", amountLabel: "管理层市场费1金额" },
{ id: 808, label: "管理层市场费2", amountLabel: "管理层市场费2金额" },
{ id: 809, label: "阳光激励费", amountLabel: "阳光激励费金额" },
{ id: 901, label: "阳光激励费2", amountLabel: "阳光激励费2金额" },
{ id: 900, label: "资源费", amountLabel: "资源费金额" }
])
}) })
it("uses the requested voucher upload rule", () => { it("uses the requested voucher upload rule", () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!