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

fix(库存管理): 优化重量计算逻辑并统一处理函数命名

yusheng 5 месяцев назад
Родитель
Сommit
22586501a9

+ 10 - 7
src/BIZComponents/inventoryTable.vue

@@ -495,7 +495,7 @@
         >
           <el-input
             v-model="scope.row.totalWeight"
-            @input="changeCount(scope.row, scope.$index, 'totalWeight')"
+            @input="handleCountChange(scope.row, scope.$index, 'totalWeight')"
             placeholder="请输入"
           >
             <template slot="append">
@@ -691,11 +691,11 @@
                 v-model="scope.row[countObj.unitIdKey]"
                 style="width: 80px"
                 v-if="!!scope.row.productId && scope.row.productId != 0"
+                @change="handleCountChange(scope.row, scope.$index)"
               >
                 <el-option
                   :label="item.conversionUnit"
                   :value="item.id"
-                  @click.native="packingChange(item, scope.$index)"
                   v-for="(item, index) in scope.row.packageDispositionList"
                   :key="index"
                 ></el-option>
@@ -1480,7 +1480,7 @@
             width: 180,
             prop: 'totalWeight',
             label: '总重',
-            // slot: 'totalWeight',
+            slot: 'totalWeight',
             formatter: (_row, _column, cellValue) => {
               if (_row.totalWeight) {
                 return _row.totalWeight + ' ' + (_row.weightUnit || '');
@@ -1698,12 +1698,12 @@
       });
     },
     methods: {
-      handleCountChange(row, index) {
+      handleCountChange(row, index,weightType) {
         // 数量变化时,若为生产加工类型,触发含税小计计算
         if (this.quoteType === 2) {
           this.calculateIncludingTaxPrice(row, index);
         } else {
-          this.changeCount(row, index);
+          this.changeCount(row, index,weightType);
         }
       },
       packingChange(item, index) {
@@ -1876,7 +1876,7 @@
             'totalPrice',
             ((row.increaseTotalWeight || 0) * row.singlePrice).toFixed(2)
           );
-            this.changeAll();
+          this.changeAll();
         }
       },
       // 计算含税小计(原含税单价逻辑)
@@ -1912,7 +1912,10 @@
           'totalPrice',
           totalPrice.toFixed(2)
         );
