Commit 6da1867e by liangjianmin

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

重构 validateForm 方法,使用规则数组简化验证逻辑,减少重复代码。
parent 161df589
Showing with 13 additions and 32 deletions
......@@ -166,42 +166,23 @@
*/
validateForm() {
var { apply_type, order_sn, customer_name, apply_fee_amount, relief_detail, relief_reason } = this.form;
if (!apply_type) {
this.errorMsg = '请选择申请类型';
return false;
}
if (!order_sn) {
this.errorMsg = '请输入订单号';
return false;
}
if (!apply_fee_amount) {
this.errorMsg = '请输入申请免收金额';
return false;
}
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 = '请输入免收原因';
var rules = [
{ invalid: !apply_type, msg: '请选择申请类型' },
{ invalid: !order_sn, msg: '请输入订单号' },
{ invalid: !apply_fee_amount, msg: '请输入申请免收金额' },
{ invalid: isNaN(apply_fee_amount) || Number(apply_fee_amount) <= 0, msg: '请输入有效的申请免收金额' },
{ invalid: !relief_detail, msg: '请选择减免明细' },
{ invalid: !relief_reason, msg: '请输入免收原因' },
{ invalid: !customer_name, msg: '请输入有效的订单号以获取客户名称' }
];
var failedRule = rules.find(rule => rule.invalid);
if (failedRule) {
this.errorMsg = failedRule.msg;
return false;
}
if (!customer_name) {
this.errorMsg = '请输入有效的订单号以获取客户名称';
return false;
}
this.errorMsg = '';
return true;
},
......
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