jiaxing.zhou

refactor(editReportingData): 优化新增商品的校验逻辑

- 注释掉了 addNewItem 方法中的校验逻辑,暂时允许无限制地添加新商品
- 重构了 RowDataEditForm 组件中的 validate 方法,使用 Promise 异步处理校验结果
- 在校验成功时,触发 rowFormDataSave事件,将表单数据保存- 优化了校验通过和未通过时的处理流程,提高了代码的可读性和可维护性
...@@ -367,15 +367,32 @@ ...@@ -367,15 +367,32 @@
367 this.tableRowformData = {} 367 this.tableRowformData = {}
368 this.$emit('cancelEditRowData',this.rowDatas.row.gnum-1) 368 this.$emit('cancelEditRowData',this.rowDatas.row.gnum-1)
369 }, 369 },
370 - validate() { 370 + // validate() {
371 - return this.$refs.editRowForm.validate((valid)=>{ 371 + // return this.$refs.editRowForm.validate((valid)=>{
372 - if(valid){ 372 + // if(valid){
373 - console.log("tg2") 373 + // console.log("tg2")
374 - this.$emit('updateLastItemValid', true); 374 + // this.$emit('updateLastItemValid', true);
375 - }else { 375 + // }else {
376 - console.log("wtg2") 376 + // console.log("wtg2")
377 - this.$emit('updateLastItemValid', false); // 通知父组件校验未通过 377 + // this.$emit('updateLastItemValid', false); // 通知父组件校验未通过
378 - } 378 + // }
379 + // });
380 + // },
381 + async validate() {
382 + return new Promise((resolve, reject) => {
383 + this.$refs.editRowForm.validate((valid) => {
384 + if (valid) {
385 + // console.log("tg2")
386 + this.$emit('rowFormDataSave', {gnum: this.rowDatas.row.gnum, tableRowformData: this.tableRowformData})
387 + this.tableRowformData = {}
388 + this.$emit('updateLastItemValid', true);
389 + resolve(true);
390 + } else {
391 + // console.log("wtg2")
392 + this.$emit('updateLastItemValid', false);
393 + resolve(false);
394 + }
395 + });
379 }); 396 });
380 }, 397 },
381 }, 398 },
......
...@@ -879,10 +879,12 @@ ...@@ -879,10 +879,12 @@
879 //添加新商品 879 //添加新商品
880 async addNewItem() { 880 async addNewItem() {
881 // 如果上一次新增的 item 没有通过校验,则不允许新增 881 // 如果上一次新增的 item 没有通过校验,则不允许新增
882 - if (!this.lastItemValid) { 882 + //console.log("this",this.lastItemValid)
883 - this.$message.warning('请先完善新增的商品信息'); 883 + // if (!this.lastItemValid) {
884 - return; 884 + // console.log(11)
885 - } 885 + // this.$message.warning('请先完善新增的商品信息');
886 + // return;
887 + // }
886 // 获取最后一个 item 的引用 888 // 获取最后一个 item 的引用
887 const lastItem = this.detailData[this.detailData.length - 1]; 889 const lastItem = this.detailData[this.detailData.length - 1];
888 // 如果存在上一次新增的 item,则进行校验 890 // 如果存在上一次新增的 item,则进行校验
...@@ -892,7 +894,10 @@ ...@@ -892,7 +894,10 @@
892 if (rowEditForm) { 894 if (rowEditForm) {
893 // 调用校验方法 895 // 调用校验方法
894 const isValid = await rowEditForm.validate(); 896 const isValid = await rowEditForm.validate();
897 + // console.log("y:",this.lastItemValid)
898 + // console.log("!",isValid)
895 if (!isValid) { 899 if (!isValid) {
900 + // console.log(22)
896 this.lastItemValid = false; // 标记上一次新增的 item 未通过校验 901 this.lastItemValid = false; // 标记上一次新增的 item 未通过校验
897 this.$message.warning('请先完善新增的商品信息'); 902 this.$message.warning('请先完善新增的商品信息');
898 return; 903 return;
......