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

fix: 退货单对话框优化总金额计算逻辑,提取公共变量减少重复代码

yusheng пре 9 месеци
родитељ
комит
9711841866

+ 8 - 11
src/views/saleManage/saleOrder/returnGoods/components/addReturnGoodsDialog.vue

@@ -388,16 +388,17 @@
     computed: {
       totalAmount() {
         let allcountAmount = 0;
+        let totalAmount =
+          (this.$refs.inventoryTableref &&
+            this.$refs.inventoryTableref.totalAmount) ||
+          0;
         if (this.form.returnSourceType == 1) {
           if (this.form.type === '10') {
-            allcountAmount =
-              this.$refs.inventoryTableref &&
-              this.$refs.inventoryTableref.totalAmount;
+            allcountAmount = Number(totalAmount);
           }
           if (this.form.type === '20') {
             allcountAmount =
-              (this.$refs.inventoryTableref &&
-                this.$refs.inventoryTableref.totalAmount) +
+              Number(totalAmount) +
               Number(
                 this.$refs.inventoryTableref1 &&
                   this.$refs.inventoryTableref1.getPrice()[0]
@@ -405,9 +406,7 @@
           }
           if (this.form.type === '30') {
             allcountAmount =
-              (this.$refs.inventoryTableref &&
-                this.$refs.inventoryTableref.totalAmount) +
-              Number(this.form.redressAmount || 0);
+              Number(totalAmount) + Number(this.form.redressAmount || 0);
           }
           if (this.form.type === '40') {
             allcountAmount =
@@ -418,9 +417,7 @@
             allcountAmount = Number(this.form.redressAmount || 0);
           }
         } else {
-          allcountAmount =
-            this.$refs.inventoryTableref &&
-            this.$refs.inventoryTableref.totalAmount;
+          allcountAmount = Number(totalAmount);
         }
 
         return parseFloat(allcountAmount).toFixed(2);