-        if (row[this.countObj.unitKey] == row.weightUnit && row.pricingWay == 1) {
+        if (
+          row[this.countObj.unitKey] == row.weightUnit &&
+          row.pricingWay == 1
+        ) {
           this.$set(this.form.datasource[index], 'totalWeight', quantity);
         } else {
           if (quantity && row.singleWeight) {

+ 66 - 24
src/BIZComponents/setProduct.js

@@ -1,15 +1,24 @@
+import C from 'highlight.js/lib/languages/1c';
 import Vue from 'vue';
 
 //改变数量
 export function changeCount(row, countObj, noDiscountSingle, weightType) {
-  console.log('changeCount~~', row, countObj, noDiscountSingle)
-  const type = countObj.type || 'sale';
+  // console.log('changeCount~~', row, countObj, noDiscountSingle);
   let total = row[countObj.countKey] || 0;
   let data = row;
+  let _endIndex = 0; //计算单重需要
   if (row.packageDispositionList) {
     let endIndex = row.packageDispositionList.findIndex(
       (ite) => row[countObj.unitIdKey] == ite.id
     );
+    _endIndex = endIndex;
+    let packageData = row.packageDispositionList.find(
+      (ite) => row[countObj.unitIdKey] == ite.id
+    );
+    row[countObj.unitKey] = packageData.conversionUnit;
+    if (row.weightUnit == row.measuringUnit && row.singleWeight) {
+      row.packageDispositionList[1].packageCell = row.singleWeight;
+    }
     for (; 0 < endIndex; endIndex--) {
       total = Vue.prototype.$math.format(
         row.packageDispositionList[endIndex].packageCell * total,
@@ -17,30 +26,31 @@ export function changeCount(row, countObj, noDiscountSingle, weightType) {
       );
     }
   }
-
   data['totalCount'] = total;
   data['discountSinglePrice'] = !noDiscountSingle
     ? data.singlePrice
     : data.discountSinglePrice;
-  
-  if(weightType == 'totalWeight'){
-    console.log('weightType~~', 1)
-    setSingleWeight(data);
+
+  if (weightType == 'totalWeight') {
+    console.log('weightType~~', 1);
+    setSingleWeight(data, countObj, _endIndex);
   } else {
-    console.log('weightType~~', 2)
-    setWeight(data, type);
+    console.log('weightType~~', 2);
+    setWeight(data, countObj);
   }
-  
+
   data['totalPrice'] = 0;
   data['discountTotalPrice'] = 0;
-  if (row.pricingWay == 2||row.pricingWay == 3) {
-    let weightKey=countObj.weightKey||'totalWeight'
+  if (row.pricingWay == 2 || row.pricingWay == 3) {
+    let weightKey = countObj.weightKey || 'totalWeight';
     if (row[weightKey] && row.singlePrice) {
       data['totalPrice'] = (row[weightKey] * row.singlePrice).toFixed(2);
     }
   } else {
     if (row[countObj.countKey] && row.singlePrice) {
-      data['totalPrice'] = (row[countObj.countKey] * row.singlePrice).toFixed(2);
+      data['totalPrice'] = (row[countObj.countKey] * row.singlePrice).toFixed(
+        2
+      );
     }
   }
   data['discountTotalPrice'] = !noDiscountSingle
@@ -50,25 +60,57 @@ export function changeCount(row, countObj, noDiscountSingle, weightType) {
 }
 
 // 计算总重
-function setWeight(row, type) {
-  if (row.weightUnit == row.measuringUnit && (type != 'purchase' || (type == 'purchase'&& row.pricingWay == 1))) {
+function setWeight(row, countObj) {
+  if (row.weightUnit == row.measuringUnit) {
     row['totalWeight'] = row.totalCount;
-  } else if (row.totalCount && row.singleWeight) {
-    row['totalWeight'] = (row.totalCount * row.singleWeight).toFixed(2);
+  } else if (row[countObj.countKey] && row.singleWeight) {
+    row['totalWeight'] = (row[countObj.countKey] * row.singleWeight).toFixed(2);
   } else {
     row['totalWeight'] = 0;
   }
+  // if (row.weightUnit == row[countObj.unitKey]) {
+  //   row['totalWeight'] = row.totalCount;
+  // } else if (row[countObj.countKey] && row.singleWeight) {
+  //   row['totalWeight'] = (row[countObj.countKey] * row.singleWeight).toFixed(2);
+  // } else {
+  //   row['totalWeight'] = 0;
+  // }
+  if (row.weightUnit == row.measuringUnit) {
+    row['totalCount'] = row.totalWeight;
+  }
+  console.log(row['totalCount'], 'dsds');
 }
 // 计算单重
-function setSingleWeight(row) {
-  console.log('setSingleWeight~~', row)
-  if (row.totalWeight && row.totalCount) {
-    console.log('setSingleWeight~~', row.totalWeight, row.totalCount)
-    row['singleWeight'] = (row.totalWeight/row.totalCount).toFixed(2);
-    console.log('singleWeight~~', row['singleWeight'])
-  }  else {
+function setSingleWeight(row, countObj, endIndex) {
+  console.log('setSingleWeight~~', row);
+  //  if (row.totalWeight && row[countObj.countKey]) {
+  //     row['singleWeight'] = (row.totalWeight / row[countObj.countKey]).toFixed(2);
+  //     console.log('singleWeight~~', row['singleWeight']);
+  //   } else {
+  //     row['singleWeight'] = 0;
+  //   }
+  // console.log(endIndex, 'endIndex');
+  if (row.weightUnit == row.measuringUnit) {
+    let totalWeight = row['totalWeight'];
+    for (; 1 < endIndex; endIndex--) {
+      totalWeight = Vue.prototype.$math.format(
+        totalWeight / row.packageDispositionList[endIndex].packageCell,
+        14
+      );
+    }
+    // console.log(totalWeight, 'totalWeight');
+    row['singleWeight'] = Number(totalWeight/row[countObj.countKey]).toFixed(2);
+  } else if (row.totalWeight && row[countObj.countKey]) {
+    row['singleWeight'] = (row.totalWeight / totalCount).toFixed(2);
+  } else {
     row['singleWeight'] = 0;
   }
+  if (row.weightUnit == row.measuringUnit) {
+    row['totalCount'] = row.totalWeight;
+  }
+  if (row.weightUnit == row[countObj.unitKey]) {
+    row[countObj.countKey] = row.totalWeight;
+  }
 }
 export function getAllPrice(arr) {
   let sum = 0;

+ 10 - 16
src/views/purchasingManage/purchaseOrder/components/inventoryTable.vue

@@ -527,7 +527,7 @@
                 <el-option
                   :label="item.conversionUnit"
                   :value="item.id"
-                  @click.native="packingChange(item, scope.$index)"
+                
                   v-for="(item, index) in scope.row.packageDispositionList"
                   :key="index"
                 ></el-option>
@@ -1106,13 +1106,13 @@
       getPrice() {
         return [this.allPrice];
       },
-      packingChange(item, index) {
-        this.$set(
-          this.form.datasource[index],
-          'purchaseUnit',
-          item.conversionUnit
-        );
-      },
+      // packingChange(item, index) {
+      //   this.$set(
+      //     this.form.datasource[index],
+      //     'purchaseUnit',
+      //     item.conversionUnit
+      //   );
+      // },
       setIncreaseTotalWeight(row, index) {
         if (row.pricingWay == 3) {
           this.$set(
@@ -1125,13 +1125,7 @@
       },
       // 改变总重
       changeTotalWeight(row, index) {
-        // this.$set(
-        //   this.form.datasource[index],
-        //   'singleWeight',
-        //   row.totalWeight ? (row.totalWeight / row.purchaseCount).toFixed(2) : 0
-        // );
-        // row.singleWeight = row.totalWeight ? (row.totalWeight / row.purchaseCount).toFixed(2) : 0
-        console.log('changeTotalWeight~~', row, this.form.datasource[index]);
+
         this.changeCount(row, index)
       },
       //改变数量
@@ -1139,7 +1133,7 @@
         // if (this.detailType) {
         //   return;
         // }
-        console.log('changeCount~~', row);
+
         let countObj = {
           countKey: 'purchaseCount',
           unitKey: 'purchaseUnit',

+ 24 - 36
src/views/purchasingManage/purchaseOrder/invoice/components/inventoryTable.vue

@@ -121,7 +121,8 @@
           <el-input
             type="number"
             v-model="scope.row.receiveTotalWeight"
-            @blur="setIcreaseTotalWeight(scope.$index)"
+                    @input="changeCount(scope.row, scope.$index, 'totalWeight')"
+
             style="width: 100%"
             :disabled="isDis(scope.row)"
           >
@@ -285,7 +286,6 @@
                 <el-option
                   :label="item.conversionUnit"
                   :value="item.id"
-                  @click.native="packingChange(item, scope.$index)"
                   v-for="(item, index) in scope.row.packageDispositionList"
                   :key="index"
                 ></el-option>
@@ -989,9 +989,7 @@
         this.setIcreaseTotalWeight(this.curIndex);
       },
       isDis(row) {
-        console.log(row, 'row');
-        console.log(row.weightUnit, 'row.weightUnit');
-        console.log(row.purchaseUnit, 'row.purchaseUnit');
+
         if (row.weightUnit == row.purchaseUnit) {
           return true;
         }
@@ -999,15 +997,27 @@
         return false;
       },
       //改变数量
-      changeCount(row, index) {
+      changeCount(row, index, weightType) {
+        if (weightType == 'totalWeight') {
+          this.$set(
+            this.form.datasource[index],
+            'totalWeight',
+            this.form.datasource[index].receiveTotalWeight
+          );
+        }
         this.$set(
           this.form,
           'datasource[' + index + ']',
-          changeCount(row, {
-            countKey: 'purchaseCount',
-            unitKey: 'purchaseUnit',
-            unitIdKey: 'purchaseUnitId'
-          })
+          changeCount(
+            row,
+            {
+              countKey: 'purchaseCount',
+              unitKey: 'purchaseUnit',
+              unitIdKey: 'purchaseUnitId'
+            },
+            false,
+            weightType
+          )
         );
         this.$set(
           this.form.datasource[index],
@@ -1048,26 +1058,7 @@
           'increaseTotalWeight',
           (receiveTotalWeight - sendTotalWeight).toFixed(2)
         );
-        if (
-          this.form.datasource[index].measuringUnit ==
-          this.form.datasource[index].weightUnit
-        ) {
-          this.$set(
-            this.form.datasource[index],
-            'totalCount',
-            receiveTotalWeight
-          );
-        } else {
-          this.$set(
-            this.form.datasource[index],
-            'singleWeight',
-            Number(
-              (
-                receiveTotalWeight / this.form.datasource[index].totalCount
-              ).toFixed(2)
-            )
-          );
-        }
+
         if (pricingWay == 2) {
           this.$set(
             this.form.datasource[index],
@@ -1275,7 +1266,6 @@
             };
           });
           this.form.datasource.forEach((item, index) => {
-
             if (item.modelKey) {
               this.$set(
                 this.form.datasource[index],
@@ -1308,11 +1298,9 @@
         this.$set(
           this.form.datasource[index],
           'receiveTotalWeight',
-          item.receiveTotalWeight ||
-            item.totalWeight ||
-            Number(item.totalCount) * Number(item.singleWeight) ||
-            0
+          item.receiveTotalWeight || item.totalWeight || 0
         );
+
         if (this.outsourceSendCode) {
           this.$set(
             this.form.datasource[index],

+ 8 - 1
src/views/saleManage/saleOrder/entrustedReceive/components/inventoryTable.vue

@@ -649,10 +649,17 @@
       //修改数量更新合计
       changeNum(row, index) {
         if (row.totalCount && row.singleWeight) {
+          let receiveTotalWeight = 0;
+          if (row.measuringUnit == row.weightUnit) {
+            receiveTotalWeight = Number(row.totalCount);
+          } else {
+            receiveTotalWeight =
+              Number(row.totalCount) * Number(row.singleWeight);
+          }
           this.$set(
             this.form.datasource[index],
             'receiveTotalWeight',
-            row.totalCount * row.singleWeight
+            receiveTotalWeight
           );
         } else {
           this.$set(this.form.datasource[index], 'receiveTotalWeight', 0);

+ 24 - 13
src/views/saleManage/saleOrder/invoice/components/inventoryTable.vue

@@ -143,7 +143,7 @@
             type="number"
             v-model="scope.row.sendTotalWeight"
             style="width: 100%"
-            @input="changeSendTotalWeight(scope.row, scope.$index)"
+            @input="changeCount(scope.row, scope.$index, true, 'totalWeight')"
           >
             <template slot="append">
               {{ scope.row.weightUnit }}
@@ -282,7 +282,6 @@
                 <el-option
                   :label="item.conversionUnit"
                   :value="item.id"
-                  @click.native="packingChange(item, scope.$index)"
                   v-for="(item, index) in scope.row.packageDispositionList"
                   :key="index"
                 ></el-option>
@@ -1089,15 +1088,28 @@
         );
       },
       //改变数量
-      changeCount(row, index, isBlockCount = true) {
+      changeCount(row, index, isBlockCount = true, weightType) {
+        if (weightType == 'totalWeight') {
+          this.$set(
+            this.form.datasource[index],
+            'totalWeight',
+            this.form.datasource[index].sendTotalWeight
+          );
+        }
+
         this.$set(
           this.form,
           'datasource[' + index + ']',
-          changeCount(row, {
-            countKey: 'saleCount',
-            unitKey: 'saleUnit',
-            unitIdKey: 'saleUnitId'
-          })
+          changeCount(
+            row,
+            {
+              countKey: 'saleCount',
+              unitKey: 'saleUnit',
+              unitIdKey: 'saleUnitId'
+            },
+            false,
+            weightType
+          )
         );
         this.$set(
           this.form.datasource[index],
@@ -1114,6 +1126,7 @@
       //修改发货总重
       changeSendTotalWeight(row, index) {
         this.curIndex = index;
+
         this.setIcreaseTotalWeight(row);
       },
       keyChange(index, row, key) {
@@ -1400,9 +1413,7 @@
             item.sendTotalWeight = item.sendTotalWeight || item.totalCount;
           } else {
             item.sendTotalWeight =
-              item.sendTotalWeight ||
-              Number(item.totalCount) * Number(item.singleWeight) ||
-              0;
+              item.sendTotalWeight || Number(item.totalWeight) || 0;
           }
 
           if (this.outsourceSendCode) {
@@ -1413,8 +1424,8 @@
             item.increaseTotalWeight =
               item.increaseTotalWeight || item.receiveTotalWeight || 0;
           }
-          item['sendTotalWeight'] = item.sendTotalWeigh;
-          item['increaseTotalWeight'] = item.increaseTotalWeight;
+          // item['sendTotalWeight'] = item.sendTotalWeigh;
+          // item['increaseTotalWeight'] = item.increaseTotalWeight;
           item['tempId'] = this.form.datasource.length;
           indexS.push(this.form.datasource.length);
           this.$set(