From cee2eca9c3e40b48c40a8fe80f938a777f03d463 Mon Sep 17 00:00:00 2001
From: wwl <xchao828@163.com>
Date: 星期二, 10 六月 2025 17:57:11 +0800
Subject: [PATCH] 1

---
 src/views/system/package/index.vue |  104 ++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 69 insertions(+), 35 deletions(-)

diff --git a/src/views/system/package/index.vue b/src/views/system/package/index.vue
index 65eea47..af9f3af 100644
--- a/src/views/system/package/index.vue
+++ b/src/views/system/package/index.vue
@@ -57,7 +57,7 @@
         <el-table-column label="濂楅鍚嶇О" align="center" prop="pacName" width="150px" fixed />
         <el-table-column label="鍘熶环" width="80px" align="center" prop="price" fixed></el-table-column>
         <el-table-column label="鎶樻墸" width="80px" align="center" prop="limits" fixed></el-table-column>
-        <el-table-column label="浼樻儬浠�" width="80px" align="center" prop="newPrice" fixed>
+        <el-table-column label="鐜颁环" width="80px" align="center" prop="newPrice" fixed>
         </el-table-column>
         <el-table-column label="鍗曢」鍒楄〃" align="center" prop="allProName" width="1200px">
         </el-table-column>
@@ -206,7 +206,7 @@
 
         <el-form-item label="鐜颁环" prop="xianprice">
           <el-input v-model="form.xianprice" placeholder="鐜颁环" clearable style="width: 140px" @input="changeXianjia"
-            @blur="numberChangeXianPrice(youhui, youhui)" type="number" :debounce="3000"/>
+            type="number" :debounce="3000" min="0"/>
         </el-form-item>
         <el-form-item label="鍏抽敭瀛�" prop="keywords">
           <el-select multiple v-model="form.keywords" placeholder="璇烽�夋嫨鍏抽敭瀛�" style="width: 160px" @change="sel" filterable
@@ -335,7 +335,7 @@
                   </el-input>
                 </template>
               </el-table-column>
-              <el-table-column prop="priceNow" label="浼樻儬浠�" width="80px" align="center">
+              <el-table-column prop="priceNow" label="鐜颁环" width="80px" align="center">
               </el-table-column>
               <el-table-column label="鎿嶄綔" align="center" width="80px">
                 <template slot-scope="scope">
@@ -486,8 +486,11 @@
       },
       forms: {},
       youhui: 10,
+      initializing: true, // 鍒濆鍖栨爣蹇�
       debounceTimer: null,
-      rules: {},
+      rules: {
+       
+      },
     };
   },
   created() {
@@ -495,6 +498,7 @@
     this.getKeyword();
     this.getCategory();
   },
+ 
   methods: {
     debounceNumberChange(currentValue, oldValue) {
       clearTimeout(this.debounceTimer);
@@ -502,30 +506,7 @@
         this.numberChange(currentValue, oldValue);
       }, 300);
     },
-    numberChange(currentValue, oldValue) {
-      this.$confirm("纭畾淇敼鎵�鏈夊瓙椤圭殑鎶樻墸鍚楋紵", "鎻愮ず", {
-        confirmButtonText: "纭畾",
-        cancelButtonText: "鍙栨秷",
-        type: "warning",
-      })
-        .then(() => {
-          this.youhui = currentValue;
-          this.DataList.forEach((item) => {
-            item.limits = this.youhui;
-            const proPrice = new Big(item.priceOrd);
-            const limits = new Big(item.limits);
-            const result = proPrice.times(limits.div(10));
-            item.priceNow = result.toNumber();
-          });
-          this.form.xianprice = this.DataList.reduce((sum, item) => {
-            return sum.plus(new Big(item.priceNow || "0"));
-          }, new Big(0)).toNumber();
-          this.lastXianPrice = this.form.xianprice;
-        })
-        .catch(() => {
-          this.youhui = oldValue;
-        });
-    },
+   
     updateProPrice(row) {
       const proPrice = new Big(row.priceOrd);
       const limits = new Big(row.limits);
@@ -606,6 +587,7 @@
         counterPrice: null,
         limits: 10,
       };
