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

fix(付款计划): 修复付款计划金额计算和验证逻辑

liujt 4 месяцев назад
Родитель
Сommit
f767173287

+ 30 - 16
src/BIZComponents/paymentCollectionPlan/Index.vue

@@ -155,7 +155,7 @@
             <el-input
                 type="number"
                 :min="0"
-                :disabled="type=='view'"
+                disabled
                 v-model="scope.row.price"
                 style="width: 100%"
                 placeholder="请输入"
@@ -259,8 +259,8 @@
           datasource: []
         },
         paymentTypeOp,
-
-        rules: {}
+        rules: {},
+        isLoadingFromApi: false
       };
     },
     computed: {
@@ -268,9 +268,9 @@
         return this.form.datasource.length;
       },
       showAddBtn() {
-        // console.log('showAddBtn~~~~', this.type, this.info.settlementMode);
+        // console.log('showAddBtn~~~~', this.type, this.info);
         // console.log('showAddBtn!!!!',!['1', '2'].includes(this.info.settlementMode) || this.type != 'view');
-        return !(['1', '2'].includes(this.info?.settlementMode)) && this.type != 'view'
+        return !(['1', '2'].includes(this.info?.settlementMode)) && this.type != 'view' 
       },
       columns() {
         return [
@@ -357,15 +357,23 @@
     },
     watch: {
       discountAmount(newval) {
-        if (newval) {
+        if (newval && !this.isLoadingFromApi) {
           this.refreshprice();
         }
       },
       info: {
         handler(newval) {
-          if (newval) {
-            // this.form = newval;
-            console.log('111111', newval.settlementMode);
+          if (newval && newval.receiptPaymentList) {
+            // Directly assign API data to table without calculation
+            this.isLoadingFromApi = true;
+            this.form.datasource = newval.receiptPaymentList;
+            if (newval.payAmount) {
+              this.discountAmount = newval.payAmount;
+            }
+            // Reset flag after a short delay to avoid affecting subsequent user changes
+            setTimeout(() => {
+              this.isLoadingFromApi = false;
+            }, 100);
           }
         },
         deep: true
@@ -374,27 +382,33 @@
     methods: {
       setDiscountAmount(val) {
         console.log(val, '000000');
+        this.isLoadingFromApi = true;
         this.discountAmount = val;
+        setTimeout(() => {
+          this.isLoadingFromApi = false;
+        }, 100);
       },
       typeChange(val, index = null) {
-        console.log(val, index, '55555');
+        // console.log(val, index, '55555');
         if (val) {
           this.$set(this.form.datasource[index], 'typeName', this.paymentTypeOp.find(item => item.value === val).label);
         }
       },
       //输入比例更新金额
       async ratioInput(val, index = null) {
-        console.log(this.discountAmount, '77777');
+        // console.log(this.discountAmount, '77777');
+        // console.log(val, '5555555');
         val = Number(val);
         try {
           if (index != null) {
             await this.checkRatio();
           }
           let newval = (val / 100).toFixed(2);
+          // console.log('newval~~~', newval)
           let price = (this.discountAmount * newval).toFixed(2);
-          console.log(newval, price, index, '88888');
+          // console.log(newval, price, index, '88888');
           if (index != null) {
-            console.log(newval, price, index, '999999');
+            // console.log(newval, price, index, '999999');
             this.$set(this.form.datasource[index], 'price', price);
           } else {
             return price;
@@ -415,7 +429,7 @@
               sum += Number(r.ratio);
             }
           });
-          console.log(sum, '3333333');
+          // console.log(sum, '3333333');
           if (sum > 100) {
             this.$message.error('总共比例不能超过100');
             this.$set(
@@ -435,7 +449,7 @@
         });
       },
       refreshprice() {
-        console.log(this.form, '666666');
+        // console.log(this.form, '666666');
         let newData = this.form.datasource;
         newData.forEach(async (r, index) => {
           if (r.ratio) {
@@ -450,7 +464,7 @@
       },
       //修改回显
       putTableValue(data) {
-        console.log('data~~~~', data);
+        console.log('data~~~~111', data);
         if (data) {
           this.form.datasource = data.receiptPaymentList;
           this.setDiscountAmount(data.payAmount);

+ 20 - 9
src/views/purchasingManage/purchaseOrder/components/addDialogNew.vue

@@ -578,6 +578,7 @@
       <PaymentCollectionPlan
         ref="paymentCollectionPlanRef"
         menu="purchase"
+        :info="form"
       ></PaymentCollectionPlan>
 
     </el-form>
@@ -1691,7 +1692,7 @@
         this.loading = false;
         data.settlementDate = data.startSettlementDate ? [data.startSettlementDate, data.endSettlementDate] : [];
         this.form = data;
-        console.log('data~~~~~~~', data);
+        console.log('data~~~~~~~000', data);
         if (data) {
           this.$nextTick(() => {
             this.$store.commit('order/setAllcountAmount', data.totalAmount);
@@ -1943,8 +1944,7 @@
           await this.getEnterprisePage();
         }
         if (type == 'add') {
-          console.log('enterprisePage~~~~~', this.enterprisePage);
-          console.log()
+          // console.log('enterprisePage~~~~~', this.enterprisePage);
           this.isUpdate = false;
           if (this.enterprisePage.length > 0) {
             this.form.partaName = this.enterprisePage[0]?.name;
@@ -2158,18 +2158,29 @@
             startSettlementDate: this.form.settlementDate.length ? this.form.settlementDate[0] : ''
           });
 
-          const receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.price, 0);
-          if(+receiptPaymentListSum != +commitData.payAmount){
-            this.$message.error('计划收款金额合计与优惠后金额不一致');
-            return;
-          }
-
           const ratioSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.ratio, 0);
           if(+ratioSum != 100){
             this.$message.error('比例合计必须为100%');
             return;
           }
 
+          let receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.price, 0);
+          const payAmount = +commitData.payAmount;
+          
+          if(+ratioSum == 100) {
+            const difference = payAmount - receiptPaymentListSum;
+            if (Math.abs(difference) > 0 && commitData.receiptPaymentList.length > 0) {
+              const lastIndex = commitData.receiptPaymentList.length - 1;
+              commitData.receiptPaymentList[lastIndex].price = (+commitData.receiptPaymentList[lastIndex].price + difference).toFixed(2);
+              receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.price, 0);
+            }
+          }
+
+          if(Math.abs(+receiptPaymentListSum - payAmount) > 0){
+            this.$message.error('计划收款金额合计与优惠后金额不一致');
+            return;
+          }
+
           if (this.isUpdate) {
             UpdateInformation(commitData)
               .then((res) => {

+ 1 - 0
src/views/saleManage/saleOrder/components/addDialogNew.vue

@@ -649,6 +649,7 @@
         <PaymentCollectionPlan
           ref="paymentCollectionPlanRef"
           menu="sale"
+          :info="form"
         ></PaymentCollectionPlan>
       </div>