Commit e57c9d09 authored by 邓春圆's avatar 邓春圆

表单验证

parent 291a052e
...@@ -690,7 +690,11 @@ export default { ...@@ -690,7 +690,11 @@ export default {
}, },
contactRules: { contactRules: {
name: [{ required: true, message: this.$t('请输入联系人'), trigger: "blur" }], name: [{ required: true, message: this.$t('请输入联系人'), trigger: "blur" }],
areaCode: [{ required: true, message: this.$t('请选择区号'), trigger: "change" }], areaCode: [{ required: true, message: this.$t('请选择区号'), trigger: "change" },{
required: true,
trigger: 'change',
validator:this.codeValidator
}],
phoneNew: [{ phoneNew: [{
required: true, required: true,
trigger: "blur", trigger: "blur",
...@@ -772,20 +776,45 @@ export default { ...@@ -772,20 +776,45 @@ export default {
phoneValidator(rule, value, callback){ phoneValidator(rule, value, callback){
if (!value) { if (!value) {
return callback(new Error(this.$t('请输入联系方式'))); return callback(new Error(this.$t('请输入联系方式')));
} }
validatorMobile({ let areaCode = this.form.customerContacts.find(e => e.phoneNew === value).areaCode
code: this.form.customerContacts.find(e => e.phoneNew === value).areaCode, if(areaCode){
mobile: value validatorMobile({
}).then(r => { code: areaCode,
if (r.data){ mobile: value
}).then(r => {
if (r.data){
callback()
} else {
callback(new Error(r.msg || this.$t('手机号验证失败')))
}
}).catch(e => {
console.error(e)
callback(new Error(this.$t('手机号验证失败')))
})
}
},
codeValidator(rule, value, callback){
let index = +(rule.field.split('.')[1])
let phone = this.form.customerContacts[index].phoneNew
if(phone){
validatorMobile({
code:value,
mobile: phone
}).then(r => {
if (r.data){
callback()
} else {
callback()
this.$message.error(r.msg || this.$t('手机号验证失败'))
}
}).catch(e => {
console.error(e)
callback() callback()
} else { this.$message.error(this.$t('手机号验证失败'))
callback(new Error(r.msg || this.$t('手机号验证失败'))) })
} }
}).catch(e => {
console.error(e)
callback(new Error(this.$t('手机号验证失败')))
})
}, },
handleDefaultChange($index){ handleDefaultChange($index){
// 只有一个联系人,设置成非默认 // 只有一个联系人,设置成非默认
......
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 to comment