Преглед изворни кода

销售订单选品反算总和和明细

koushanshan пре 1 година
родитељ
комит
19903a6424
3 измењених фајлова са 319 додато и 83 уклоњено
  1. 1 0
      src/libs/update-columns/index.js
  2. 6 1
      src/locale/lang/zh-CN.js
  3. 312 82
      src/view/sale/order/form.vue

+ 1 - 0
src/libs/update-columns/index.js

@@ -29,6 +29,7 @@ export default {
     {updateField: 'unitName', valueFiled: 'unitName'},
     {updateField: 'subUnitName', valueFiled: 'subUnitName'},
     {updateField: 'decimalPlaces' , valueFiled: 'decimalPlaces'},
+    {updateField: 'factPrice' , valueFiled: 'priceStandard'},
   ],
 
   /**

+ 6 - 1
src/locale/lang/zh-CN.js

@@ -307,8 +307,13 @@ export const columns = {
   priceStd: '标价',
   amtStd: '标价金额',
   priceSale: '售价',
+  factPrice: '优惠后单价',
   itemAmt: '售价金额',
-  priceDiscount: '折扣',
+  totalFactAmt: '实收金额',
+  factAmt: '优惠后金额',
+  discAmt: '优惠金额',
+  priceDiscount: '标价折扣',
+  discount: '折扣',
   whName: '仓库名称',
   oWhName: '原仓库名称',
   whCode: '仓库编码',

+ 312 - 82
src/view/sale/order/form.vue

@@ -117,7 +117,10 @@
                      :delete-flag="type === $config.formMode.add ? true : false"
                      :columns="this.type === this.$config.formMode.add ? addOrderItemColumns: editOrderItemColumns"
                      @changeNonStandard="changeNonStandard"
-                     controlId="skuId" @on-choose="getTotals" @changeValue="getTotals"/>
+                     controlId="skuId"
+                     @on-choose="getTotals"
+                     @changeValue="getTotals"
+                     @delRow ='delRow'/>
           <div>
             <DkForm ref="goodsFootFormData" v-model="goodsFootFormData" :labelMaxWords="5" name="dk-form"
                     class="read-only-form">
@@ -128,9 +131,24 @@
               </DkFormItem>
               <!--货物金额-->
               <DkFormItem prop="sumAmount" class="amount">
-                <InputNumberPop ref="sumAmount" :v-model="goodsFootFormData.sumAmount" :clearable="false"
+                <InputNumberPop ref="sumAmount" v-model="goodsFootFormData.sumAmount" :clearable="false"
                                 :digits="2" :readonly="true"/>
               </DkFormItem>
+              <!--实收金额-->
+              <DkFormItem prop="factAmt" class="amount" :label="$t('totalFactAmt')">
+                <InputNumberPop ref="factAmt" v-model="goodsFootFormData.factAmt" :digits="2"
+                                :readonly="false" @on-blur="(val)=>changeDiscountOrAmount(val, 1)" />
+              </DkFormItem>
+              <!--折扣-->
+              <DkFormItem prop="discount" class="amount">
+                <InputNumberPop ref="discount" v-model="goodsFootFormData.discount" :digits="2"
+                                :readonly="updateTotalFootMessageFlag" unit="%"  @on-blur="(val)=>changeDiscountOrAmount(val, 2)" />
+              </DkFormItem>
+              <!--优惠金额-->
+              <DkFormItem prop="discAmt" class="amount">
+                <InputNumberPop ref="discAmt" v-model="goodsFootFormData.discAmt" :digits="2"
+                                :readonly="updateTotalFootMessageFlag" @on-blur="(val)=>changeDiscountOrAmount(val, 3)" />
+              </DkFormItem>
               <!--标价总额-->
               <DkFormItem prop="sumStandard" class="amount">
                 <InputNumberPop ref="sumStandard" v-model="goodsFootFormData.sumStandard" :digits="2"
@@ -217,6 +235,9 @@ export default {
         sumAmount: 0,
         sumStandard: 0,
         saleDiscount: 0,
+        discount: 0,//整单折扣
+        factAmt: 0,//实收金额
+        discAmt: 0,//总单优惠
       },
       //客户收款
       receiptFormData: {
@@ -253,17 +274,6 @@ export default {
           field: 'skuCode',
           type: 'disabled',
         },
-        //价格
-        {
-          field: 'priceSale',
-          type: 'number',
-          digits: 2,
-          formula: {
-            itemAmt: ['itemQty*priceSale', 'itemQty', 'priceSale'],
-            priceDiscount: ['priceSale/priceStd*100', 'priceSale', 'priceStd'],
-          },
-        },
-        //数量
         {
           field: 'itemQty',
           type: 'number',
@@ -274,7 +284,76 @@ export default {
             amtStd: ['itemQty*priceStd', 'itemQty', 'priceStd'],
             box: ['itemQty/packBox', 'itemQty', 'packBox'],
             piece: ['itemQty%packBox', 'itemQty', 'packBox'],
+            factAmt: ['itemQty*factPrice', 'itemQty', 'factPrice'],
+            discount: ['(factPrice / priceSale * 100 ', 'factPrice', 'priceSale'],
           },
+        }, //数量
+        {
+          field: 'priceSale',
+          type: 'disabled',
+          number: true,
+          digits: 2,
+        }, //价格
+        {
+          field: 'itemAmt',
+          type: 'disabled',
+          digits: 2,
+          number: true,
+          sum: true,
+        }, //金额
+        {
+          field: 'factPrice',
+          type: 'number',
+          digits: 2,
+          formula: {
+            //实际金额 =  数量 *  实际金额
+            factAmt: ['itemQty*factPrice', 'itemQty', 'factPrice'],
+            //标价折扣 =  售价 / 标价 * 100
+            priceDiscount: ['factPrice/priceStd*100', 'factPrice', 'priceStd'],
+            //折扣 = 实际单价/ 售价 *100
+            discount: ['factPrice / priceSale * 100 ', 'factPrice', 'priceSale'],
+          },
+        },//实际价格
+        {
+          field: 'factAmt',
+          type: 'number',
+          digits: 2,
+          number: true,
+          sum: true,
+          formulaLate: true,
+          formula: {
+            //实际单价 =  金额 / 数量
+            factPrice: ['factAmt / itemQty  ', 'priceSale', 'discount'],
+            //折扣 = 实际金额 / 金额
+            discount: ['factAmt /  itemAmt * 100 ', 'factAmt', 'itemAmt'],
+          },
+        },//实际金额.
+        {
+          field: 'discount',
+          type: 'number',
+          number: true,
+          digits: 2,
+          formulaLate: true,
+          formula: {
+            //实际单价 =  售价 * 折扣 / 100 - 优惠金额
+            factPrice: ['priceSale * discount /100 ', 'priceSale', 'discount'],
+            //实际金额 =  数量 *  实际金额
+            factAmt: ['itemQty * factPrice', 'itemQty', 'factPrice'],
+          },
+        },//折扣
+        //商品标价
+        {
+          field: 'priceStd',
+          type: 'disabled',
+          number: true,
+          digits: 2,
+        },
+        //标价折扣
+        {
+          field: 'priceDiscount',
+          type: 'disabled',
+          number: true,
+          digits: 2,
         },
         // //包装
         // {
@@ -335,33 +414,6 @@ export default {
           ],
           searchDetailFlag: true
         },
-        //金额
-        {
-          field: 'itemAmt',
-          type: 'number',
-          digits: 2,
-          number: true,
-          sum: true,
-          formulaLate: true,
-          formula: {
-            priceSale: ['itemAmt/itemQty', 'itemAmt', 'itemQty'],
-            priceDiscount: ['itemAmt/itemQty/priceStd*100', 'itemAmt', 'itemQty', 'priceStd'],
-          },
-        },
-        //商品标价
-        {
-          field: 'priceStd',
-          type: 'disabled',
-          number: true,
-          digits: 2,
-        },
-        //标价折扣
-        {
-          field: 'priceDiscount',
-          type: 'disabled',
-          number: true,
-          digits: 2,
-        },
         //非标号
         {
           field: 'nonStdCode', type: 'text', equal: true,
@@ -393,28 +445,86 @@ export default {
           field: 'skuCode',
           type: 'disabled',
         },
-        //价格
+        {
+          field: 'itemQty',
+          type: 'number',
+          digits: this.decimalPlaces,
+          sum: true,
+          formula: {
+            itemAmt: ['itemQty*priceSale', 'itemQty', 'priceSale'],
+            amtStd: ['itemQty*priceStd', 'itemQty', 'priceStd'],
+            box: ['itemQty/packBox', 'itemQty', 'packBox'],
+            piece: ['itemQty%packBox', 'itemQty', 'packBox'],
+            factAmt: ['itemQty*factPrice', 'itemQty', 'factPrice'],
+            discount: ['(factPrice / priceSale * 100 ', 'factPrice', 'priceSale'],
+          },
+        }, //数量
         {
           field: 'priceSale',
+          type: 'disabled',
+          number: true,
+          digits: 2,
+        }, //价格
+        {
+          field: 'itemAmt',
+          type: 'disabled',
+          digits: 2,
+          number: true,
+          sum: true,
+        }, //金额
+        {
+          field: 'factPrice',
           type: 'number',
           digits: 2,
           formula: {
-            itemAmt: ['itemQty*priceSale', 'itemQty', 'priceSale'],
-            priceDiscount: ['priceSale/priceStd*100', 'priceSale', 'priceStd'],
+            //实际金额 =  数量 *  实际金额
+            factAmt: ['itemQty*factPrice', 'itemQty', 'factPrice'],
+            //标价折扣 =  售价 / 标价 * 100
+            priceDiscount: ['factPrice/priceStd*100', 'factPrice', 'priceStd'],
+            //折扣 = 实际单价/ 售价 *100
+            discount: ['factPrice / priceSale * 100 ', 'factPrice', 'priceSale'],
           },
-        },
-        //数量
+        },//实际价格
         {
-          field: 'itemQty',
+          field: 'factAmt',
           type: 'number',
-          digits:this.decimalPlaces,
+          digits: 2,
+          number: true,
           sum: true,
+          formulaLate: true,
           formula: {
-            itemAmt: ['itemQty*priceSale', 'itemQty', 'priceSale'],
-            amtStd: ['itemQty*priceStd', 'itemQty', 'priceStd'],
-            box: ['itemQty/packBox', 'itemQty', 'packBox'],
-            piece: ['itemQty%packBox', 'itemQty', 'packBox'],
+            //实际单价 =  金额 / 数量
+            factPrice: ['factAmt / itemQty  ', 'priceSale', 'discount'],
+            //折扣 = 实际金额 / 金额
+            discount: ['factAmt /  itemAmt * 100 ', 'factAmt', 'itemAmt'],
+          },
+        },//实际金额.
+        {
+          field: 'discount',
+          type: 'number',
+          number: true,
+          digits: 2,
+          formulaLate: true,
+          formula: {
+            //实际单价 =  售价 * 折扣 / 100 - 优惠金额
+            factPrice: ['priceSale * discount /100 ', 'priceSale', 'discount'],
+            //实际金额 =  数量 *  实际金额
+            factAmt: ['itemQty * factPrice', 'itemQty', 'factPrice'],
           },
+        },//折扣
+        //商品标价
+        {
+          field: 'priceStd',
+          type: 'disabled',
+          number: true,
+          digits: 2,
+        },
+        //标价折扣
+        {
+          field: 'priceDiscount',
+          type: 'disabled',
+          number: true,
+          digits: 2,
         },
         // //包装
         // {
@@ -476,32 +586,6 @@ export default {
           ],
           searchDetailFlag: true
         },
-        //金额
-        {
-          field: 'itemAmt',
-          type: 'number',
-          digits: 2,
-          number: true,
-          sum: true,
-          formula: {
-            priceSale: ['itemAmt/itemQty', 'itemAmt', 'itemQty'],
-            priceDiscount: ['itemAmt/itemQty/priceStd*100', 'itemAmt', 'itemQty', 'priceStd'],
-          },
-        },
-        //商品标价
-        {
-          field: 'priceStd',
-          type: 'disabled',
-          number: true,
-          digits: 2,
-        },
-        //标价折扣
-        {
-          field: 'priceDiscount',
-          type: 'disabled',
-          number: true,
-          digits: 2,
-        },
         //非标号
         {
           field: 'nonStdCode', type: 'text', equal: true,
@@ -553,6 +637,7 @@ export default {
           field: 'remarks', type: 'text', equal: true,
         },
       ],
+      updateTotalFootMessageFlag:false,
     }
   },
 
@@ -730,8 +815,7 @@ export default {
         this.formData.addressGcj02 = value.addressGcj02;
         this.formData.addressFull = value.addressFull + (this.formData.addressNo ? this.formData.addressNo : '');
       }
-    }
-    ,
+    } ,
     /**
      *   @desc   : 拼写详细地址
      *   @date   : 2022/6/9 10:08
@@ -783,6 +867,7 @@ export default {
         +(row['unitName']?(row['nonStandardForm']['piece']?row['unitName']:''):'')
       table[rowIndex]['itemQty'] = row['packBox'] * (row['nonStandardForm']['box']?row['nonStandardForm']['box']:0) + (row['nonStandardForm']['piece'] ?row['nonStandardForm']['piece']:0)
       table[rowIndex]['itemAmt'] = table[rowIndex]['itemQty'] * table[rowIndex]['priceSale']
+      table[rowIndex]['factAmt'] = table[rowIndex]['itemQty'] * table[rowIndex]['factPrice']
       console.log('row',row)
       table[rowIndex]['box'] = row['nonStandardForm']['box']?row['nonStandardForm']['box']:0
       table[rowIndex]['piece'] = row['nonStandardForm']['piece'] ?row['nonStandardForm']['piece']:0
@@ -794,18 +879,28 @@ export default {
      *   @author : 付斌
      */
     getTotals(field, row, rowIndex) {
-      let table = this.$refs['goodsTable'].tableData
-      console.log('table',table)
+      let table = this.$refs['goodsTable'].tableData.filter(it=>it.skuId)
+      console.log('table',JSON.parse(JSON.stringify(table)))
       if (table && table.length > 0) {
         //计算合计
         this.getTotale(table)
         table.forEach(row => {
+          //数量
           if (!row["itemQty"] || row["itemQty"] == '') {
             this.$set(row, 'itemQty', 0);
           }
+          //金额
           if (!row["itemAmt"] || row["itemQty"] == '') {
             this.$set(row, 'itemAmt', 0);
           }
+          //实际金额
+          if (!row["factAmt"] || row["itemQty"] == '') {
+            this.$set(row, 'factAmt', 0);
+          }
+          //折扣
+          if (!row["discount"] || row["discount"] == '') {
+            this.$set(row, 'discount', 0);
+          }
 
           this.decimalPlaces = row['decimalPlaces']
 
@@ -840,8 +935,109 @@ export default {
           }
         })
       }
+
+      //过滤有商品并且不是赠品数据
+      let tableLength = this.$refs['goodsTable'].tableData.filter(it => it.skuId && !it.flgGift).length
+      //region 有价格
+      let hasPriceTable = this.$refs['goodsTable'].tableData.filter(it => it.skuId && it.priceSale > 0 && !it.flgGift)
+      console.log("有价格",hasPriceTable)
+      //endregion
+
+      //region  无价格
+      let noPriceTable = this.$refs['goodsTable'].tableData.filter(it => it.skuId && (!it.priceSale || it.priceSale == 0) && !it.flgGift)
+      console.log("无价格",noPriceTable)
+      if (noPriceTable && noPriceTable.length > 0 && noPriceTable.length == tableLength) {
+        this.updateTotalFootMessageFlag = true
+        for (let i = 0; i < noPriceTable.length; i++) {
+          //折扣禁用
+          noPriceTable[i].readOnly = ['discount']
+        }
+        this.$refs['goodsTable'].$refs['xTable'].refreshColumn();
+      } else {
+        this.updateTotalFootMessageFlag = false
+        for (let i = 0; i < noPriceTable.length; i++) {
+          delete noPriceTable[i].readOnly
+        }
+        this.$refs['goodsTable'].$refs['xTable'].refreshColumn();
+      }
+      //endregion
     },
