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

fix(库存管理): 修复重量单位与包装单位相同时的单重和重量计算逻辑

yusheng 7 месяцев назад
Родитель
Сommit
ae6f5db8a8
1 измененных файлов с 96 добавлено и 25 удалено
  1. 96 25
      src/views/warehouseManagement/stockManagement/add.vue

+ 96 - 25
src/views/warehouseManagement/stockManagement/add.vue

@@ -256,7 +256,7 @@
               </template>
               <template v-slot:singleWeight="{ row, $index }">
                 <el-input
-                  :disabled="row.isSave"
+                  :disabled="row.isSave || row.weightUnit == row.packingUnit"
                   v-model="row.singleWeight"
                   placeholder="请输入"
                   :min="0"
@@ -264,13 +264,13 @@
                   @input="inputSingleWeight(row, $index)"
                 >
                   <template slot="append">
-                    {{ row.weightUnit + '/' + row.measureUnit }}
+                    {{ row.weightUnit }}
                   </template>
                 </el-input>
               </template>
               <template v-slot:weight="{ row, $index }">
                 <el-input
-                  :disabled="row.isSave"
+                  :disabled="row.isSave || row.weightUnit == row.packingUnit"
                   v-model="row.weight"
                   placeholder="请输入"
                   @input="inputAllweight(row, $index)"
@@ -1533,19 +1533,23 @@
         } else if (row.packingQuantity > 9999) {
           this.$set(this.productList[index], 'singleWeight', 9999);
         }
-        console.log(row.singleWeight);
-        console.log(row.measureQuantity);
+        if (row.measureUnit == row.weightUnit) {
+          row.weight = row.singleWeight * row.packingQuantity;
+          row.measureQuantity = row.weight;
+        } else {
+          row.weight = row.singleWeight * row.measureQuantity;
+        }
 
         //重量
-        if (row.measureType == '2') {
-          if (row.packingUnit == 'KG') {
-            const weight =
-              Number(row.measureQuantity) * Number(row.singleWeight);
-            this.$set(this.productList[index], 'weight', weight);
-          } else {
-            this.$set(this.productList[index], 'weight', measureQuantity);
-          }
-        }
+        // if (row.measureType == '2') {
+        //   if (row.packingUnit == 'KG') {
+        //     const weight =
+        //       Number(row.measureQuantity) * Number(row.singleWeight);
+        //     this.$set(this.productList[index], 'weight', weight);
+        //   } else {
+        //     this.$set(this.productList[index], 'weight', measureQuantity);
+        //   }
+        // }
 
         console.log(row, 'row2');
       },
@@ -1553,8 +1557,17 @@
         if (row.weight < 0) {
           this.$set(this.productList[index], 'weight', 1);
         }
-        const singleWeight = Number(row.weight) / Number(row.measureQuantity);
-        this.$set(this.productList[index], 'singleWeight', singleWeight);
+        if (row.measureUnit == row.weightUnit) {
+          row.measureQuantity = row.weight;
+          row.singleWeight =
+            Math.trunc((row.measureQuantity / row.packingQuantity) * 100) / 100;
+        } else {
+          row.singleWeight = row.measureQuantity
+            ? row.weight / row.measureQuantity
+            : 0;
+        }
+        // const singleWeight = Number(row.weight) / Number(row.measureQuantity);
+        // this.$set(this.productList[index], 'singleWeight', singleWeight);
       },
       // 仓库选择
       // wareHouseSelection(val, index) {
@@ -1650,6 +1663,9 @@
           let weight = 0;
           if (row.measureUnit == row.weightUnit) {
             weight = row.measureQuantity;
+            row.singleWeight =
+              Math.trunc((row.measureQuantity / row.packingQuantity) * 100) /
+              100;
           } else if (row.singleWeight) {
             weight = row.measureQuantity * Number(row.singleWeight);
           }
@@ -2962,11 +2978,33 @@
                 ]);
               }
             } else {
-              // let pNum =
-              let pNum = Math.ceil(
-                row.measureQuantity /
-                  row.packingSpecificationOption[1]?.packageCell
-              );
+              let pNum = 0;
+              if (row.packingUnitId) {
+                let splitIndex = row.packingSpecificationOption.findIndex(
+                  (item) => item.id == row.packingUnitId
+                );
+                if (splitIndex == 0) {
+                  pNum = Math.ceil(
+                    row.measureQuantity /
+                      row.packingSpecificationOption[1]?.packageCell
+                  );
+                }
+                if (splitIndex == 1) {
+                  pNum = row.packingQuantity;
+                }
+
+                for (; splitIndex > 1; splitIndex--) {
+                  pNum = Math.ceil(
+                    row.packingQuantity *
+                      row.packingSpecificationOption[splitIndex].packageCell
+                  );
+                }
+              } else {
+                pNum = Math.ceil(
+                  row.measureQuantity /
+                    row.packingSpecificationOption[1]?.packageCell
+                );
+              }
               // row.packingQuantity;
               // console.log(row.packingQuantity,'row.packingQuantity')
               // return
@@ -3249,7 +3287,25 @@
                       this.$math.format(filterArr[0].packageCell * index, 14);
               }
             } else {
-              measureQuantity = row.packingSpecificationOption[1].packageCell;
+              //计量单位等于重量单位并且有总重 计量数量=总重/包装数
+              if (row.weightUnit == row.measureUnit && row.weight) {
+                measureQuantity =
+                  Math.trunc((row.weight / packingCodeList.length) * 100) / 100;
+              } else {
+                // 处理单位不为KG类,计量单位为KG类的情况
+                let splitIndex = row.packingSpecificationOption.findIndex(
+                  (item) =>
+                    item.conversionUnit == row.packingUnit &&
+                    item.packageUnit != item.conversionUnit
+                );
+                for (; splitIndex > 0; splitIndex--) {
+                  measureQuantity = this.$math.format(
+                    measureQuantity *
+                      row.packingSpecificationOption[splitIndex].packageCell,
+                    14
+                  );
+                }
+              }
             }
             console.log(
               'meadasdassureQuantity',
@@ -3409,11 +3465,26 @@
 
         const lastIndex = this.packingList.length - 1;
 
-        let remainder =
-          row.measureQuantity % row.packingSpecificationOption[1]?.packageCell;
+        let remainder = 0;
+        if (row.weightUnit != row.measureUnit) {
+          remainder =
+            row.measureQuantity %
+            row.packingSpecificationOption[1]?.packageCell;
+        }
         console.log(remainder, 'remainder');
         if (remainder > 0) {
-          this.$set(this.packingList[lastIndex], 'measureQuantity', remainder);
+          let onlyCode = packingCodeList[packingCodeList.length - 1]?.onlyCode;
+          let index = this.packingList.findIndex(
+            (packingItem) => packingItem.packageNo == onlyCode
+          );
+          this.$set(this.packingList[index], 'measureQuantity', remainder);
+          if (row.singleWeight) {
+            this.$set(
+              this.packingList[index],
+              'weight',
+              row.singleWeight * remainder
+            );
+          }
         }
       },
       //入库明细删除