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() { ...@@ -42,7 +42,7 @@ export function buildMarketTransferFormData() {
}, },
{ {
label: "收款账户", label: "收款账户",
name: "transferInMerchantId", name: "rcvMerchantId",
type: "select", type: "select",
attrs: { attrs: {
popperClass: "market-transfer-account-popper", popperClass: "market-transfer-account-popper",
...@@ -79,6 +79,37 @@ export function buildMarketTransferFormData() { ...@@ -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 = []) { export function getVisibleAmountFields(expenseCategoryIds = []) {
return EXPENSE_CATEGORY_OPTIONS.filter(item => expenseCategoryIds.includes(item.id)); return EXPENSE_CATEGORY_OPTIONS.filter(item => expenseCategoryIds.includes(item.id));
} }
...@@ -94,18 +125,3 @@ export function mapMarketFeeResults(data = {}) { ...@@ -94,18 +125,3 @@ export function mapMarketFeeResults(data = {}) {
totalAmount: data.expenseCategoryTotalResult || 0, 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 @@ ...@@ -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>
...@@ -110,23 +111,26 @@ ...@@ -110,23 +111,26 @@
<script> <script>
import { import {
downloadMarketTransferDetail,
getMarketTransferBankAccounts, getMarketTransferBankAccounts,
getMarketTransferFeeShow, getMarketTransferFeeShow,
getMarketTransferPlatformMerchants, getMarketTransferPlatformMerchants,
getTransferRecord, queryMarketTransferFee,
submitMarketTransferFee, submitMarketTransferFee,
} from "@api/accountManage"; } from "@api/accountManage";
import GlOssApi from "glsk-oss-jssdk"; import GlOssApi from "glsk-oss-jssdk";
import { mapActions, mapState } from "vuex"; import { mapActions, mapState } from "vuex";
import { deepClone } from "@/common/util"; import { deepClone } from "@/common/util";
import util from "@/libs/util";
import { baseConfig } from "@/main"; import { baseConfig } from "@/main";
import { import {
buildMarketFeeDownloadTask,
buildMarketTransferFormData, buildMarketTransferFormData,
buildMarketTransferSubmitParams,
EXPENSE_CATEGORY_OPTIONS, EXPENSE_CATEGORY_OPTIONS,
getVisibleAmountFields, getVisibleAmountFields,
mapMarketFeeResults, mapMarketFeeResults,
MARKET_TRANSFER_UPLOAD_RULE, MARKET_TRANSFER_UPLOAD_RULE,
normalizeApprovedMarketTransferFees,
} from "../accountStateManage/marketTransfer"; } from "../accountStateManage/marketTransfer";
export default { export default {
...@@ -150,6 +154,8 @@ export default { ...@@ -150,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: {},
...@@ -166,7 +172,7 @@ export default { ...@@ -166,7 +172,7 @@ export default {
billMerchantName: "", billMerchantName: "",
expenseCategoryIds: [], expenseCategoryIds: [],
transferTotalAmount: "", transferTotalAmount: "",
transferInMerchantId: "", rcvMerchantId: "",
invoiceRemark: "", invoiceRemark: "",
fileUrlList: [], fileUrlList: [],
remark: "", remark: "",
...@@ -176,7 +182,7 @@ export default { ...@@ -176,7 +182,7 @@ export default {
}, },
transferRules: { transferRules: {
expenseCategoryIds: [{ required: true, type: "array", min: 1, message: "请选择费用类型", trigger: "change" }], 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" }], invoiceRemark: [{ required: true, message: "请输入发票及其他说明", trigger: "change" }],
fileUrlList: [{ required: true, type: "array", min: 1, message: "请选择转账凭证", trigger: "change" }], fileUrlList: [{ required: true, type: "array", min: 1, message: "请选择转账凭证", trigger: "change" }],
}, },
...@@ -218,7 +224,7 @@ export default { ...@@ -218,7 +224,7 @@ export default {
})); }));
const formData = buildMarketTransferFormData().map(item => ({ ...item })); const formData = buildMarketTransferFormData().map(item => ({ ...item }));
const billMerchant = formData.find(item => item.name === "billMerchantName"); 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; billMerchant.label = this.billMerchantLabel;
bankAccount.optionList = this.bankAccountList; bankAccount.optionList = this.bankAccountList;
...@@ -255,25 +261,25 @@ export default { ...@@ -255,25 +261,25 @@ export default {
})); }));
}); });
}, },
getTransferDetail() { // getTransferDetail() {
getTransferRecord({ id: this.info.id }).then((res) => { // getTransferRecord({ id: this.info.id }).then((res) => {
const transferList = res.transferList || []; // const transferList = res.transferList || [];
const currentPlatformMerchantId = this.transferForm.platformMerchantId; // const currentPlatformMerchantId = this.transferForm.platformMerchantId;
const currentPlatformMerchantName = this.transferForm.platformMerchantName; // const currentPlatformMerchantName = this.transferForm.platformMerchantName;
this.detailInfo = transferList[0] || {}; // this.detailInfo = transferList[0] || {};
this.transferForm = { // this.transferForm = {
...this.transferForm, // ...this.transferForm,
...this.detailInfo, // ...this.detailInfo,
...deepClone(this.info), // ...deepClone(this.info),
id: this.info.id, // id: this.info.id,
reconciliationBillId: this.info.id, // reconciliationBillId: this.info.id,
platformMerchantId: currentPlatformMerchantId, // platformMerchantId: currentPlatformMerchantId,
platformMerchantName: currentPlatformMerchantName, // platformMerchantName: currentPlatformMerchantName,
expenseCategoryIds: [], // expenseCategoryIds: [],
fileUrlList: [], // fileUrlList: [],
}; // };
}); // });
}, // },
getBankAccountList() { getBankAccountList() {
getMarketTransferBankAccounts({ getMarketTransferBankAccounts({
currentPage: 1, currentPage: 1,
...@@ -282,7 +288,7 @@ export default { ...@@ -282,7 +288,7 @@ export default {
this.bankAccountList = (res.list || []).map(item => ({ this.bankAccountList = (res.list || []).map(item => ({
// value: item.merchantId || item.id || item.bankAccountNo, // value: item.merchantId || item.id || item.bankAccountNo,
// label: this.formatBankAccountLabel(item), // label: this.formatBankAccountLabel(item),
value: item.bankAccountNo, value: item.merchantId,
label: item.bankAccountName, label: item.bankAccountName,
})); }));
}); });
...@@ -299,9 +305,10 @@ export default { ...@@ -299,9 +305,10 @@ export default {
return; return;
this.transferForm.platformMerchantId = this.platformForm.platformMerchantId; this.transferForm.platformMerchantId = this.platformForm.platformMerchantId;
this.transferForm.platformMerchantName = this.platformForm.platformMerchantName; this.transferForm.platformMerchantName = this.platformForm.platformMerchantName;
this.getTransferDetail(); // this.getTransferDetail();
this.getBankAccountList(); this.getBankAccountList();
this.step = 2; this.step = 2;
this.queryApprovedMarketTransferFee();
}); });
return; return;
} }
...@@ -314,32 +321,76 @@ export default { ...@@ -314,32 +321,76 @@ 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);
}, },
handleExpenseChange(value) { isExpenseCategoryDisabled(id) {
this.clearTransferValidate("expenseCategoryIds"); return this.lockedExpenseCategoryIds.includes(id);
this.visibleAmountFields.forEach((item) => { },
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}`, ""); this.$set(this.transferForm, `amount_${item.id}`, "");
return;
}
this.$set(this.transferForm, `amount_${item.id}`, amountMap[item.id] ?? "");
}); });
if (!value.length) { 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");
const unlockedExpenseCategoryIds = this.getUnlockedExpenseCategoryIds(expenseCategoryIds);
if (!expenseCategoryIds.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,
}); });
}); });
}, },
handleDownloadDetail() { handleDownloadDetail() {
const list = [ const params = {
...this.dowloadList, reconciliationBillId: this.info.id,
buildMarketFeeDownloadTask(this.info, this.transferForm.expenseCategoryIds), expenseCategoryIds: this.transferForm.expenseCategoryIds,
]; };
this.actionSetDownloadList({ list, type: "dowloadList" }); downloadMarketTransferDetail(params).then((res) => {
console.log("下载任务已创建", res);
util.open(res);
});
}, },
formatBankAccountLabel(item) { formatBankAccountLabel(item) {
const accountName = item.bankAccountName || item.merchantName || ""; const accountName = item.bankAccountName || item.merchantName || "";
...@@ -349,10 +400,18 @@ export default { ...@@ -349,10 +400,18 @@ export default {
}, },
submitTransfer() { submitTransfer() {
this.$refs.transferFormRef.$refs[this.transferChildRef].validate((valid) => { this.$refs.transferFormRef.$refs[this.transferChildRef].validate((valid) => {
this.transferForm.payName = this.transferForm.platformMerchantName;
if (!valid) if (!valid)
return; return;
const params = deepClone(this.transferForm); const params = buildMarketTransferSubmitParams(deepClone(this.transferForm), this.lockedExpenseCategoryIds);
params.fileUrlList = params.fileUrlList.map(item => item.fileUrl); if (!params.expenseCategoryIds.length) {
this.$message.error("请选择新的费用类型");
return;
}
if (!params.fileUrlList.length) {
this.$message.error("请等待转账凭证上传完成");
return;
}
submitMarketTransferFee(params).then(() => { submitMarketTransferFee(params).then(() => {
this.$message.success("操作成功"); this.$message.success("操作成功");
this.$emit("handleConfirm"); this.$emit("handleConfirm");
......
...@@ -3,9 +3,10 @@ import { ...@@ -3,9 +3,10 @@ import {
EXPENSE_CATEGORY_OPTIONS, EXPENSE_CATEGORY_OPTIONS,
FORM_COMPONENT_RULE, FORM_COMPONENT_RULE,
buildMarketTransferFormData, buildMarketTransferFormData,
buildMarketTransferSubmitParams,
getVisibleAmountFields, getVisibleAmountFields,
mapMarketFeeResults, normalizeApprovedMarketTransferFees,
buildMarketFeeDownloadTask mapMarketFeeResults
} from "@/views/financeManage/accountStateManage/marketTransfer" } from "@/views/financeManage/accountStateManage/marketTransfer"
describe("marketTransfer helpers", () => { describe("marketTransfer helpers", () => {
...@@ -13,7 +14,6 @@ describe("marketTransfer helpers", () => { ...@@ -13,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", () => {
...@@ -29,24 +29,21 @@ describe("marketTransfer helpers", () => { ...@@ -29,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", () => {
...@@ -78,8 +75,27 @@ describe("marketTransfer helpers", () => { ...@@ -78,8 +75,27 @@ describe("marketTransfer helpers", () => {
}) })
it("adds a horizontal-scroll popper class for bank account options", () => { 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") 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!