Просмотр исходного кода

fix(销售订单): 修复仓库变更时批次号未重置的问题

liujt 7 месяцев назад
Родитель
Сommit
5a9f6c430b
1 измененных файлов с 232 добавлено и 34 удалено
  1. 232 34
      src/views/saleManage/saleOrder/invoice/components/inventoryTable.vue

+ 232 - 34
src/views/saleManage/saleOrder/invoice/components/inventoryTable.vue

@@ -180,7 +180,7 @@
           <el-select
             v-model="scope.row.warehouseId"
             placeholder="请选择"
-            @change="warehouseChange(scope.$index, scope.row)"
+            @change="warehouseChange(scope.$index, scope.row, true)"
           >
             <el-option
               v-for="item in scope.row.warehouseList"
@@ -1115,7 +1115,7 @@
         this.selection = [];
       },
 
-      async warehouseChange(index, row) {
+      async warehouseChange(index, row, isReset = false) {
         const data = row.warehouseList.find(
           (item) => item.warehouseId == row.warehouseId
         );
@@ -1140,9 +1140,11 @@
           warehouseOutStock || 0
         );
 
-        this.$set(this.form.datasource[index], 'batchStockId', '');
-
-        this.$set(this.form.datasource[index], 'batchNo', '');
+        if(isReset) {
+          this.$set(this.form.datasource[index], 'batchStockId', '');
+          this.$set(this.form.datasource[index], 'batchNo', '');
+        }
+        
       },
 
       //批次号选择
