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

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;
}
},
// 暴露校验方法给父组件调用
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>

View File

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