yijing пре 1 година
родитељ
комит
99544df23d
1 измењених фајлова са 127 додато и 388 уклоњено
  1. 127 388
      src/views/warehouseManagement/stockManagement/add.vue

+ 127 - 388
src/views/warehouseManagement/stockManagement/add.vue

@@ -795,7 +795,7 @@ export default {
     },
     // 计算最小单元数量
     async computeNum(row, index, isClear) {
-      console.log('row, index', row, index);
+      console.log('row,', row);
 
       // 清空仓库(包装数量输入)
       if (isClear) {
@@ -833,8 +833,8 @@ export default {
           this.$set(this.productList[index], 'warehouseName', '');
         }
         // -----------------------------------------------------------------
-        let startIndex = row.packingSpecificationOption.findIndex((ite) => {
 
+        let startIndex = row.packingSpecificationOption.findIndex((ite) => {
           return (
             row.measuringUnit == ite.packingUnit &&
             ite.packingUnit != ite.conversionUnit
@@ -843,70 +843,29 @@ export default {
         let endIndex = row.packingSpecificationOption.findIndex(
           (ite) => row.packingUnit == ite.conversionUnit
         );
-
-        console.log(row, 'rowwwwwwwwwwwwww')
-
-
+        console.log(endIndex);
         let total = Number(row.packingQuantity);
-        //计量数量
-        row.measureQuantity = this.changeCount(total);
-        console.log(total, '包装数量')
 
-        if (row.packingUnit == row.measureUnit) {
-          // total = Number(row.packingQuantity) * row.netWeight;
-          console.log(total, '22')
-        } else {
-          let num = 0;
-          for (; startIndex < endIndex; endIndex--) {
-            // total = 
-            num = this.$math.format(
-              row.packingSpecificationOption[endIndex].packageCell * total,
-              14
-            );
-          }
-          console.log(num, 'numnumnum')
-          total = Number(num);
-          console.log(total, '333')
+        for (; startIndex < endIndex; endIndex--) {
+          total = this.$math.format(
+            row.packingSpecificationOption[endIndex].packageCell * total,
+            14
+          );
         }
+        //计量数量
+        row.measureQuantity = this.changeCount(total);
 
-        // 判断单位和计量单位是否为不拆物料层规格
-        let packingBoolen = !!this.getDict('不拆物料层规格', row.packingUnit)
-          .dictValue;
-        let measureBoolen = !!this.getDict('不拆物料层规格', row.measureUnit)
-          .dictValue;
-        console.log(packingBoolen, 'packingBoolen')
-        console.log(measureBoolen, 'measureBoolen')
+        console.log(row.measureQuantity, '计量数量')
+        console.log(total, '包装数量')
 
-        if (packingBoolen && measureBoolen && row.packingUnit != 'L') {
+        // --------------------------------------------------------------------
+        //计量单位不是数量时,配置了单重的重量计算
 
-          console.log(total, '55555')
-          this.$set(this.productList[index], 'weight', total);
-          if (row.packingUnit == row.measureUnit) {
-            this.$set(this.productList[index], 'measureQuantity', row.packingQuantity)
-          }
-        } else {
-          console.log(row, 'row')
-          if (row.measureType != 1) {
-            if (row.packingUnit == 'KG') {
-              if (row.packingUnit == row.measureUnit) {
-                this.$set(this.productList[index], 'weight', row.measureQuantity)
-              } else {
-                const weight = total * Number(row.singleWeight);
-                this.$set(this.productList[index], 'weight', weight)
-              }
-              console.log(total, '66')
-            } else {
-              const weight = row.measureQuantity * Number(row.singleWeight);
-              this.$set(this.productList[index], 'weight', weight)
-              console.log(total, '77')
-            }
-          } else {
-            const weight = total * Number(row.singleWeight);
-            this.$set(this.productList[index], 'weight', weight)
-            console.log(total, '8')
-          }
+        if (row.measureType != 1 && row.singleWeight) {
+          //计量数量*单重
+          const weight = row.measureQuantity * Number(row.singleWeight);
+          this.$set(this.productList[index], 'weight', weight)
         }
-        this.$set(this.productList[index], 'measureQuantity', total)
       }
     },
     //出入库申请列表操作直接入库
@@ -1738,7 +1697,6 @@ export default {
     //计算金额
     calcSumTotal(measureQuantity, unitPrice, row) {
       //最小包装单元,包装数量,单价
-      console.log(measureQuantity, unitPrice, ';;;;;;;;;;')
       const total = {
         measureQuantity: Number(measureQuantity > 0 ? measureQuantity : 0),
         unitPrice: Number(unitPrice > 0 ? unitPrice : 0)
@@ -1748,7 +1706,6 @@ export default {
       );
 
       row.totalMoney = number;
-      console.log(number, 'number')
       return number;
     },
 
@@ -1981,140 +1938,6 @@ export default {
           });
       });
     },
-    // 产品批量保存
-    // async listSaveArrs() {
-    //   this.validateForm()
-    //     .then(async () => {
-    //       // 批量获取包装编码并处理
-    //       let packingCodePrams = this.productList.map((row) => {
-    //         // 判断单位和计量单位是否为不拆物料层规格
-    //         let packingBoolen = !!this.getDict(
-    //           '不拆物料层规格',
-    //           row.packingUnit
-    //         ).dictValue;
-    //         let measureBoolen = !!this.getDict(
-    //           '不拆物料层规格',
-    //           row.measureUnit
-    //         ).dictValue;
-    //         let num = 0;
-    //         if (packingBoolen) {
-    //           let filterArr = row.packingSpecificationOption.filter(
-    //             (item) => {
-    //               return (
-    //                 item.packageUnit == row.packingUnit &&
-    //                 item.packageUnit != item.conversionUnit
-    //               );
-    //             }
-    //           );
-    //           num = Math.ceil(row.packingQuantity / filterArr[0].packageCell);
-    //         }
-    //         if (row.isSave) {
-    //           return {};
-    //         } else {
-    //           console.log(packingBoolen, 'packingBoolen怕怕怕怕怕怕怕')
-    //           // 处理单位为KG类的情况
-    //           if (packingBoolen) {
-    //             return {
-    //               assetCode: row.categoryCode + row.index,
-    //               batchNum: row.batchNo,
-    //               num
-    //             };
-    //           } else {
-    //             if (row.isUnpack) {
-    //               if (measureBoolen) {
-    //                 // 处理单位不为KG类,计量单位为KG类的情况
-    //                 let num = row.packingQuantity;
-    //                 let splitIndex = row.packingSpecificationOption.findIndex(
-    //                   (item) =>
-    //                     item.conversionUnit == row.packingUnit &&
-    //                     item.packageUnit != item.conversionUnit
-    //                 );
-    //                 for (; splitIndex > 1; splitIndex--) {
-    //                   num = this.$math.format(
-    //                     num *
-    //                     row.packingSpecificationOption[splitIndex]
-    //                       .packageCell,
-    //                     14
-    //                   );
-    //                 }
-    //                 return {
-    //                   assetCode: row.categoryCode + row.index,
-    //                   batchNum: row.batchNo,
-    //                   num
-    //                 };
-    //               } else {
-    //                 console.log('拆包情况------:', row.measureQuantity, row.packingSpecificationOption[1]?.packageCell);
-
-    //                 // 处理拆包到最小包装单元数量的情况
-    //                 let num = Math.ceil(
-    //                   row.measureQuantity / row.packingSpecificationOption[1]?.packageCell
-    //                 );
-    //                 return {
-    //                   assetCode: row.categoryCode + row.index,
-    //                   batchNum: row.batchNo,
-    //                   num: num
-    //                 };
-    //               }
-    //             } else {
-    //               return {
-    //                 assetCode: row.categoryCode + row.index,
-    //                 batchNum: row.batchNo,
-    //                 num: row.packingQuantity
-    //               };
-    //             }
-    //           }
-    //         }
-    //       });
-    //       let filterPackingCodePrams = packingCodePrams.filter(
-    //         (item) => item.assetCode
-    //       );
-    //       let { data } = await storageApi.getAssetNum(filterPackingCodePrams);
-    //       console.log('data-----11111111111111111---', data);
-    //       let packingCodeList = [];
-    //       packingCodePrams.forEach((item, index) => {
-    //         packingCodeList[index] = data.filter(
-    //           (ite) => ite.assetCode == item.assetCode
-    //         );
-    //       });
-    //       // 批量生成包装
-    //       this.productList.map((row, index) => {
-    //         if (!row.isSave) {
-    //           this.generateWrappers(row, index, packingCodeList[index]);
-    //           this.$set(this.productList[index], 'isSave', true);
-    //           console.log('this.productList[index]----', this.productList[index]);
-    //           console.log('row----', row);
-
-    //           this.$set(
-    //             this.productList[index],
-    //             'warehouseId',
-    //             row.warehouseId
-    //           );
-    //           this.$set(
-    //             this.productList[index],
-    //             'warehouseName',
-    //             row.warehouseName
-    //           );
-
-    //           this.$set(
-    //             this.productList[index],
-    //             'warehouseIds',
-    //             [row.warehouseId]
-    //           );
-    //           this.$set(
-    //             this.productList[index],
-    //             'warehouseNames',
-    //             [row.warehouseName]
-    //           );
-    //         }
-    //       });
-    //       // 加载虚拟列表数据(分页)
-    //       // this.pickingFetchData();
-    //       // this.materielFetchData();
-    //     })
-    //     .catch((err) => {
-    //       console.log(err);
-    //     });
-    // },
     // 物品保存验证表单(单独)
     validateFormIndividually(index) {
       return new Promise(async (resolve) => {
@@ -2210,69 +2033,28 @@ export default {
         try {
           await this.validateFormIndividually(index)
 
-          // 判断单位和计量单位是否为不拆物料层规格
-          let packingBoolen = !!this.getDict('不拆物料层规格', row.packingUnit)
-            .dictValue;
-          let measureBoolen = !!this.getDict('不拆物料层规格', row.measureUnit)
-            .dictValue;
-          console.log('packingBoolen---------', packingBoolen);
-          console.log('measureBoolen---------', measureBoolen);
-          let packingNum = 0;
-
-          // 处理单位为KG类的情况
-          if (packingBoolen) {
-
-            if (!row.isUnpack && row.packingUnit == '立方') {
-              packingNum = 1;
-            } else {
-              let filterArr = row.packingSpecificationOption.filter((item) => {
-                return (
-                  item.packageUnit == row.packingUnit &&
-                  item.packageUnit != item.conversionUnit
-                );
-              });
-              packingNum = Math.ceil(
-                row.packingQuantity / filterArr[0].packageCell
-              );
-            }
-          }
-          // 处理单位不为KG类,计量单位为KG类的情况
-          let measureNum = row.packingQuantity;
-          let num = 0;
-
-          if (measureBoolen) {
-            let splitIndex = row.packingSpecificationOption.findIndex(
-              (item) =>
-                item.conversionUnit == row.packingUnit &&
-                item.packageUnit != item.conversionUnit
-            );
-            for (; splitIndex > 1; splitIndex--) {
-              measureNum = this.$math.format(
-                measureNum *
-                row.packingSpecificationOption[splitIndex].packageCell,
-                14
-              );
-            }
-          } else {
-            if (row.packingSpecificationOption[1]?.packageCell) {
-              num = Math.ceil(
-                row.measureQuantity / row.packingSpecificationOption[1]?.packageCell
-              );
-            } else {
-              num = row.packingQuantity;
-            }
-
-          }
-          console.log(packingNum, measureNum, num, '加油加油加油')
-
           if (row.packingSpecificationLabel?.length < 1) {
             this.$message.error('请到主数据维护包装组信息!')
             return;
           }
+
           // 不拆包
           if (!row.isUnpack) {
             if (row.packingUnit != row.measureUnit) {
               let pNum = row.packingQuantity;
+              let splitIndex = row.packingSpecificationOption.findIndex(
+                (item) =>
+                  item.conversionUnit == row.packingUnit &&
+                  item.packageUnit != item.conversionUnit
+              );
+              for (; splitIndex > 1; splitIndex--) {
+                pNum = this.$math.format(
+                  pNum *
+                  row.packingSpecificationOption[splitIndex].packageCell,
+                  14
+                );
+              }
+              console.log(pNum, 'pNum12')
               const { data } = await storageApi.getAssetNum([
                 {
                   assetCode: row.categoryCode + row.index,
@@ -2292,31 +2074,23 @@ export default {
               ]);
             }
           } else {
+            let pNum = row.packingQuantity;
             //拆包
             const { data } = await storageApi.getAssetNum([
               {
                 assetCode: row.categoryCode + row.index,
                 batchNum: row.batchNo,
-                num: packingBoolen ? packingNum : measureBoolen ? measureNum : num,
+                num: pNum,
               }
             ]);
 
             this.generateWrappers(row, index, data);
           }
-          this.$set(this.productList[index], 'isSave', true)
+          this.$set(this.productList[index], 'isSave', true);
           this.$set(this.productList[index], 'warehouseId', row.warehouseId);
-          this.$set(
-            this.productList[index],
-            'warehouseName',
-            row.warehouseName
-          );
-
-          this.$set(this.productList[index], 'warehouseIds', row.warehouseId);
-          this.$set(
-            this.productList[index],
-            'warehouseNames',
-            row.warehouseName
-          );
+          this.$set(this.productList[index], 'warehouseName', row.warehouseName);
+          this.$set(this.productList[index], 'warehouseIds', [row.warehouseId]);
+          this.$set(this.productList[index], 'warehouseNames', [row.warehouseName]);
 
           resolve()
         } catch (error) {
@@ -2410,10 +2184,33 @@ export default {
       console.log('num-----------', num);
 
       if (!row.isUnpack) {
-        let packingUnit = !row.isUnpack ? row.packingUnit : row.packingSpecificationOption[1].conversionUnit;
-        let packingQuantity = row.packingQuantity / packingCodeList.length;
+        console.log(row.packingSpecificationOption[1])
+        // let packingUnit = !row.isUnpack ? row.packingUnit : row.packingSpecificationOption[1].conversionUnit;
+        // let packingQuantity = row.packingQuantity / packingCodeList.length;
+
+        let packingUnit = row.packingSpecificationOption[1]?.conversionUnit;
+        let startIndex = row.packingSpecificationOption.findIndex((ite) => {
+          return (
+            row.measuringUnit == ite.packingUnit &&
+            ite.packingUnit != ite.conversionUnit
+          );
+        });
+        let endIndex = row.packingSpecificationOption.findIndex(
+          (ite) => row.packingUnit == ite.conversionUnit
+        );
+        let total = Number(row.packingQuantity);
+        for (; startIndex < endIndex; endIndex--) {
+          total = this.$math.format(
+            row.packingSpecificationOption[endIndex].packageCell * total,
+            14
+          );
+        }
+        console.log('total-----------', total)
+        let packingQuantity = row.measureQuantity / total;
+
         let measureUnit = row.measureUnit;
-        let measureQuantity = row.measureQuantity / row.packingQuantity;
+
+        let measureQuantity = row.measureQuantity / packingCodeList.length;
 
         for (let index = 0; index < packingCodeList.length; index++) {
           let item = {
@@ -2430,7 +2227,7 @@ export default {
             batchNo: row.batchNo, // 批次号
             packageNo: packingCodeList[index]?.onlyCode, // 包装编码
             packingQuantity: packingQuantity, // 包装数量
-            packingUnit: packingUnit,
+            packingUnit: packingUnit,//包装单位
             measureQuantity: measureQuantity, // 计量数量
             measureUnit: measureUnit, // 计量单位
             weight: 0, // 重量
@@ -2611,10 +2408,6 @@ export default {
             result: 1, // 结果(1合格 2不合格)
             status: 2 // 状态(0=未质检 1待检 2已检)
           };
-          /**
-           * packingUnit: row.isUnpack ? packingBoolen ? filterArr[0].conversionUnit : measureBoolen  ? row.packingSpecificationOption[2] ? row.packingSpecificationOption[2].conversionUnit
-           *                     : row.packingSpecificationOption[1].conversionUnit: row.measureUnit: packingBoolen ? filterArr[0].conversionUnit : row.packingUnit,
-           */
           if (row.isUnpack) {
             // 第二层条件: packingBoolen
             if (packingBoolen) {
@@ -2732,6 +2525,9 @@ export default {
     // 打开仓库弹框
     handleWareHouse(row, idx, type) {
       console.log(row, 'row')
+      console.log(idx, 'idx')
+      console.log(type, 'type')
+
       if (row.packingSpecificationLabel?.length < 1) {
         this.$message.error('请到主数据维护包装组信息!')
         return;
@@ -2739,18 +2535,11 @@ export default {
       if (row.isSave) {
         return false;
       }
-      let packingBoolen = !!this.getDict('不拆物料层规格', row.packingUnit)
-        .dictValue;
-      let measureBoolen = !!this.getDict('不拆物料层规格', row.measureUnit)
-        .dictValue;
-      console.log(packingBoolen, 'packingBoolen')
-      console.log(measureBoolen, 'measureBoolen')
-      //行内选择仓库
+      //单个
       if (idx > -1 && type != 'batch') {
-
         if (row.packingQuantity > 0) {
-          //不拆
           if (!row.isUnpack) {
+            console.log('不拆')
             //计量和包装单位相同
             if (row.measureUnit == row.packingUnit) {
               let pNum = 0;
@@ -2764,45 +2553,11 @@ export default {
                 row.categoryLevelPathIdParent
               );
             } else {
-              let pNum = Math.ceil(row.packingQuantity)
-;
-              let mNum = row.measureQuantity
-              this.$refs.wareHouseDailogRef.open(
-                pNum,
-                mNum,
-                idx,
-                row.warehouseId,
-                row.warehouseName + '',
-                row.categoryLevelPathIdParent
-              );
-            }
-          } else {
-
-            if (packingBoolen) {
-              console.log(packingBoolen, 'packingBoolen', row.packageUnit, row.isUnpack);
-
-              let filterArr = row.packingSpecificationOption.filter((item) => {
-                return (
-                  item.packageUnit == row.packingUnit &&
-                  item.packageUnit != item.conversionUnit
-                );
-              });
-
-              let num = Math.ceil(
-                row.packingQuantity / filterArr[0].packageCell
-              );
-              this.$refs.wareHouseDailogRef.open(
-                num,
-                row.measureQuantity,
-                idx,
-                row.warehouseId,
-                row.warehouseName + '',
-                row.categoryLevelPathIdParent
-              );
-            } else {
-              console.log(measureBoolen, 'measureBoolen');
-              let num = row.packingQuantity;
-              if (measureBoolen) {
+              if (row.packingSpecificationOption[1]?.packageCell) {
+                // let num = Math.ceil(
+                //   row.measureQuantity / row.packingSpecificationOption[1]?.packageCell
+                // );
+                let num = row.packingQuantity;
                 let splitIndex = row.packingSpecificationOption.findIndex(
                   (item) =>
                     item.conversionUnit == row.packingUnit &&
@@ -2821,50 +2576,38 @@ export default {
                   idx,
                   row.warehouseId,
                   row.warehouseName + '',
-                  row.categoryLevelPathIdParent
-                );
+                  row.categoryLevelPathIdParent);
               } else {
-                console.log(row.measureType, 'row.measureType')
-                console.log(row.measureUnit, 'row.measureUnit')
-                console.log(row.packingUnit, 'row.packingUnit')
-                if (row.measureType != 1 && row.measureUnit == row.packingUnit) {
-                  let pNum = 0;
-                  let mNum = row.measureQuantity
-                  this.$refs.wareHouseDailogRef.open(
-                    pNum,
-                    mNum,
-                    idx,
-                    row.warehouseId,
-                    row.warehouseName + '',
-                    row.categoryLevelPathIdParent
-                  );
-                } else {
-                  console.log(row.packingSpecificationOption[1]?.packageCell, 'row.packingSpecificationOption[1]?.packageCell')
-                  if (row.packingSpecificationOption[1]?.packageCell) {
-                    let num = Math.ceil(
-                      row.measureQuantity / row.packingSpecificationOption[1]?.packageCell
-                    );
-                    console.log(num, 'num')
-                    this.$refs.wareHouseDailogRef.open(
-                      num,
-                      row.measureQuantity,
-                      idx,
-                      row.warehouseId,
-                      row.warehouseName + '',
-                      row.categoryLevelPathIdParent);
-                  } else {
-                    console.log(num, 'numnumnumnum')
-                    this.$refs.wareHouseDailogRef.open(
-                      num,
-                      row.measureQuantity,
-                      idx,
-                      row.warehouseId,
-                      row.warehouseName + '',
-                      row.categoryLevelPathIdParent);
-                  }
-                }
+                this.$refs.wareHouseDailogRef.open(
+                  num,
+                  row.measureQuantity,
+                  idx,
+                  row.warehouseId,
+                  row.warehouseName + '',
+                  row.categoryLevelPathIdParent);
               }
             }
+          } else {
+            console.log('拆')
+            let filterArr = row.packingSpecificationOption.filter((item) => {
+              return (
+                item.packageUnit == row.packingUnit &&
+                item.packageUnit != item.conversionUnit
+              );
+            });
+
+            let num = Math.ceil(
+              row.measureQuantity / row.packingSpecificationOption[1]?.packageCell
+            );
+            console.log(num, 'num')
+            this.$refs.wareHouseDailogRef.open(
+              num,
+              row.measureQuantity,
+              idx,
+              row.warehouseId,
+              row.warehouseName + '',
+              row.categoryLevelPathIdParent
+            );
           }
         } else {
           this.$message.error('请先填写包装数量!');
@@ -2874,50 +2617,46 @@ export default {
         console.log(row, `row`)
         console.log(idx, `idx`)
         console.log(type, 'type')
-        // 批量设置
+
+        // 验证所有选中行是否填写了包装数量
         if (row.some(item => !item.packingQuantity)) {
           this.$message.error('请先填写所有行的包装数量!');
           return;
         }
 
-        for (let i = 0; i < row.length; i++) {
-          //测量单位等于包装单位
-          if (row[i].measureType != 1 && row[i].measureUnit === row[i].packingUnit) {
-            row[i].packingQuantity2 = 0;
-            console.log(row[i].packingQuantity2)
-          } else {
-            row[i].packingQuantity2 = Math.ceil(
-              row[i].measureQuantity / row[i].packingSpecificationOption[1]?.packageCell
-            );
-            console.log(row[i].packingQuantity2, '单位不一样')
-          }
-        }
-        console.log(row, 'rowrowrowrowrowrow我看看')
-
-
-        const pNum = row.reduce((sum, item) => {
-          if (item.packingQuantity2 !== undefined && item.packingQuantity2 !== null) {
-            return sum + Number(item.packingQuantity2);
-          }
-          return sum;
+        // 计算总需求数量
+        let totalPacking = row.reduce((sum, item) => {
+          return sum + Number(this.calculateRequiredWarehouseNum(item));
         }, 0);
-
         const mNum = row.reduce((sum, item) => {
           if (item.measureQuantity !== undefined && item.measureQuantity !== null) {
             return sum + Number(item.measureQuantity);
           }
           return sum;
         }, 0);
-        console.log(pNum, 'pppp')
-        console.log(mNum, 'mmmmm')
+        // 打开仓库选择弹窗
         this.$refs.wareHouseDailogRef.open(
-          pNum,
+          totalPacking,
           mNum
         );
       }
     },
+    calculateRequiredWarehouseNum(row) {
+      if (!row.isUnpack && row.measureUnit !== row.packingUnit) {
+        let splitIndex = row.packingSpecificationOption.findIndex(
+          item => item.conversionUnit === row.packingUnit
+        );
+        let num = row.packingQuantity;
+        for (; splitIndex > 1; splitIndex--) {
+          num = Math.ceil(num * row.packingSpecificationOption[splitIndex].packageCell);
+        }
+        return num;
+      }
+      console.log(row.packingQuantity, 'row.calculateRequiredWarehouseNum')
+      return row.packingQuantity;
+    },
     wareHouseSelection(argum, idx) {
-      console.log(argum, 'argumargumargumargumargumargum');
+      console.log(argum, 'argumargumargumargumargumargum', idx);
       // 方便包装遍历获取仓库id和名称
       let warehouseIds = [];
       let warehouseNames = [];
@@ -2929,7 +2668,7 @@ export default {
         }
       });
 
-      console.log(idx, this.productList, 'idxidxidxidx')
+      console.log(idx, 'idxidxidxidx', this.productList, 'this.productList')
 
       if (idx > -1) {
         this.$set(