Commit e63b3a84 by chenwq

feat(市场转账): 新增费用调整相关功能

新增调整费用输入表单项,包含输入合法性校验与自动格式化
优化转账总金额计算逻辑以支持叠加调整费用
当填写调整费用时自动将备注设为必填项
更新表单验证规则与校验清除逻辑
调整转账费用选择的处理函数参数与逻辑
1 parent 99abac62
......@@ -54,6 +54,12 @@ export function buildMarketTransferFormData() {
optionsName: "bankAccountList",
},
{
label: "费用调整",
name: "adjustmentFee",
type: "input",
maxlength: 20,
},
{
label: "转账金额",
name: "transferTotalAmount",
type: "showTxt",
......
......@@ -174,6 +174,7 @@ export default {
billType: "",
billMerchantName: "",
expenseCategoryIds: [],
adjustmentFee: "",
transferTotalAmount: "",
rcvMerchantId: "",
invoiceRemark: "",
......@@ -185,9 +186,11 @@ export default {
},
transferRules: {
expenseCategoryIds: [{ required: true, type: "array", min: 1, message: "请选择费用类型", trigger: "change" }],
adjustmentFee: [{ validator: (rule, value, callback) => this.validateAdjustmentFee(rule, value, callback), trigger: ["change", "blur"] }],
rcvMerchantId: [{ required: true, message: "请选择收款账户", trigger: "change" }],
invoiceRemark: [{ required: true, message: "请输入发票及其他说明", trigger: "change" }],
fileUrlList: [{ required: true, type: "array", min: 1, message: "请选择转账凭证", trigger: "change" }],
remark: [{ required: false, message: "请输入备注", trigger: "change" }],
},
};
},
......@@ -228,8 +231,13 @@ export default {
const formData = buildMarketTransferFormData().map(item => ({ ...item }));
const billMerchant = formData.find(item => item.name === "billMerchantName");
const bankAccount = formData.find(item => item.name === "rcvMerchantId");
const adjustmentFee = formData.find(item => item.name === "adjustmentFee");
billMerchant.label = this.billMerchantLabel;
bankAccount.optionList = this.bankAccountList;
adjustmentFee.inputFn = this.handleAdjustmentFeeInput;
adjustmentFee.listeners = {
blur: this.handleAdjustmentFeeBlur,
};
const expenseIndex = formData.findIndex(item => item.name === "expenseCategoryIds");
formData.splice(expenseIndex + 1, 0, ...amountFields);
......@@ -246,6 +254,7 @@ export default {
expenseCategoryIds: [],
fileUrlList: [],
};
this.syncRemarkRequired();
this.getPlatformMerchantList();
},
methods: {
......@@ -304,8 +313,9 @@ export default {
handleConfirm() {
if (this.step === 1) {
this.$refs.platformFormRef.$refs[this.platformChildRef].validate((valid) => {
if (!valid)
if (!valid) {
return;
}
this.transferForm.platformMerchantId = this.platformForm.platformMerchantId;
this.transferForm.platformMerchantName = this.platformForm.platformMerchantName;
// this.getTransferDetail();
......@@ -324,17 +334,87 @@ export default {
const formRef = this.$refs.transferFormRef?.$refs?.[this.transferChildRef];
formRef && formRef.clearValidate(field);
},
validateTransferField(field) {
const formRef = this.$refs.transferFormRef?.$refs?.[this.transferChildRef];
formRef && formRef.validateField(field);
},
validateTransferFieldWithCallback(field, callback) {
const formRef = this.$refs.transferFormRef?.$refs?.[this.transferChildRef];
formRef && formRef.validateField(field, callback);
},
clearTransferValidateAfterLayout() {
this.$nextTick(() => {
this.clearTransferValidate(["expenseCategoryIds", "rcvMerchantId", "invoiceRemark", "fileUrlList"]);
this.clearTransferValidate(["expenseCategoryIds", "adjustmentFee", "rcvMerchantId", "invoiceRemark", "fileUrlList", "remark"]);
});
},
refreshTransferFormValidateLayout() {
this.clearTransferValidate(["expenseCategoryIds", "rcvMerchantId", "invoiceRemark", "fileUrlList"]);
this.clearTransferValidate(["expenseCategoryIds", "adjustmentFee", "rcvMerchantId", "invoiceRemark", "fileUrlList", "remark"]);
this.$nextTick(() => {
this.transferFormKey += 1;
});
},
isAdjustmentFeeFilled() {
const adjustmentFee = this.transferForm.adjustmentFee;
return adjustmentFee !== undefined && adjustmentFee !== null && `${adjustmentFee}`.trim() !== "";
},
getAdjustedTransferTotalAmount(totalAmount) {
const adjustmentFee = Number(this.transferForm.adjustmentFee) || 0;
return ((Number(totalAmount) || 0) + adjustmentFee).toFixed(2);
},
getAmountMapTotal(amountMap = {}) {
return Object.keys(amountMap).reduce((total, key) => total + (Number(amountMap[key]) || 0), 0);
},
getLocalTransferTotalAmount(expenseCategoryIds = []) {
if (!expenseCategoryIds.length && !this.isAdjustmentFeeFilled()) {
return "";
}
const totalAmount = expenseCategoryIds.length ? this.getAmountMapTotal(this.lockedExpenseAmountMap) : 0;
return this.getAdjustedTransferTotalAmount(totalAmount);
},
syncRemarkRequired() {
this.$set(this.transferRules.remark[0], "required", this.isAdjustmentFeeFilled());
},
normalizeAdjustmentFeeInput(value) {
let nextValue = `${value || ""}`.replace(/[^\d.-]/g, "");
const isNegative = nextValue.startsWith("-");
nextValue = nextValue.replace(/-/g, "");
if (isNegative) {
nextValue = `-${nextValue}`;
}
const dotIndex = nextValue.indexOf(".");
if (dotIndex !== -1) {
nextValue = `${nextValue.slice(0, dotIndex + 1)}${nextValue.slice(dotIndex + 1).replace(/\./g, "")}`;
const parts = nextValue.split(".");
nextValue = `${parts[0]}.${parts[1].slice(0, 2)}`;
}
return nextValue.slice(0, 20);
},
handleAdjustmentFeeInput(value) {
this.transferForm.adjustmentFee = this.normalizeAdjustmentFeeInput(value);
this.syncRemarkRequired();
this.$nextTick(() => {
if (this.isAdjustmentFeeFilled()) {
this.validateTransferField("remark");
return;
}
this.clearTransferValidate("remark");
});
},
handleAdjustmentFeeBlur() {
this.validateTransferFieldWithCallback("adjustmentFee", (message) => {
if (message) {
return;
}
this.handleExpenseChange(this.transferForm.expenseCategoryIds, false);
});
},
validateAdjustmentFee(rule, value, callback) {
const adjustmentFee = `${value || ""}`.trim();
const error = adjustmentFee && !/^-?\d+(\.\d{1,2})?$/.test(adjustmentFee)
? new Error("费用调整仅支持数字、负数和两位小数")
: undefined;
callback(error);
},
isExpenseCategoryDisabled(id) {
return this.lockedExpenseCategoryIds.includes(id);
},
......@@ -369,18 +449,14 @@ export default {
});
this.transferForm.transferTotalAmount = totalAmount || 0;
},
handleExpenseChange(value) {
handleExpenseChange(value, refreshLayout = true) {
const expenseCategoryIds = this.mergeLockedExpenseCategoryIds(value);
if (expenseCategoryIds.length !== value.length)
if (expenseCategoryIds.length !== value.length) {
this.transferForm.expenseCategoryIds = expenseCategoryIds;
this.refreshTransferFormValidateLayout();
const unlockedExpenseCategoryIds = this.getUnlockedExpenseCategoryIds(expenseCategoryIds);
if (!expenseCategoryIds.length) {
this.transferForm.transferTotalAmount = "";
return;
}
const unlockedExpenseCategoryIds = this.getUnlockedExpenseCategoryIds(expenseCategoryIds);
if (!unlockedExpenseCategoryIds.length) {
this.applyExpenseAmountMap(this.lockedExpenseAmountMap);
this.applyExpenseAmountMap(this.lockedExpenseAmountMap, this.getLocalTransferTotalAmount(expenseCategoryIds));
return;
}
getMarketTransferFeeShow({
......@@ -391,8 +467,10 @@ export default {
this.applyExpenseAmountMap({
...result.amountMap,
...this.lockedExpenseAmountMap,
}, result.totalAmount);
this.refreshTransferFormValidateLayout();
}, this.getAdjustedTransferTotalAmount(result.totalAmount));
if (refreshLayout) {
this.refreshTransferFormValidateLayout();
}
});
},
handleDownloadDetail() {
......@@ -418,8 +496,9 @@ export default {
submitTransfer() {
this.$refs.transferFormRef.$refs[this.transferChildRef].validate((valid) => {
this.transferForm.payName = this.transferForm.platformMerchantName;
if (!valid)
if (!valid) {
return;
}
const params = buildMarketTransferSubmitParams(deepClone(this.transferForm), this.lockedExpenseCategoryIds);
if (!params.expenseCategoryIds.length) {
this.$message.error("请选择新的费用类型");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!