diff --git a/src/components/Template/StepComponents/ZLSubPackage.vue b/src/components/Template/StepComponents/ZLSubPackage.vue index a553d27..78c6d8a 100644 --- a/src/components/Template/StepComponents/ZLSubPackage.vue +++ b/src/components/Template/StepComponents/ZLSubPackage.vue @@ -285,6 +285,9 @@ export default { } }); + // 清空之前的分装列表错误状态,重新验证 + this.fzListErrors = []; + // 验证分装列表中的数值 - 根据字段的fillType和当前templateFillType比较 if (this.fzList && this.fzList.length > 0) { for (let i = 0; i < this.fzList.length; i++) { @@ -299,7 +302,7 @@ export default { isValid = false; } } - + // 验证实际分装数量 if (this.inputNumberItem.fillType === this.templateFillType) { if (isValueEmpty(this.fzList[i].actnum)) { @@ -322,9 +325,7 @@ export default { }); // 重置分装列表错误状态 - this.fzListErrors.forEach((_, index) => { - this.fzListErrors = [] - }); + this.fzListErrors = []; }, // 分装数量失去焦点时,根据数量生成分装列表 async onBlurFzsl(e) { @@ -361,91 +362,46 @@ export default { }, onBlurFzNum(index, field) { if (this.fzList[index]) { - // 确保fzListErrors数组有足够的元素 - if (this.fzListErrors.length <= index) { - this.$set(this.fzListErrors, index, false); - } - if (this.fzList[index][field]) { - // 有值的话就清空对应的错误信息 - this.$set(this.fzListErrors, index, false); + // 有值的话就移除对应的错误信息 + this.removeFzListError(index, field); } else { - // 没有值的话就边框标红 - this.$set(this.fzListErrors, index, true); + // 没有值的话就添加错误信息,边框标红 + this.addFzListError(index, field); } } }, - verifyFzListError(index, field) { - // 如果index和field都为空,就全匹配 - if (index === undefined && field === undefined) { - if (this.fzList && this.fzList.length > 0) { - // 清空现有错误信息 - this.fzListErrors = []; - - // 遍历fzList,没有值的就放到fzListErrors里面 - for (let i = 0; i < this.fzList.length; i++) { - const item = this.fzList[i]; - if (isValueEmpty(item.prenum)) { - this.fzListErrors.push({ - rowIndex: i, - field: "prenum", - error: "请输入预填分装数量" - }); - } - if (isValueEmpty(item.actnum)) { - this.fzListErrors.push({ - rowIndex: i, - field: "actnum", - error: "请输入实际分装数量" - }); - } - } - } - } else if (index !== undefined) { - // 如果index不为空,检查指定索引的项 - if (this.fzList[index]) { - const item = this.fzList[index]; - - if (field === undefined) { - // 如果field为空,检查prenum和actnum - // 先移除该索引的所有错误信息 - this.fzListErrors = this.fzListErrors.filter(err => err.rowIndex !== index); - - // 没有值的就放到fzListErrors里面 - if (isValueEmpty(item.prenum)) { - this.fzListErrors.push({ - rowIndex: index, - field: "prenum", - error: "请输入预填分装数量" - }); - } - if (isValueEmpty(item.actnum)) { - this.fzListErrors.push({ - rowIndex: index, - field: "actnum", - error: "请输入实际分装数量" - }); - } - } else { - // 如果field不为空,检查指定字段 - // 先移除该索引和字段的错误信息 - this.fzListErrors = this.fzListErrors.filter(err => !(err.rowIndex === index && err.field === field)); - - // 没有值的就放到fzListErrors里面 - if (isValueEmpty(item[field])) { - this.fzListErrors.push({ - rowIndex: index, - field: field, - error: field === "prenum" ? "请输入预填分装数量" : "请输入实际分装数量" - }); - } - } - } + + // 添加分装列表错误信息 + addFzListError(index, field) { + const errorObj = { + rowIndex: index, + field: field, + error: field === 'prenum' ? '请输入预填分装数量' : '请输入实际分装数量' + }; + // 检查是否已经存在相同的错误 + const exists = this.fzListErrors.some(item => + item.rowIndex === index && item.field === field + ); + if (!exists) { + this.fzListErrors.push(errorObj); } }, + + // 移除分装列表错误信息 + removeFzListError(index, field) { + this.fzListErrors = this.fzListErrors.filter(item => + !(item.rowIndex === index && item.field === field) + ); + }, hasError(index, field) { const o = this.fzListErrors.find((item)=>{ + // 检查 item 是否存在且为对象类型 + if (!item || typeof item !== 'object') { + return false; // 忽略布尔值、null、undefined等无效值 + } + // 只有对象类型的 item 才进行匹配 return item.rowIndex === index && item.field === field; }) return o !== undefined; diff --git a/src/components/Template/StepComponents/ry/zlfz.vue b/src/components/Template/StepComponents/ry/zlfz.vue index f478ca1..bc9bb68 100644 --- a/src/components/Template/StepComponents/ry/zlfz.vue +++ b/src/components/Template/StepComponents/ry/zlfz.vue @@ -63,7 +63,16 @@ export default { const {key} = data; if(key === 'zlfz'){ const formData = await this.$refs.stepFormPackageRef.getFormData(); - console.log(formData,"formData") + if(formData){ + const {zlfz} = formData; + const fzInfo = { + ...zlfz.formData, + fzList:zlfz.fzList, + }; + this.$refs.stepFormPackageRef.updateFormData("fzInfo",fzInfo); + this.$message.success("质量分装成功"); + this.justUpdateFilledFormData(); + } } }