+    /**
+     *   @desc   : 修改实收金额或者折扣或者优惠金额
+     *   @date   : 2024/6/12 11:01
+     *   @author : 寇珊珊
+     */
+    changeDiscountOrAmount(value ,number){
+      //region  修改实收金额或者折扣或者优惠金额
+      //实收金额
+      if(number ==1){
+        //实收金额
+        this.goodsFootFormData.factAmt = value
+        //优惠金额 = 合计金额 - 实收金额
+        this.goodsFootFormData.discAmt = parseFloat(this.goodsFootFormData.sumAmount - this.goodsFootFormData.factAmt)
+        //总单折扣 = 实收金额 /合计金额
+        if(this.goodsFootFormData.sumAmount>0){
+          this.goodsFootFormData.discount = parseFloat(this.goodsFootFormData.factAmt / this.goodsFootFormData.sumAmount * 100)
+        }
+      }
+      //折扣
+      else if(number ==2){
+        //折扣
+        this.goodsFootFormData.discount = value
+        //实收金额 = 合计金额 * 折扣
+        this.goodsFootFormData.factAmt = parseFloat(this.goodsFootFormData.sumAmount * this.goodsFootFormData.discount)
+        //单优惠金额 = 合计金额 - 实收金额
+        this.goodsFootFormData.discAmt = parseFloat(this.goodsFootFormData.sumAmount -  this.goodsFootFormData.factAmt)
+      }
+      //优惠金额
+      else if(number ==3){
+        //优惠金额
+        this.goodsFootFormData.discAmt = value
+        //实收金额 = 合计金额 - 优惠金额
+        this.goodsFootFormData.factAmt = parseFloat(this.goodsFootFormData.sumAmount - this.goodsFootFormData.discAmt)
+        //折扣 = 实收金额 / 合计金额
+        this.goodsFootFormData.discount = parseFloat(this.goodsFootFormData.factAmt / this.goodsFootFormData.sumAmount * 100)
+      }
+      //endregion
 
+      //region  修改明细
+      let table = this.$refs['goodsTable'].tableData.filter(it => it.skuId && it.priceSale > 0 && !it.flgGift)
+      if (table && table.length > 0) {
+        let  i = 1;
+        let sumFactAmt = 0
+        for (let row of table) {
+          //商品折扣= 折扣
+          row.discount = this.goodsFootFormData.discount
+          if(i<table.length){
+            //实际金额 =  实际单价 * 数量
+            row.factAmt = parseFloat(row.factPrice * row.itemQty)
+            //实际单价 = 售价 * 折扣
+            row.factPrice = parseFloat(row.priceSale * row.discount)
+            sumFactAmt += row.factAmt
+            i++
+          }
+          //最后一条带价格的明细
+          else if(i == table.length){
+            //实际金额 =  实收金额 - 除了最后一条明细的实际金额总和
+            row.factAmt = parseFloat(this.goodsFootFormData.factAmt - sumFactAmt )
+            //实际单价 = 实际金额 / 数量
+            row.factPrice = parseFloat(row.factAmt / row.itemQty)
+          }
+        }
+      }
+      //endregion
+
+      //region 赠品赋值为0
+      let flgGiftList = this.$refs['goodsTable'].tableData.filter(it => it.skuId && it.flgGift)
+      if (flgGiftList && flgGiftList.length > 0) {
+        for (let row of flgGiftList) {
+          row.priceSale = 0
+          row.factPrice = 0
+          row.discount = 0
+        }
+      }
+      //endregion
+    },
     /**
     * @desc   : 计算合计
     * @author : 常皓宁
@@ -851,20 +1047,54 @@ export default {
       let sumQuantity = 0;  // 合计数量
       let sumAmount = 0;    // 货物金额
       let sumStandard = 0;  // 标价总额
+      let factAmt = 0;  // 实际合计金额
       if (table && table.length > 0) {
         table.forEach(row => {
           sumQuantity += parseFloat(row["itemQty"]);
           sumAmount += parseFloat(row["itemAmt"])
           this.$set(row, 'amtStd', parseFloat(row["itemQty"]) * parseFloat(row["priceStd"]));
           sumStandard += parseFloat(row["amtStd"]);
+          // this.$set(row, 'factAmt', parseFloat(row["itemQty"]) * parseFloat(row["factPrice"]));
+          //
+          factAmt += parseFloat(row["factAmt"])
         })
       }
       this.goodsFootFormData.sumQuantity = sumQuantity;
       this.goodsFootFormData.sumAmount = sumAmount;
       this.goodsFootFormData.sumStandard = sumStandard;
       this.goodsFootFormData.saleDiscount = (sumAmount / sumStandard * 100).toFixed(2);
+      //实收金额 = 明细实际金额汇总
+      this.goodsFootFormData.factAmt = factAmt;
+      //优惠金额 = 合计金额 - 实收金额
+      this.goodsFootFormData.discAmt = parseFloat(this.goodsFootFormData.sumAmount - this.goodsFootFormData.factAmt);
+      //折扣 = 实收金额 / 合计金额  *100
+      this.goodsFootFormData.discount = parseFloat(this.goodsFootFormData.factAmt / this.goodsFootFormData.sumAmount * 100 );
+    },
+    /**
+     *   @desc   : 删除明细行
+     *   @date   : 2024/6/12 9:44
+     *   @author : 寇珊珊
+     */
+    delRow(row, rowIndex){
+      let list = this.$refs['goodsTable'].tableData.filter(it => it.skuId)
+      if (list && list.length > 0) {
+        let table = this.$refs['goodsTable'].tableData.filter(it => it.priceSale > 0)
+        if (table && table.length == 0) {
+          this.$IBMessage({
+              content: this.$t('Q_002', {'param': this.$v('删除唯一有价格的商品后重新计算价格')}),
+              title: this.$t('systemQuestion')
+            },
+            {
+              ok: () => {
+                this.getTotals(this.$refs['goodsTable'].tableData)
+              },
+              cancel: () => {
+                this.$refs['goodsTable'].tableData.push(row);
+              }
+            })
+        }
+      }
     },
-
     /**
      * @desc   : 通过id查询
      * @author : 付斌