From 875113ca076c613503c3ad4e663f16fde7a68440 Mon Sep 17 00:00:00 2001
From: lkk <364857242@qq.com>
Date: 星期五, 10 一月 2025 18:06:32 +0800
Subject: [PATCH] sl

---
 src/views/system/comp/index.vue |   97 +++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 74 insertions(+), 23 deletions(-)

diff --git a/src/views/system/comp/index.vue b/src/views/system/comp/index.vue
index ea5f569..e835cee 100644
--- a/src/views/system/comp/index.vue
+++ b/src/views/system/comp/index.vue
@@ -336,31 +336,31 @@
                 <el-input ref="inputName" v-model="queryParams.price" placeholder="鍚堣" clearable style="width: 140px" />
               </el-form-item>
               <el-form-item label="浼樻儬">
-                <el-input-number ref="inputNumber" style="width: 150px" v-model="youhui" :precision="2" :step="0.1"
-               :min="0" @change="numberChange"></el-input-number>
+                <el-input-number ref="inputNumber" style="width: 150px" v-model="youhui" :precision="1" :step="0.1"
+                  :min="0" :max="20" @change="debounceNumberChange" :debounce="3000"></el-input-number>
               </el-form-item>
               <el-form-item label="鐜颁环">
                 <el-input ref="inputName" v-model="queryParams.xianprice" placeholder="鍚堣" clearable
-                  style="width: 140px" />
+                  style="width: 140px" @input="changeXianjia" @blur="numberChangeXianPrice(youhui, youhui)" />
               </el-form-item>
               <el-form-item>
                 <el-button icon="el-icon-refresh" size="mini" @click="resetQuerys">閲嶇疆</el-button>
               </el-form-item>
             </el-form>
             <el-table border v-loading="loading" :data="OnenewpacName" :row-class-name="tableRowClassName" height="478">
-              <el-table-column label="椤圭洰鍚嶇О" align="center" prop="proName" width="486">
+              <el-table-column label="椤圭洰鍚嶇О" align="center" prop="proName" width="410">
 
                 <template slot-scope="scope">
                   {{ scope.row.proName }}
                 </template>
               </el-table-column>
               <el-table-column label="鍘熶环" align="center" prop="proPrice" width="85"></el-table-column>
-              <el-table-column label="鎶樻墸" width="85">
+              <el-table-column label="鎶樻墸" width="151">
                 <template slot-scope="scope">
                   <!-- 鍙緭鍏ョ函鏁板瓧鎶樻墸 -->
-                  <el-input v-model.number="scope.row.limits" @input="validateDiscount(scope.row)" placeholder="杈撳叆鎶樻墸"
-                    size="small" type="number" min="0" step="1" max="10">
-                  </el-input>
+                  <el-input-number v-model.number="scope.row.limits"
+                    placeholder="杈撳叆鎶樻墸" size="small" type="number" :min="0" :step="0.1" :precision="1" :max="20">
+                  </el-input-number>
                 </template>
               </el-table-column>
               <el-table-column label="鐜颁环" align="center" prop="ysPrice" width="85"></el-table-column>
@@ -428,7 +428,7 @@
               </el-table-column>
             </el-table>
             <div style="font-size: 16px;margin-top: 10px;">椤圭洰鎬绘潯鏁帮細<span style="font-weight: 700;margin-right: 5px;">{{
-                newpacName.length }}</span>鏉�</div>
+              newpacName.length }}</span>鏉�</div>
           </el-col>
           <el-col :span="8" :xs="24">
             <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="46px"
@@ -459,8 +459,8 @@
           <el-col :span="2" :xs="24">
             <div style="margin: 240% 16%">
               <el-button type="primary" size="medium " icon="el-icon-back"
-                style="writing-mode: vertical-rl; text-align: center;letter-spacing: 10px;"
-                @click="resetright">纭� 璁�</el-button>
+                style="writing-mode: vertical-rl; text-align: center;letter-spacing: 10px;" @click="resetright">纭�
+                璁�</el-button>
             </div>
           </el-col>
           <el-col :span="8" :xs="24">
