Commit facf2974 by Jaxon

Merge remote-tracking branch 'origin/SAAS+V5.8.2-cwq' into SAAS+V5.8.2-cwq

2 parents 08436565 2277962c
......@@ -42,7 +42,7 @@ export function buildMarketTransferFormData() {
},
{
label: "收款账户",
name: "transferInMerchantId",
name: "rcvMerchantId",
type: "select",
attrs: {
popperClass: "market-transfer-account-popper",
......@@ -79,6 +79,37 @@ export function buildMarketTransferFormData() {
];
}
export function buildMarketTransferSubmitParams(form = {}, excludeExpenseCategoryIds = []) {
const params = { ...form };
const fileUrlList = Array.isArray(params.fileUrlList) ? params.fileUrlList : [];
const expenseCategoryIds = Array.isArray(params.expenseCategoryIds) ? params.expenseCategoryIds : [];
params.expenseCategoryIds = expenseCategoryIds.filter(id => !excludeExpenseCategoryIds.includes(id));
params.fileUrlList = fileUrlList
.map(item => item && item.fileUrl)
.filter(Boolean);
delete params.fileUrl;
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 = []) {
return EXPENSE_CATEGORY_OPTIONS.filter(item => expenseCategoryIds.includes(item.id));
}
......@@ -94,18 +125,3 @@ export function mapMarketFeeResults(data = {}) {
totalAmount: data.expenseCategoryTotalResult || 0,
};
}
export function buildMarketFeeDownloadTask(row, expenseCategoryIds = []) {
const params = {
id: row.id,
expenseCategoryIds,
method: "dj.api.smartcarlife.reconciliationBill.transfer.market.fee.download",
};
return {
name: "市场费转账明细",
exportParam: JSON.stringify(params),
status: "waiting",
timeid: new Date().getTime(),
};
}
......@@ -33,6 +33,7 @@
@change="handleExpenseChange">
<el-checkbox v-for="item in expenseCategoryOptions"
:key="item.id"
:disabled="isExpenseCategoryDisabled(item.id)"
:label="item.id">
{{ item.label }}
</el-checkbox>
......@@ -110,23 +111,26 @@
<script>
import {
downloadMarketTransferDetail,
getMarketTransferBankAccounts,
getMarketTransferFeeShow,
getMarketTransferPlatformMerchants,
getTransferRecord,
queryMarketTransferFee,
submitMarketTransferFee,
} from "@api/accountManage";
import GlOssApi from "glsk-oss-jssdk";
import { mapActions, mapState } from "vuex";
import { deepClone } from "@/common/util";
import util from "@/libs/util";
import { baseConfig } from "@/main";
import {
buildMarketFeeDownloadTask,
buildMarketTransferFormData,
buildMarketTransferSubmitParams,
EXPENSE_CATEGORY_OPTIONS,
getVisibleAmountFields,
mapMarketFeeResults,
MARKET_TRANSFER_UPLOAD_RULE,
normalizeApprovedMarketTransferFees,
} from "../accountStateManage/marketTransfer";
export default {
......@@ -150,6 +154,8 @@ export default {
platformMerchantList: [],
bankAccountList: [],
expenseCategoryOptions: EXPENSE_CATEGORY_OPTIONS,
lockedExpenseCategoryIds: [],
lockedExpenseAmountMap: {},
uploadRule: MARKET_TRANSFER_UPLOAD_RULE,
uploadFileList: [],
detailInfo: {},
......@@ -166,7 +172,7 @@ export default {
billMerchantName: "",
expenseCategoryIds: [],
transferTotalAmount: "",
transferInMerchantId: "",
rcvMerchantId: "",
invoiceRemark: "",
fileUrlList: [],
remark: "",
......@@ -176,7 +182,7 @@ export default {
},
transferRules: {
expenseCategoryIds: [{ required: true, type: "array", min: 1, message: "请选择费用类型", trigger: "change" }],
transferInMerchantId: [{ required: true, message: "请选择收款账户", trigger: "change" }],
rcvMerchantId: [{ required: true, message: "请选择收款账户", trigger: "change" }],
invoiceRemark: [{ required: true, message: "请输入发票及其他说明", trigger: "change" }],
fileUrlList: [{ required: true, type: "array", min: 1, message: "请选择转账凭证", trigger: "change" }],
},
......@@ -218,7 +224,7 @@ export default {
}));
const formData = buildMarketTransferFormData().map(item => ({ ...item }));
const billMerchant = formData.find(item => item.name === "billMerchantName");
const bankAccount = formData.find(item => item.name === "transferInMerchantId");
const bankAccount = formData.find(item => item.name === "rcvMerchantId");
billMerchant.label = this.billMerchantLabel;
bankAccount.optionList = this.bankAccountList;
......@@ -255,25 +261,25 @@ export default {
}));
});
},
getTransferDetail() {
getTransferRecord({ id: this.info.id }).then((res) => {
const transferList = res.transferList || [];
const currentPlatformMerchantId = this.transferForm.platformMerchantId;
const currentPlatformMerchantName = this.transferForm.platformMerchantName;
this.detailInfo = transferList[0] || {};
this.transferForm = {
...this.transferForm,
...this.detailInfo,
...deepClone(this.info),
id: this.info.id,
reconciliationBillId: this.info.id,
platformMerchantId: currentPlatformMerchantId,
platformMerchantName: currentPlatformMerchantName,
expenseCategoryIds: [],
fileUrlList: [],
};
});
},
// getTransferDetail() {
// getTransferRecord({ id: this.info.id }).then((res) => {
// const transferList = res.transferList || [];
// const currentPlatformMerchantId = this.transferForm.platformMerchantId;
// const currentPlatformMerchantName = this.transferForm.platformMerchantName;
// this.detailInfo = transferList[0] || {};
// this.transferForm = {
// ...this.transferForm,
// ...this.detailInfo,
// ...deepClone(this.info),
// id: this.info.id,
// reconciliationBillId: this.info.id,
// platformMerchantId: currentPlatformMerchantId,
// platformMerchantName: currentPlatformMerchantName,
// expenseCategoryIds: [],
// fileUrlList: [],
// };
// });
// },
getBankAccountList() {
getMarketTransferBankAccounts({
currentPage: 1,
......@@ -282,7 +288,7 @@ export default {
this.bankAccountList = (res.list || []).map(item => ({
// value: item.merchantId || item.id || item.bankAccountNo,
// label: this.formatBankAccountLabel(item),
value: item.bankAccountNo,
value: item.merchantId,
label: item.bankAccountName,
}));
});
......@@ -299,9 +305,10 @@ export default {
return;
this.transferForm.platformMerchantId = this.platformForm.platformMerchantId;
this.transferForm.platformMerchantName = this.platformForm.platformMerchantName;
this.getTransferDetail();
// this.getTransferDetail();
this.getBankAccountList();
this.step = 2;
this.queryApprovedMarketTransferFee();
});
return;
}
......@@ -314,32 +321,76 @@ export default {
const formRef = this.$refs.transferFormRef?.$refs?.[this.transferChildRef];
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) {
const expenseCategoryIds = this.mergeLockedExpenseCategoryIds(value);
if (expenseCategoryIds.length !== value.length)
this.transferForm.expenseCategoryIds = expenseCategoryIds;
this.clearTransferValidate("expenseCategoryIds");
this.visibleAmountFields.forEach((item) => {
this.$set(this.transferForm, `amount_${item.id}`, "");
});
if (!value.length) {
const unlockedExpenseCategoryIds = this.getUnlockedExpenseCategoryIds(expenseCategoryIds);
if (!expenseCategoryIds.length) {
this.transferForm.transferTotalAmount = "";
return;
}
if (!unlockedExpenseCategoryIds.length) {
this.applyExpenseAmountMap(this.lockedExpenseAmountMap);
return;
}
getMarketTransferFeeShow({
reconciliationBillId: this.info.id,
expenseCategoryIds: value,
expenseCategoryIds: unlockedExpenseCategoryIds,
}).then((res) => {
const result = mapMarketFeeResults(res || {});
this.transferForm.transferTotalAmount = result.totalAmount;
Object.keys(result.amountMap).forEach((id) => {
this.$set(this.transferForm, `amount_${id}`, result.amountMap[id]);
this.applyExpenseAmountMap({
...result.amountMap,
...this.lockedExpenseAmountMap,
});
});
},
handleDownloadDetail() {
const list = [
...this.dowloadList,
buildMarketFeeDownloadTask(this.info, this.transferForm.expenseCategoryIds),
];
this.actionSetDownloadList({ list, type: "dowloadList" });
const params = {
reconciliationBillId: this.info.id,
expenseCategoryIds: this.transferForm.expenseCategoryIds,
};
downloadMarketTransferDetail(params).then((res) => {
console.log("下载任务已创建", res);
util.open(res);
});
},
formatBankAccountLabel(item) {
const accountName = item.bankAccountName || item.merchantName || "";
......@@ -349,10 +400,18 @@ export default {
},
submitTransfer() {
this.$refs.transferFormRef.$refs[this.transferChildRef].validate((valid) => {
this.transferForm.payName = this.transferForm.platformMerchantName;
if (!valid)
return;
const params = deepClone(this.transferForm);
params.fileUrlList = params.fileUrlList.map(item => item.fileUrl);
const params = buildMarketTransferSubmitParams(deepClone(this.transferForm), this.lockedExpenseCategoryIds);
if (!params.expenseCategoryIds.length) {
this.$message.error("请选择新的费用类型");
return;
}
if (!params.fileUrlList.length) {
this.$message.error("请等待转账凭证上传完成");
return;
}
submitMarketTransferFee(params).then(() => {
this.$message.success("操作成功");
this.$emit("handleConfirm");
......
......@@ -3,9 +3,10 @@ import {
EXPENSE_CATEGORY_OPTIONS,
FORM_COMPONENT_RULE,
buildMarketTransferFormData,
buildMarketTransferSubmitParams,
getVisibleAmountFields,
mapMarketFeeResults,
buildMarketFeeDownloadTask
normalizeApprovedMarketTransferFees,
mapMarketFeeResults
} from "@/views/financeManage/accountStateManage/marketTransfer"
describe("marketTransfer helpers", () => {
......@@ -13,7 +14,6 @@ describe("marketTransfer helpers", () => {
const fields = getVisibleAmountFields([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", () => {
......@@ -29,24 +29,21 @@ describe("marketTransfer helpers", () => {
expect(result.totalAmount).toBe(33)
})
it("builds one async download task for all selected categories", () => {
const task = buildMarketFeeDownloadTask({ id: "bill-1" }, [706, 808])
const exportParam = JSON.parse(task.exportParam)
it("normalizes approved market transfer fees for default checked readonly categories", () => {
const result = normalizeApprovedMarketTransferFees([
{ expenseCategoryId: 706, expenseCategoryResult: 11 },
{ expenseCategoryId: 706, expenseCategoryResult: 12 },
{ expenseCategoryId: 900, expenseCategoryResult: 22 },
{ expenseCategoryId: null, expenseCategoryResult: 33 }
])
expect(task.name).toBe("市场费转账明细")
expect(exportParam.id).toBe("bill-1")
expect(exportParam.expenseCategoryIds).toEqual([706, 808])
expect(exportParam.method).toBe("dj.api.smartcarlife.reconciliationBill.transfer.market.fee.download")
expect(result.expenseCategoryIds).toEqual([706, 900])
expect(result.amountMap).toEqual({ 706: 12, 900: 22 })
expect(result.totalAmount).toBe(34)
})
it("keeps the expense category options fixed", () => {
expect(EXPENSE_CATEGORY_OPTIONS).toEqual([
{ 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("keeps the expense category ids fixed", () => {
expect(EXPENSE_CATEGORY_OPTIONS.map(item => item.id)).toEqual([706, 808, 809, 901, 900])
})
it("uses the requested voucher upload rule", () => {
......@@ -78,8 +75,27 @@ describe("marketTransfer helpers", () => {
})
it("adds a horizontal-scroll popper class for bank account options", () => {
const bankAccount = buildMarketTransferFormData().find(item => item.name === "transferInMerchantId")
const bankAccount = buildMarketTransferFormData().find(item => item.name === "rcvMerchantId")
expect(bankAccount.attrs.popperClass).toBe("market-transfer-account-popper")
})
it("submits voucher urls as a fileUrlList array", () => {
const params = buildMarketTransferSubmitParams({
id: "bill-1",
remark: "ok",
expenseCategoryIds: [706, 808, 900],
fileUrlList: [
{ fileUrl: "https://example.com/a.png" },
{ fileUrl: "" },
{ fileUrl: "https://example.com/b.jpg" }
]
}, [706, 900])
expect(params.expenseCategoryIds).toEqual([808])
expect(params.fileUrlList).toEqual(["https://example.com/a.png", "https://example.com/b.jpg"])
expect(params.fileUrl).toBeUndefined()
expect(params.id).toBe("bill-1")
expect(params.remark).toBe("ok")
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!