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

表单验证

parent 291a052e
......@@ -690,7 +690,11 @@ export default {
},
contactRules: {
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: [{
required: true,
trigger: "blur",
......@@ -772,9 +776,12 @@ export default {
phoneValidator(rule, value, callback){
if (!value) {
return callback(new Error(this.$t('请输入联系方式')));
}
let areaCode = this.form.customerContacts.find(e => e.phoneNew === value).areaCode
if(areaCode){
validatorMobile({
code: this.form.customerContacts.find(e => e.phoneNew === value).areaCode,
code: areaCode,
mobile: value
}).then(r => {
if (r.data){
......@@ -786,6 +793,28 @@ export default {
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()
this.$message.error(this.$t('手机号验证失败'))
})
}
},
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