@@ -804,24 +804,30 @@
     this.getList();
   },
   methods: {
-    validateDiscount(row) {
-      if (row.limits > 10) {
-        row.limits = 10; // 寮哄埗灏嗗�艰缃负鏈�澶у��
-      } else if (row.limits < 0) {
-        row.limits = 0; // 寮哄埗灏嗗�艰缃负鏈�灏忓��
+    debounceNumberChange(currentValue, oldValue) {
+      clearTimeout(this.debounceTimer);
+      this.debounceTimer = setTimeout(() => {
+        this.numberChange(currentValue, oldValue);
+      }, 300);
+    },
+    changeXianjia() {
+      // 鍘熷鎶樻墸鐜囪绠�
+
+
+      if (this.queryParams.price !== 0) {
+        this.youhui = (Math.floor((this.queryParams.xianprice / this.queryParams.price) * 100) / 100) * 10;
       }
-      this.updateProPrice(row); // 鏇存柊浠锋牸鎴栧叾浠栭�昏緫
+
     },
     updateProPrice(row) {
-
       const proPrice = new Big(row.proPrice);
 
       const limits = new Big(row.limits);
       const result = proPrice.times(limits.div(10));  // ordPrice * (discount / 10)
       row.ysPrice = result.toNumber();
-      this.queryParams.xianprice = this.OnenewpacName.reduce((sum, item) => {
-        return sum.plus(new Big(item.ysPrice || '0'));
-      }, new Big(0)).toNumber();
+      // this.queryParams.xianprice = this.OnenewpacName.reduce((sum, item) => {
+      //   return sum.plus(new Big(item.ysPrice || '0'));
+      // }, new Big(0)).toNumber();
       this.youhui = (Math.floor((this.queryParams.xianprice / this.queryParams.price) * 100) / 100) * 10
     },
     getList() {
@@ -909,7 +915,7 @@
       this.handleQuery();
     },
     resetQuerys() {
-        this.OnenewpacName = [],
+      this.OnenewpacName = [],
         this.queryParams.price = 0,
         this.queryParams.xianprice = 0,
         this.youhui = 0
@@ -1002,6 +1008,7 @@
             const limits = new Big(item.limits);
             const result = proPrice.times(limits.div(10));  // ordPrice * (discount / 10)
             item.ysPrice = result.toNumber();
+            console.log("numberChange")
             this.queryParams.xianprice = this.OnenewpacName.reduce((sum, item) => {
               return sum.plus(new Big(item.ysPrice || '0'));
             }, new Big(0));
@@ -1014,6 +1021,50 @@
         });
 
     },
+    numberChangeXianPrice(currentValue, oldValue) {
+      this.$confirm("纭畾淇敼鎵�鏈夊瓙椤圭殑鎶樻墸鍚楋紵", "鎻愮ず", {
+        confirmButtonText: "纭畾",
+        cancelButtonText: "鍙栨秷",
+        type: "warning",
+      })
+        .then(() => {
+          // 纭繚淇敼鎶樻墸鐨勫��
+          this.youhui = currentValue;
+          // 濡傛灉鎶樻墸灏忎簬鏈�灏忔姌鎵e�硷紝淇鎶樻墸
+          if (this.youhui < this.getInfodis) {
+            this.youhui = this.getInfodis;
+          }
+          let totalYsprice = new Big(0); // 鍒濆鍖栨�� ysprice
+          // 閬嶅巻姣忎釜椤圭洰锛屾洿鏂版瘡涓瓙椤圭殑浠锋牸
+          this.OnenewpacName.forEach((item) => {
+            item.limits = this.youhui;
+            const proPrice = new Big(item.proPrice);
+            const limits = new Big(item.limits);
+            const result = proPrice.times(limits.div(10));  // ordPrice * (discount / 10)
+            item.ysPrice = result.toNumber();
+            totalYsprice = totalYsprice.plus(new Big(item.ysPrice));
+          });
+          // 濡傛灉鎬荤殑 ysPrice 鍜屾煡璇㈠弬鏁颁腑鐨� xianprice 涓嶄竴鑷达紝杩涜璋冩暣
+          if (!totalYsprice.eq(this.queryParams.xianprice)) {
+            const diff = new Big(this.queryParams.xianprice).minus(totalYsprice);
+            // 濡傛灉 OnenewpacName 鏁扮粍涓嶄负绌猴紝璋冩暣鏈�鍚庝竴椤圭殑 ysPrice
+            if (this.OnenewpacName.length > 0) {
+              const lastItem = this.OnenewpacName[this.OnenewpacName.length - 1];
+              const newYsPrice = new Big(lastItem.ysPrice).plus(diff).toNumber();
+              // 浣跨敤 splice 鏇挎崲鏈�鍚庝竴椤癸紝纭繚鏇存柊瑙﹀彂瑙嗗浘鏇存柊
+              console.log("hhh");
+
+              this.$set(this.OnenewpacName[this.OnenewpacName.length - 1], 'ysPrice', newYsPrice);
+
+            }
+          }
+        })
+        .catch(() => {
+          // 濡傛灉鍙栨秷淇敼锛屾仮澶嶅師鏈夌殑浼樻儬鍊�
+          this.youhui = oldValue;
+        });
+    },
+
 
     changegroupingName() {
       if (this.selectionList.length <= 0) {
@@ -1134,7 +1185,7 @@
           const existingItem = this.OnenewpacName.find(existing => existing.proId === item.proId);
           if (!existingItem) {
             newItemsToAdd.push(item); // 濡傛灉涓嶅瓨鍦ㄧ浉鍚岄」鐩紝鍒欐坊鍔犲埌鏂版暟缁�
-            this.updateProPrice(item); // 鏇存柊鍗曚釜椤圭洰鐨勪环鏍�
+            this.updateProPrice(item);
           }
         });
 

--
Gitblit v1.8.0