网点费用申请子表单校验拦截

This commit is contained in:
wuteng 2025-10-15 15:53:04 +08:00
parent 5346431544
commit 0e6afb51fd
2 changed files with 46 additions and 18 deletions

View File

@ -2490,6 +2490,25 @@ export default {
} }
}); });
return true; return true;
},
// 暴露校验方法给父组件调用
validateForm(cb) {
this.$refs.form.validate((valid) => {
// 获取所有错误信息
const errors = this.getFormErrors()
cb(valid, errors) // 给父组件传递:校验结果 + 错误信息
})
},
getFormErrors() {
const form = this.$refs.form
if (!form) return []
// Element UI 的 fields 数组存储了所有字段的校验状态
return form.fields
.filter(field => field.validateMessage) // 筛选出有错误的字段
.map(field => ({
prop: field.prop, // 字段名(如 'name'、'age')
message: field.validateMessage // 错误提示信息
}))
} }
} }
}; };

View File

@ -259,18 +259,24 @@ export default {
}, },
/** 提交按钮 */ /** 提交按钮 */
submitForm() { submitForm() {
// 校验子表单
this.$refs["refAdjustDetail"].validateForm((valid, errors) => {
if (!valid) {
// this.$modal.msgError(errors[0].message);
return
} else {
this.$refs["form"].validate(valid => { this.$refs["form"].validate(valid => {
if (valid) { if (valid) {
let jsonData=this.$refs.refAdjustDetail.getJsonData(); let jsonData = this.$refs.refAdjustDetail.getJsonData();
console.log("====>jsonData==>",jsonData); console.log("====>jsonData==>", jsonData);
const params={ const params = {
"applyManCode":this.form.applyManCode, "applyManCode": this.form.applyManCode,
"applyMemo":this.form.applyMemo, "applyMemo": this.form.applyMemo,
"applySiteCode":this.form.applySiteCode, "applySiteCode": this.form.applySiteCode,
"applyType":this.form.applyType, "applyType": this.form.applyType,
"billCode":this.form.billCode, "billCode": this.form.billCode,
"destConfirmSiteCode":this.form.destConfirmSiteCode, "destConfirmSiteCode": this.form.destConfirmSiteCode,
"jsonData":JSON.stringify(jsonData), "jsonData": JSON.stringify(jsonData),
} }
addEmisWaybillAjustApply(params).then(response => { addEmisWaybillAjustApply(params).then(response => {
this.$modal.msgSuccess("申请成功"); this.$modal.msgSuccess("申请成功");
@ -278,6 +284,9 @@ export default {
}); });
} }
}); });
}
});
}, },
} }