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,9 +776,12 @@ export default { ...@@ -772,9 +776,12 @@ 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('请输入联系方式')));
} }
let areaCode = this.form.customerContacts.find(e => e.phoneNew === value).areaCode
if(areaCode){
validatorMobile({ validatorMobile({
code: this.form.customerContacts.find(e => e.phoneNew === value).areaCode, code: areaCode,
mobile: value mobile: value
}).then(r => { }).then(r => {
if (r.data){ if (r.data){
...@@ -786,6 +793,28 @@ export default { ...@@ -786,6 +793,28 @@ export default {
console.error(e) console.error(e)
callback(new Error(this.$t('手机号验证失败'))) 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){ 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