Ver código fonte

feat(库存管理): 增加总重输入功能并优化重量计算逻辑

liujt 5 meses atrás
pai
commit
b1facf8e26

+ 29 - 8
src/BIZComponents/inventoryTable.vue

@@ -483,6 +483,27 @@
           </el-input>
         </el-form-item>
       </template>
+      <template v-slot:totalWeight="scope">
+        <el-form-item
+          style="margin-bottom: 20px"
+          :rules="{
+            required: false,
+            pattern: numberReg,
+            trigger: 'change'
+          }"
+          :prop="'datasource.' + scope.$index + '.totalWeight'"
+        >
+          <el-input
+            v-model="scope.row.totalWeight"
+            @input="changeCount(scope.row, scope.$index, 'totalWeight')"
+            placeholder="请输入"
+          >
+            <template slot="append">
+              {{ scope.row.weightUnit }}
+            </template>
+          </el-input>
+        </el-form-item>
+      </template>
       <template v-slot:increaseTotalWeight="scope">
         <el-form-item
           :prop="'datasource.' + scope.$index + '.increaseTotalWeight'"
@@ -1460,11 +1481,11 @@
             prop: 'totalWeight',
             label: '总重',
             slot: 'totalWeight',
-            formatter: (_row, _column, cellValue) => {
-              if (_row.totalWeight) {
-                return _row.totalWeight + ' ' + (_row.weightUnit || '');
-              }
-            },
+            // formatter: (_row, _column, cellValue) => {
+            //   if (_row.totalWeight) {
+            //     return _row.totalWeight + ' ' + (_row.weightUnit || '');
+            //   }
+            // },
             align: 'center'
           },
           {
@@ -1828,7 +1849,7 @@
         return [this.allPrice, this.form.discountTotalPrice];
       },
       //改变数量
-      changeCount(row, index) {
+      changeCount(row, index, weightType) {
         if (!row) {
           this.form.datasource = this.form.datasource.map((item, i) => {
             return changeCount(item, this.countObj, false);
@@ -1837,7 +1858,7 @@
             this.setIncreaseTotalWeight(item, i);
           });
         } else {
-          const updatedRow = changeCount(row, this.countObj, false);
+          const updatedRow = changeCount(row, this.countObj, false, weightType);
           this.$set(this.form.datasource, index, updatedRow);
           this.setIncreaseTotalWeight(row, index);
         }
@@ -1891,7 +1912,7 @@
           'totalPrice',
           totalPrice.toFixed(2)
         );
-        if (row[this.countObj.unitKey] == row.weightUnit) {
+        if (row[this.countObj.unitKey] == row.weightUnit && row.pricingWay == 1) {
           this.$set(this.form.datasource[index], 'totalWeight', quantity);
         } else {
           if (quantity && row.singleWeight) {

+ 25 - 4
src/BIZComponents/setProduct.js

@@ -1,7 +1,8 @@
 import Vue from 'vue';
 
 //改变数量
-export function changeCount(row, countObj, noDiscountSingle) {
+export function changeCount(row, countObj, noDiscountSingle, weightType) {
+  console.log('changeCount~~', row, countObj, noDiscountSingle)
   let total = row[countObj.countKey] || 0;
   let data = row;
   if (row.packageDispositionList) {
@@ -20,8 +21,15 @@ export function changeCount(row, countObj, noDiscountSingle) {
   data['discountSinglePrice'] = !noDiscountSingle
     ? data.singlePrice
     : data.discountSinglePrice;
-
-  setWeight(data);
+  
+  if(weightType == 'totalWeight'){
+    console.log('weightType~~', 1)
+    setSingleWeight(data);
+  } else {
+    console.log('weightType~~', 2)
+    setWeight(data);
+  }
+  
   data['totalPrice'] = 0;
   data['discountTotalPrice'] = 0;
   if (row.pricingWay == 2||row.pricingWay == 3) {
@@ -39,8 +47,10 @@ export function changeCount(row, countObj, noDiscountSingle) {
     : data.discountTotalPrice;
   return data;
 }
+
+// 计算总重
 function setWeight(row) {
-  if (row.weightUnit == row.measuringUnit) {
+  if (row.weightUnit == row.measuringUnit && row.pricingWay == 1) {
     row['totalWeight'] = row.totalCount;
   } else if (row.totalCount && row.singleWeight) {
     row['totalWeight'] = (row.totalCount * row.singleWeight).toFixed(2);
@@ -48,6 +58,17 @@ function setWeight(row) {
     row['totalWeight'] = 0;
   }
 }
+// 计算单重
+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 {
+    row['singleWeight'] = 0;
+  }
+}
 export function getAllPrice(arr) {
   let sum = 0;
   arr.forEach((item) => {

+ 42 - 9
src/views/purchasingManage/purchaseOrder/components/inventoryTable.vue

@@ -283,6 +283,27 @@
           </el-input>
         </el-form-item>
       </template>
+      <template v-slot:totalWeight="scope">
+        <el-form-item
+          style="margin-bottom: 20px"
+          :rules="{
+            required: false,
+            pattern: numberReg,
+            trigger: 'change'
+          }"
+          :prop="'datasource.' + scope.$index + '.totalWeight'"
+        >
+          <el-input
+            v-model="scope.row.totalWeight"
+            @input="changeCount(scope.row, scope.$index, 'totalWeight')"
+            placeholder="请输入"
+          >
+            <template slot="append">
+              {{ scope.row.weightUnit }}
+            </template>
+          </el-input>
+        </el-form-item>
+      </template>
       <template v-slot:technicalAnswerName="{ row, $index }">
         <el-form-item
           style="margin-bottom: 20px"
@@ -561,7 +582,7 @@
   import { numberReg, positiveIntegerReg } from 'ele-admin';
   import productList from '@/BIZComponents/product-list.vue';
   import dictMixins from '@/mixins/dictMixins';
-
+  import headList from '@/BIZComponents/user-select/user-select.vue';
   import billDetailDialog from './billDetailDialog.vue';
   import taskinstanceDialog from '@/BIZComponents/procedure/taskinstanceDialog.vue';
   import { pricingWayList, lbjtList } from '@/enum/dict.js';
@@ -596,7 +617,8 @@
       taskinstanceDialog,
       // fileMain,
       productList,
-      billDetailDialog
+      billDetailDialog,
+      headList
     },
     computed: {
       canHandl() {
@@ -892,11 +914,11 @@
             label: '总重',
             slot: 'totalWeight',
             align: 'center',
-            formatter: (row, column) => {
-              if (row.totalWeight) {
-                return row.totalWeight + ' ' + (row.weightUnit || '');
-              }
-            }
+            // formatter: (row, column) => {
+            //   if (row.totalWeight) {
+            //     return row.totalWeight + ' ' + (row.weightUnit || '');
+            //   }
+            // }
           },
           {
             width: 180,
@@ -1101,8 +1123,19 @@
           this.changeAll();
         }
       },
+      // 改变总重
+      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)
+      },
       //改变数量
-      changeCount(row, index) {
+      changeCount(row, index, weightType) {
         // if (this.detailType) {
         //   return;
         // }
@@ -1126,7 +1159,7 @@
           this.$set(
             this.form,
             'datasource[' + index + ']',
-            changeCount(row, countObj)
+            changeCount(row, countObj, false, weightType)
           );
           this.setIncreaseTotalWeight(row, index);
         }