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

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,7 +2490,26 @@ 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 // 错误提示信息
}))
}
} }
}; };
</script> </script>

View File

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