Prechádzať zdrojové kódy

feat: 优化金额计算逻辑,添加有效金额选择和汇总功能

xieyong 21 hodín pred
rodič
commit
da34b59f44
1 zmenil súbory, kde vykonal 54 pridanie a 21 odobranie
  1. 54 21
      src/BIZComponents/inventoryTableDetails.vue

+ 54 - 21
src/BIZComponents/inventoryTableDetails.vue

@@ -113,7 +113,9 @@
       <template v-slot:toolbar>
         <div class="headbox">
           <div class="pricebox">
-            <span class="amount" v-if="showSummary">数量合计:{{ allQuantity }}</span>
+            <span class="amount" v-if="showSummary"
+              >数量合计:{{ allQuantity }}</span
+            >
             <span class="amount" v-if="isAllPrice">总计:{{ allPrice }}元</span>
             <span class="amount" v-if="isDiscountTotalPrice"
               >优惠后总金额:{{ form.discountTotalPrice }}元</span
@@ -138,7 +140,12 @@
     matchInventoryTotal
   } from '@/api/wms';
   import { getSummaries } from '@/utils/util.js';
-  import { getAllQuantity } from '@/BIZComponents/setProduct.js';
+  import {
+    getAllQuantity,
+    getAllPrice,
+    getAllDiscountPrice,
+    formatPrice
+  } from '@/BIZComponents/setProduct.js';
 
   const dayjs = require('dayjs');
 
@@ -184,7 +191,10 @@
         type: Boolean,
         default: false
       },
-      cacheKeyUrl: '',
+      cacheKeyUrl: {
+        type: String,
+        default: ''
+      },
       //是否显示订单编码
       isOrderNo: {
         type: Boolean,
@@ -540,7 +550,7 @@
             prop: 'warehouseName',
             label: '仓库名称',
             slot: 'warehouseName',
-            align: 'center',
+            align: 'center'
           },
           {
             minWidth: 160,
@@ -555,7 +565,7 @@
             prop: 'availableCountBase',
             label: this.isWms ? '可用数量' : '库存数量',
             showOverflowTooltip: true,
-            align: 'center',
+            align: 'center'
           },
           {
             minWidth: 140,
@@ -667,8 +677,10 @@
             align: 'center',
             isNone: !this.isDiscount,
             formatter: (_row, _column, cellValue) => {
-              return this.quoteTypeOp.find((item) => item.value == _row.quoteWay)
-                ?.label || '';
+              return (
+                this.quoteTypeOp.find((item) => item.value == _row.quoteWay)
+                  ?.label || ''
+              );
             }
           },
           {
@@ -970,11 +982,7 @@
     },
     methods: {
       getSummaries(param) {
-        return getSummaries(
-          param,
-          ['saleCount'],
-          ' '
-        );
+        return getSummaries(param, ['saleCount'], ' ');
       },
       handleDone() {
         if (this.isSelected) {
@@ -1021,6 +1029,39 @@
       handleMethod(row) {
         this.$refs.timeDialogDialogRef.open(row);
       },
+      /**
+       * 取第一个有效金额,全部无效时回退到 fallback。
+       * 注意不能直接用 ||,否则接口正常返回的 0 会被当成无效值跳过。
+       */
+      pickAmount(candidates, fallback) {
+        const hit = candidates.find(
+          (v) => v !== null && v !== undefined && v !== '' && !isNaN(Number(v))
+        );
+        const num = Number(hit === undefined ? fallback : hit);
+        return isNaN(num) ? 0 : formatPrice(num);
+      },
+      // 汇总:总计 / 数量合计 / 优惠后总金额
+      setAmount(data = {}) {
+        this.allQuantity =
+          getAllQuantity(this.form.datasource, this.countObj) || 0;
+        // 总计:优先用接口返回的总金额,接口未返回时按明细行合计兜底
+        this.allPrice = this.pickAmount(
+          [data.totalAmount, data.totalPrice, data?.contractVO?.totalPrice],
+          getAllPrice(this.form.datasource)
+        );
+        if (this.isDiscountTotalPrice) {
+          // 优惠后总金额:接口未返回时按明细行折让合计兜底,无折让时等于总计
+          this.form.discountTotalPrice = this.pickAmount(
+            [
+              data.payAmount,
+              data.discountTotalPrice,
+              data?.contractVO?.discountTotalPrice
+            ],
+            Number(getAllDiscountPrice(this.form.datasource)) ||
+              Number(this.allPrice)
+          );
+        }
+      },
       setDeliveryDays() {
         console.log(this.form.datasource, 'this.form.datasource');
         this.form.datasource.forEach((item, i) => {
@@ -1078,15 +1119,7 @@
           });
 
           this.form.datasource = productList;
-          this.allPrice =
-            data.totalAmount || data.totalPrice || data?.contractVO?.totalPrice;
-          this.allQuantity = getAllQuantity(this.form.datasource, this.countObj)  
-          if (this.isDiscountTotalPrice) {
-            this.form.discountTotalPrice =
-              data.payAmount ||
-              data.discountTotalPrice ||
-              data?.contractVO?.discountTotalPrice;
-          }
+          this.setAmount(data);
           if (this.isWms) {
             let codeList = this.form.datasource
               .filter((item) => item.productCode)