+      this.initializing = true; 
       this.resetForm("form");
     },
     handleQuery() {
@@ -647,6 +629,7 @@
       this.checkedListkey = [];
       this.checkedNodes = [];
       this.getDataList();
+      this.youhui = 10
     },
     handleStatusChange(row) {
       let data = {
@@ -664,6 +647,7 @@
         });
     },
     handleUp() {
+      this.reset();
       this.title = "浣撴濂楅淇℃伅缁存姢";
       this.open = true;
       getPacInFo(this.forms.pacId).then((response) => {
@@ -692,7 +676,7 @@
       getPacInFo(row.pacId).then((response) => {
         const data = response.data || {};
         Object.keys(data).forEach((key) => {
-          this.$set(this.form, key, data[key]);
+          this.$set(this.form, key, response.data[key]);
         });
         this.youhui = data.limits || 10;
         this.pics = data.price || 0;
@@ -705,7 +689,9 @@
         this.checkedkey = this.DataList.map(item => item.proId || '');
         this.checkedListkey = [...this.checkedkey];
         this.checkedNodes = [...this.checkedkey];
+        
         return this.getDataList();
+       
       }).then(() => {
         this.loading = false;
         this.$nextTick(() => {
@@ -714,7 +700,6 @@
       }).catch((error) => {
         this.loading = false;
         this.$message.error("鍔犺浇鏁版嵁澶辫触");
-        console.error(error);
       });
     },
     addmembers() {
@@ -824,7 +809,9 @@
         this.pics = this.DataList.reduce((total, item) => total + item.priceOrd, 0);
         this.$nextTick(() => {
           this.$refs.tree.setCheckedKeys(this.checkedNodes);
+          this.initializing = false;
         });
+       
       });
       this.loading = false;
     },
@@ -836,6 +823,9 @@
       });
     },
     handleCurrentChecked(data, checked, indeterminate) {
+      if (this.initializing) {
+        return; // 鍒濆鍖栨椂涓嶅鐞�
+      }
       if (checked) {
         if (!this.DataList.some((item) => item.proId === data.proId)) {
           this.DataList.push({
@@ -849,14 +839,16 @@
         if (!this.checkedNodes.includes(data.proId)) {
           this.checkedNodes.push(data.proId);
         }
+        this.updateTotalPrice();
       } else {
         this.DataList = this.DataList.filter((item) => item.proId !== data.proId);
         const index = this.checkedNodes.indexOf(data.proId);
         if (index > -1) {
           this.checkedNodes.splice(index, 1);
         }
+        this.updateTotalPrice();
       }
-      this.updateTotalPrice();
+     
     },
     updateTotalPrice() {
       this.form.xianprice = this.DataList.reduce((sum, item) => {
@@ -869,7 +861,7 @@
         this.youhui = (Math.floor((this.form.xianprice / this.pics) * 100) / 100) * 10;
       }
     },
-    numberChangeXianPrice(currentValue, oldValue) {
+   /*  numberChangeXianPrice(currentValue, oldValue) {
       if (this.form.xianprice === this.lastXianPrice || !this.form.xianprice) return;
       clearTimeout(this.debounceTimer);
       this.debounceTimer = setTimeout(() => {
@@ -903,7 +895,7 @@
             this.youhui = oldValue;
           });
       }, 500);
-    },
+    }, */
     spliceData() {
       for (var i = 0; i < this.DataList.length; i++) {
         for (var j = i + 1; j < this.DataList.length; j++) {
@@ -932,6 +924,47 @@
       this.TotalPrice1 = this.DataList.reduce((sum, item) => sum + item.priceOrd, 0);
     },
     submitForm() {
+      // 妫�鏌ョ幇浠锋槸鍚﹀彂鐢熷彉鍖�
+      if (this.form.xianprice !== this.lastXianPrice) {
+        this.$confirm("纭畾淇敼鎵�鏈夊瓙椤圭殑鎶樻墸鍚楋紵", "鎻愮ず", {
+          confirmButtonText: "纭畾",
+          cancelButtonText: "鍙栨秷",
+          type: "warning",
+        }).then(() => {
+          // 鏇存柊鎵�鏈夊瓙椤圭殑鎶樻墸
+          this.youhui = (Math.floor((this.form.xianprice / this.pics) * 100) / 100) * 10;
+          let totalYsprice = new Big(0);
+          this.DataList.forEach((item) => {
+            item.limits = this.youhui;
+            const ordPrice = new Big(item.priceOrd);
+            const discount = new Big(item.limits);
+            const result = ordPrice.times(discount.div(10));
+            item.priceNow = result.toNumber();
+            totalYsprice = totalYsprice.plus(new Big(item.priceNow));
+          });
+          
+          if (!totalYsprice.eq(this.form.xianprice)) {
+            const diff = new Big(this.form.xianprice).minus(totalYsprice);
+            if (this.DataList.length > 0) {
+              const lastItem = this.DataList[this.DataList.length - 1];
+              const newYsPrice = new Big(lastItem.priceNow).plus(diff).toNumber();
+              this.$set(this.DataList[this.DataList.length - 1], "priceNow", newYsPrice);
+            }
+          }
+          
+          // 淇濆瓨鏁版嵁
+          return this.saveData();
+        }).catch(() => {
+          // 鐢ㄦ埛鍙栨秷鎿嶄綔锛屾仮澶嶅師鏉ョ殑鐜颁环
+          this.form.xianprice = this.lastXianPrice;
+        });
+      } else {
+        // 鐜颁环娌℃湁鍙樺寲锛岀洿鎺ヤ繚瀛�
+        this.saveData();
+      }
+    },
+    // 鏂板涓�涓柟娉曞鐞嗕繚瀛橀�昏緫
+    saveData() {
       this.form.limits = this.youhui;
       this.form.price = this.pics;
       this.form.priceNow = this.form.xianprice;
@@ -952,7 +985,7 @@
         pacName: this.form.pacName,
         limits: this.form.limits,
         pacStatus: this.form.pacStatus,
-        packageProjects: packageProjects,
+        packageProjects: packageProjects, 
         newPrice: this.form.xianprice,
         price: this.pics,
         pacId: this.form.pacId || null,
@@ -963,7 +996,8 @@
         pacRemark: this.form.pacRemark,
         detail: this.form.detail,
       };
-      saveOreditTjPacNew(data).then((res) => {
+      
+      return saveOreditTjPacNew(data).then((res) => {
         this.open = false;
         this.getList();
       });

--
Gitblit v1.8.0