Sfoglia il codice sorgente

fix(accountstatement): 修复对账表单验证和字段处理问题

liujt 4 mesi fa
parent
commit
40b81fa461

+ 27 - 13
src/views/saleManage/saleOrder/accountstatement/components/addAccountDialog.vue

@@ -188,6 +188,17 @@
         data.amountTotalPrice = data.orderList.reduce((pre, cur) => pre + +cur.amountTotalPrice, 0);
         data.amountCompletePrice = data.orderList.reduce((pre, cur) => pre + +cur.statementAmount, 0);
         data.amountUnCompletePrice = data.orderList.reduce((pre, cur) => pre + +cur.unStatementAmount, 0);
+        data.orderList = data.orderList.map(item => {
+            item.deliveryProducts = item.deliveryProducts.map(i => {
+              return {
+                ...i,
+                taxRate: i.taxRate || 0,
+                discountRatio: i.discountRatio || 100,
+                singlePrice: i.singlePrice || 0,
+              }
+            })
+            return item;
+          })
         this.datasource = data.orderList || [];
         this.dataForm = data;
         switch (this.dataForm.dateType) {
@@ -221,6 +232,7 @@
       },
       //查询获取订单数据
       async handleSearch(params) {
+        console.log('this.$refs.inventoryTableRef~~~', this.$refs.inventoryTableref);
         let searchQuery = {
           endDate: params.endDate,
           sourceId: params.sourceId,
@@ -274,20 +286,20 @@
         if (!this.datasource.length)
           return this.$message.warning('暂无对账信息');
         
-        if (!this.getValidForm()){
-          return this.$message.warning('请完善对账信息');
-        }
-        let api =
-          this.dialogType == 'add'
-            ? createAccountStatementAPI
-            : accountstatementUpdateAPI;
-        let params = {
-          ...this.dataForm,
-          orderList: this.datasource,
-          // recorpayList: this.recorpayList
-        };
-        this.saveLoading = true;
         try {
+          // 校验 inventoryTableref 组件的表单
+          await this.$refs.inventoryTableref.getValidForm();
+          
+          let api =
+            this.dialogType == 'add'
+              ? createAccountStatementAPI
+              : accountstatementUpdateAPI;
+          let params = {
+            ...this.dataForm,
+            orderList: this.datasource,
+            // recorpayList: this.recorpayList
+          };
+          this.saveLoading = true;
           let data = await api(params);
           if (is == 'sub') {
             await this.submitApprove(data);
@@ -301,6 +313,8 @@
           this.reload();
           this.saveLoading = false;
         } catch (error) {
+          console.error('保存失败:', error);
+          // 错误提示已经在 getValidForm 方法中处理
           this.saveLoading = false;
         }
       },

+ 14 - 9
src/views/saleManage/saleOrder/accountstatement/components/inventoryTable.vue

@@ -117,7 +117,7 @@
                         v-model="scope.row.singlePrice"
                         placeholder="请输入"
                         @input="changeCount(scope.row, scope.$index)"
-                        :disabled="scope.row.orderCategory != 4"
+                        :disabled="item.orderCategory != 4"
                         type="number"
                       >
                         <template slot="append">元</template>
@@ -139,7 +139,7 @@
                         placeholder="请输入"
                         type="number"
                         @input="getNotaxSinglePrice(scope.row, scope.$index)"
-                        :disabled="scope.row.orderCategory != 4"
+                        :disabled="item.orderCategory != 4"
                       >
                         <template slot="append">%</template>
                       </el-input>
@@ -161,7 +161,7 @@
                         type="number"
                         :min="0"
                         :max="100"
-                        :disabled="scope.row.orderCategory != 4"
+                        :disabled="item.orderCategory != 4"
                         @input="getDiscountRatioPrice(scope.row, scope.$index)"
                       >
                         <template slot="append">%</template>
@@ -633,7 +633,7 @@ export default {
         console.log('changeCount~~~', item)
         console.log('this.datasource[index]~~~', this.datasource[index])
         // row.totalPrice = parseFloat((item.totalCount * item.singlePrice).toFixed(2))
-        if (item.singlePrice && item.taxRate) {
+        if (item.singlePrice && item.totalCount) {
           // this.$set(
           //   this.datasource[index],
           //   'totalPrice',
@@ -751,8 +751,13 @@ export default {
           validationPromises.push(
             new Promise((formResolve, formReject) => {
               const formRef = this.$refs['form' + index];
-              if (formRef) {
-                formRef.validate((valid, errors) => {
+              console.log(formRef, 'formRef');
+              
+              // 处理表单引用可能是数组的情况
+              const actualFormRef = Array.isArray(formRef) ? formRef[0] : formRef;
+              
+              if (actualFormRef && typeof actualFormRef.validate === 'function') {
+                actualFormRef.validate((valid, errors) => {
                   if (!valid) {
                     formReject({ index, errors });
                   } else {
@@ -760,9 +765,9 @@ export default {
                   }
                 });
               } else {
-                // 如果表单引用不存在,检查数据直接验证
+                // 如果表单引用不存在或没有validate方法,检查数据直接验证
                 if (!item.singlePrice || !item.taxRate || !item.discountRatio) {
-                  formReject({ index, message: `第${index + 1}项缺少必填字段` });
+                  formReject({ index, message: `缺少必填字段` });
                 } else {
                   formResolve(true);
                 }
@@ -780,7 +785,7 @@ export default {
             if (error.message) {
               this.$message.error(error.message);
             } else {
-              this.$message.error(`第${error.index + 1}项表单验证失败`);
+              this.$message.error(`表单未填写完整`);
             }
             reject(false);
           });