@@ -1489,12 +1491,204 @@
         });
         this.form.datasource.forEach(async (item, index) => {
           if (indexS.includes(index)) {
+            if(!item.batchNo) {
+              console.log('111~~~~');
+              this.$set(
+                this.form.datasource[index],
+                'warehouseList',
+                await getIdWarehouseList({
+                  categoryId: item.productId
+                })
+              );
+              if (item.warehouseId) {
+                this.$set(
+                  this.form.datasource[index],
+                  'warehouseNum',
+                  await getWarehouseOutStock({
+                    warehouseId: item.warehouseId,
+                    code: item.productCode
+                  })
+                );
+              } else if (this.form.datasource[index]?.warehouseList?.length) {
+                this.$set(
+                  this.form.datasource[index],
+                  'warehouseId',
+                  this.form.datasource[index]?.warehouseList[0].warehouseId
+                );
+                await this.warehouseChange(index, this.form.datasource[index]);
+              }
+
+              const templist = await getBatchList({
+                categoryCode: item.productCode,
+                warehouseId: item.warehouseId,
+                size: -1
+              });
+
+              console.log('templist~~~~', templist.list);
+
+              // 批次号
+              this.$set(
+                this.form.datasource[index],
+                'batchNoList',
+                templist?.list || []
+              );
+              // console.log(this.form.datasource[index]);
+            } else {
+              this.setBatchAndWarehouse(item, index);
+            }
+            
+          }
+        });
+      },
+      async setBatchAndWarehouse(item, index) {
+        // 通过产品编号和批次号获取仓库列表
+        const warehouse = await getIdWarehouseList({
+          categoryId: item.productId,
+          batchNo: item.batchNo
+        })
+        // 如果有仓库列表
+        if (warehouse?.length) {
+          console.log('222~~~~', item.batchNo);
+          // 设置仓库列表
+          this.$set(
+            this.form.datasource[index],
+            'warehouseList',
+            warehouse
+          );
+          // 如果有仓库ID
+          if (item.warehouseId) {
+            // console.log('444~~~~');
+            // const templist = await getBatchList({
+            //   categoryCode: item.productCode,
+            //   warehouseId: item.warehouseId,
+            //   size: -1
+            // });
+            // const batchNoList = templist?.list || [];
+            // // 批次号
+            // this.$set(
+            //   this.form.datasource[index],
+            //   'batchNoList',
+            //   batchNoList
+            // );
+            // const batchNo = batchNoList.find(i => i.batchNo === item.batchNo);
+            // if (batchNo) {
+            //   this.$set(
+            //     this.form.datasource[index],
+            //     'batchStockId',
+            //     batchNo.id
+            //   );
+            //   this.$set(
+            //     this.form.datasource[index],
+            //     'warehouseNum',
+            //     data.measureQuantity || 0
+            //   );
+            // }
+
+          } 
+          // 没有仓库ID,设置第一个仓库ID
+          else {
+             if (this.form.datasource[index]?.warehouseList?.length){
+              console.log('555~~~~');
+              this.$set(
+                this.form.datasource[index],
+                'warehouseId',
+                this.form.datasource[index]?.warehouseList[0].warehouseId
+              );
+
+              // await this.warehouseChange(index, this.form.datasource[index]);
+             }
+          }
+
+          // const wdata = warehouse.find(
+          //   (i) => i.warehouseId == row.warehouseId
+          // );
+
+          // this.$set(
+          //   this.form.datasource[index],
+          //   'warehouseName',
+          //   wdata.warehouseName
+          // );
+          // this.$set(
+          //   this.form.datasource[index],
+          //   'warehouseCode',
+          //   wdata.warehouseCode
+          // );
+          // const warehouseOutStock = await getWarehouseOutStock({
+          //   warehouseId: wdata.warehouseId,
+          //   code: row.productCode
+          // });
+          // this.$set(
+          //   this.form.datasource[index],
+          //   'warehouseNum',
+          //   warehouseOutStock || 0
+          // );
+          
+          console.log('444~~~~');
+          // 通过仓库ID获取批次号列表
+          const templist = await getBatchList({
+            categoryCode: item.productCode,
+            warehouseId: item.warehouseId,
+            size: -1
+          });
+          let batchNoList = templist?.list || [];
+          console.log('batchNoList~~~~', batchNoList);
+          // 设置批次列表
+          this.$set(
+            this.form.datasource[index],
+            'batchNoList',
+            batchNoList
+          );
+          // 查找批次号是否存在批次列表
+          const batchNo = batchNoList.find(i => i.batchNo == item.batchNo);
+          console.log('batchNo~~~~', batchNo);
+          // 存在
+          if (batchNo) {
+            // 设置批次ID
+            this.$set(
+              this.form.datasource[index],
+              'batchStockId',
+              batchNo.id
+            );
+            // 设置批次库存
+            this.$set(
+              this.form.datasource[index],
+              'warehouseNum',
+              batchNo.measureQuantity || 0
+            );
+          } else { //不存在
+            // 批次列表添加不存在的批次号对象
+            batchNoList = batchNoList.push({
+              batchNo: item.batchNo,
+              id: 999,
+              measureQuantity: 0
+            })
+            // 设置为不存在的批次ID
+            this.$set(
+              this.form.datasource[index],
+              'batchStockId',
+              999
+            );
+            this.$set(
+              this.form.datasource[index],
+              'warehouseNum',
+              ''
+            );
+          }
+        } 
+        // 如果没有仓库列表
+        else {
+          console.log('333~~~~');
+          // 通过产品编码查仓库
+          const tempWarehouse = await getIdWarehouseList({
+            categoryId: item.productId,
+          })
+          // 有仓库列表
+          if (tempWarehouse?.length) {
+            console.log('666~~~~');
             this.$set(
               this.form.datasource[index],
               'warehouseList',
-              await getIdWarehouseList({
-                categoryId: item.productId
-              })
+              tempWarehouse
             );
             if (item.warehouseId) {
               this.$set(
@@ -1505,46 +1699,50 @@
                   code: item.productCode
                 })
               );
-            } else if (this.form.datasource[index]?.warehouseList?.length) {
-              this.$set(
-                this.form.datasource[index],
-                'warehouseId',
-                this.form.datasource[index]?.warehouseList[0].warehouseId
-              );
-              await this.warehouseChange(index, this.form.datasource[index]);
+            } else {
+              if (this.form.datasource[index]?.warehouseList?.length) {
+                this.$set(
+                  this.form.datasource[index],
+                  'warehouseId',
+                  this.form.datasource[index]?.warehouseList[0].warehouseId
+                );
+                await this.warehouseChange(index, this.form.datasource[index]);
+              }
+              
             }
 
-            const templist = await getBatchList({
+            const templist1 = await getBatchList({
               categoryCode: item.productCode,
               warehouseId: item.warehouseId,
               size: -1
             });
 
-            console.log('templist~~~~', templist.list);
-
+            let tempBatchNoList = templist1?.list || [];
+            tempBatchNoList = tempBatchNoList.push({
+              batchNo: item.batchNo,
+              id: 999,
+              measureQuantity: 0
+            })
             // 批次号
             this.$set(
               this.form.datasource[index],
               'batchNoList',
-              templist?.list || []
+              tempBatchNoList
+            );
+            this.$set(
+              this.form.datasource[index],
+              'batchStockId',
+              999
+            );
+            this.$set(
+              this.form.datasource[index],
+              'warehouseNum',
+              ''
             );
-            console.log(this.form.datasource[index]);
-            if (item.batchStockId) {
-              // this.$set(
-              //   this.form.datasource[index],
-              //   'warehouseNum',
-              //   await getWarehouseOutStock({
-              //     warehouseId: item.warehouseId,
-              //     code: item.productCode
-              //   })
-              // );
-
-              await this.batchNoChange(index, this.form.datasource[index]);
-            }
           }
-        });
+        }
+        
       },
-
       remove(i) {
         this.form.datasource.splice(i, 1);
         this.setSort();