Commit 6da1867e by liangjianmin

fix(apply): 优化表单验证逻辑以提高可读性和维护性

重构 validateForm 方法,使用规则数组简化验证逻辑,减少重复代码。
parent 161df589
Showing with 13 additions and 32 deletions
...@@ -167,38 +167,19 @@ ...@@ -167,38 +167,19 @@
validateForm() { validateForm() {
var { apply_type, order_sn, customer_name, apply_fee_amount, relief_detail, relief_reason } = this.form; var { apply_type, order_sn, customer_name, apply_fee_amount, relief_detail, relief_reason } = this.form;
if (!apply_type) { var rules = [
this.errorMsg = '请选择申请类型'; { invalid: !apply_type, msg: '请选择申请类型' },
return false; { invalid: !order_sn, msg: '请输入订单号' },
} { invalid: !apply_fee_amount, msg: '请输入申请免收金额' },
{ invalid: isNaN(apply_fee_amount) || Number(apply_fee_amount) <= 0, msg: '请输入有效的申请免收金额' },
if (!order_sn) { { invalid: !relief_detail, msg: '请选择减免明细' },
this.errorMsg = '请输入订单号'; { invalid: !relief_reason, msg: '请输入免收原因' },
return false; { invalid: !customer_name, msg: '请输入有效的订单号以获取客户名称' }
} ];
if (!apply_fee_amount) { var failedRule = rules.find(rule => rule.invalid);
this.errorMsg = '请输入申请免收金额'; if (failedRule) {
return false; this.errorMsg = failedRule.msg;
}
if (isNaN(apply_fee_amount) || Number(apply_fee_amount) <= 0) {
this.errorMsg = '请输入有效的申请免收金额';
return false;
}
if (!relief_detail) {
this.errorMsg = '请选择减免明细';
return false;
}
if (!relief_reason) {
this.errorMsg = '请输入免收原因';
return false;
}
if (!customer_name) {
this.errorMsg = '请输入有效的订单号以获取客户名称';
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment