From 7fa5cdd283a6323f405a7cffc43c1c0e054ccca6 Mon Sep 17 00:00:00 2001
From: lkk <364857242@qq.com>
Date: 星期二, 07 一月 2025 13:55:55 +0800
Subject: [PATCH] age

---
 src/views/system/comp/index.vue |  148 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 102 insertions(+), 46 deletions(-)

diff --git a/src/views/system/comp/index.vue b/src/views/system/comp/index.vue
index 3163714..9c97373 100644
--- a/src/views/system/comp/index.vue
+++ b/src/views/system/comp/index.vue
@@ -31,7 +31,7 @@
       </el-col>
       <el-col :span="1.5">
         <el-button type="primary" icon="el-icon-edit" size="mini" :disabled="single" @click="mainDepartment"
-          v-hasPermi="['system:comp:edit']">缁存姢閮ㄩ棬</el-button>
+          v-hasPermi="['system:comp:edit']">缁存姢濂楅</el-button>
       </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
@@ -121,8 +121,8 @@
           <el-col :span="7" :xs="24">
             <div style="padding: 0 20px">
               <el-form ref="form" :model="form" :rules="rules" label-width="80px" :inline="true">
-                <el-form-item label="閮ㄩ棬鍚嶇О" prop="dwDeptName">
-                  <el-input v-model="form.dwDeptName" placeholder="璇疯緭鍏ラ儴闂ㄥ悕绉�" />
+                <el-form-item label="濂楅鍚嶇О" prop="dwDeptName">
+                  <el-input v-model="form.dwDeptName" placeholder="璇疯緭鍏ュ椁愬悕绉�" />
                 </el-form-item>
                 <el-form-item label="绛剧害閲戦" prop="signingPrice">
                   <el-input v-model="form.signingPrice" placeholder="璇疯緭鍏ョ绾﹂噾棰�" />
@@ -131,7 +131,7 @@
               <el-row :gutter="10" class="mb8">
                 <el-col :span="1.5">
                   <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddDept"
-                    v-hasPermi="['system:comp:add']">淇濆瓨閮ㄩ棬</el-button>
+                    v-hasPermi="['system:comp:add']">淇濆瓨濂楅</el-button>
                 </el-col>
                 <el-col :span="1.5">
                   <el-button type="primary" icon="el-icon-edit" size="mini" :disabled="singleg" @click="handledeleDept"
@@ -141,7 +141,7 @@
               <el-table ref="tb" v-loading="loading" :data="deptList" @selection-change="handleSelection" border
                 style="width: 320px" height="350">
                 <el-table-column type="selection" width="40px" align="center" />
-                <el-table-column label="閮ㄩ棬鍚嶇О" align="center" prop="dwDeptName" />
+                <el-table-column label="濂楅鍚嶇О" align="center" prop="dwDeptName" />
               </el-table>
             </div>
           </el-col>
@@ -333,8 +333,8 @@
                 <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" :max="10" :min="1"></el-input-number>
+                <el-input-number ref="inputNumber" style="width: 150px" v-model="youhui" :precision="2" :step="0.1"
+                  :max="10" :min="1" @change="numberChange"></el-input-number>
               </el-form-item>
               <el-form-item label="鐜颁环">
                 <el-input ref="inputName" v-model="queryParams.xianprice" placeholder="鍚堣" clearable
@@ -372,8 +372,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="11" :xs="24">
@@ -801,7 +801,7 @@
       this.updateProPrice(row); // 鏇存柊浠锋牸鎴栧叾浠栭�昏緫
     },
     updateProPrice(row) {
-  
+
       const proPrice = new Big(row.proPrice);
 
       const limits = new Big(row.limits);
@@ -810,7 +810,7 @@
       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
+      this.youhui = (Math.floor((this.queryParams.xianprice / this.queryParams.price) * 100) / 100) * 10
     },
     getList() {
       this.$nextTick(() => {
@@ -963,7 +963,7 @@
       if (this.form.drugManufacturerId) {
         this.beCurrentDept();
       }
-      this.title = "閮ㄩ棬鍒嗙粍缁存姢" + "( " + this.form.cnName + ")";
+      this.title = "濂楅鍒嗙粍缁存姢" + "( " + this.form.cnName + ")";
       getInfo().then((response) => {
         this.getInfodis = response.user.discount;
         if (this.getInfodis == null || this.getInfodis == 10) {
@@ -971,16 +971,34 @@
         }
       });
     },
-    // 鎶樻墸
-    numberChange(currentValue) {
-      this.forms.limits = currentValue;
-      /* if (this.forms.limits > this.getInfodis) {
-        this.forms.limits = this.getInfodis;
-        this.forms.ysPrice = (
-          this.forms.price *
-          (this.forms.limits / 10)
-        ).toFixed(2);
-      } */
+    numberChange(currentValue, oldValue) {
+      this.$confirm("纭畾淇敼鎵�鏈夊瓙椤圭殑鎶樻墸鍚楋紵", "鎻愮ず", {
+        confirmButtonText: "纭畾",
+        cancelButtonText: "鍙栨秷",
+        type: "warning",
+      })
+        .then(() => {
+          this.youhui = currentValue;
+          if (this.youhui < this.getInfodis) {
+            this.youhui = this.getInfodis;
+            // this.$modal.msgError(`璇ヤ汉鍛樻渶楂樹紭鎯犳潈闄愪负${this.getInfodis}鎶榒);
+          }
+          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();
+            this.queryParams.xianprice = this.OnenewpacName.reduce((sum, item) => {
+              return sum.plus(new Big(item.ysPrice || '0'));
+            }, new Big(0));
+          })
+          // ----------------------------------------------------------
+
+        })
+        .catch(() => {
+          this.youhui = oldValue;
+        });
 
     },
 
@@ -1074,36 +1092,74 @@
         this.dataList = selection;
       }
     },
-    // 鍗曢」閫夊畾鎸夐挳
     resetright() {
-      this.queryParams.price = 0;
-      this.dataList.forEach((item) => {
-        this.$refs.tre.toggleRowSelection(item, false);
-        this.OnenewpacName.push(item);
-      });
+  if (this.dataList.length == 0) {
+    return; // 濡傛灉鏁版嵁鍒楄〃涓虹┖锛岀洿鎺ヨ繑鍥�
+  } else {
+    this.queryParams.price = 0; // 鍒濆鍖栨�讳环
+    this.queryParams.xianprice = 0; // 鍒濆鍖栫幇浠�
+    this.youhui = 0; // 鍒濆鍖栦紭鎯�
 
-      for (var i = 0; i < this.OnenewpacName.length - 1; i++) {
-        for (var j = i + 1; j < this.OnenewpacName.length; j++) {
-          if (this.OnenewpacName[i].proId == this.OnenewpacName[j].proId) {
-            this.OnenewpacName.splice(j, 1);
-            j--;
-          }
+    const newItemsToAdd = []; // 鐢ㄤ簬瀛樺偍鏂伴渶瑕佹坊鍔犵殑椤圭洰
+
+    this.dataList.forEach((item) => {
+      this.$refs.tre.toggleRowSelection(item, false); // 鍙栨秷閫変腑鐘舵��
+      // 浣跨敤 $set 纭繚鍝嶅簲鎬�
+      this.$set(item, 'limits', 10); // 璁剧疆闄愬埗鏁伴噺
+      this.$set(item, 'ysPrice', item.proPrice); // 璁剧疆鐜颁环涓哄師浠�
+
+      // 妫�鏌ユ槸鍚﹀凡缁忓瓨鍦ㄧ浉鍚岀殑椤圭洰
+      const existingItem = this.OnenewpacName.find(existing => existing.proId === item.proId);
+      if (!existingItem) {
+        newItemsToAdd.push(item); // 濡傛灉涓嶅瓨鍦ㄧ浉鍚岄」鐩紝鍒欐坊鍔犲埌鏂版暟缁�
+        this.updateProPrice(item); // 鏇存柊鍗曚釜椤圭洰鐨勪环鏍�
+      }
+    });
+
+    // 娣诲姞鏂伴」鐩埌 OnenewpacName
+    this.OnenewpacName.push(...newItemsToAdd);
+
+    // 鍒犻櫎閲嶅椤圭洰锛岃繖閲屾垜浠彧闇�澶勭悊鏂版坊鍔犵殑椤圭洰鍜屽師鏈夐」鐩箣闂寸殑閲嶅
+    for (let i = this.OnenewpacName.length - newItemsToAdd.length; i < this.OnenewpacName.length - 1; i++) {
+      for (let j = i + 1; j < this.OnenewpacName.length; j++) {
+        if (this.OnenewpacName[i].proId === this.OnenewpacName[j].proId) {
+          this.OnenewpacName.splice(j, 1); // 鍒犻櫎閲嶅鐨勯」鐩�
+          j--; // 鍥犱负鍒犻櫎浜嗕竴涓厓绱狅紝褰撳墠鐨刯瑕佸噺1
         }
       }
-      return this.OnenewpacName.forEach((item) => {
-        this.queryParams.price += item.proPrice;
-      });
-    },
+    }
+    this.queryParams.price = 0
+    this.queryParams.xianprice = 0
+    // 閲嶆柊璁$畻鎬讳环鍜岀幇浠�
+    this.OnenewpacName.forEach((item) => {
+      this.queryParams.price += item.proPrice; // 绱姞鍘熶环
+      this.queryParams.xianprice += item.ysPrice || 0; // 绱姞鐜颁环锛屽鏋測sPrice涓簎ndefined鍒欑疮鍔�0
+    });
+
+    // 璁$畻浼樻儬锛岃繖閲屽亣璁句紭鎯犳槸鐜颁环涓庡師浠风殑宸鐧惧垎姣�
+    this.youhui = (Math.floor((this.queryParams.xianprice / this.queryParams.price) * 100) / 100) * 10;
+  }
+},
     handledbelete(row) {
       this.queryParams.price = 0;
-      this.OnenewpacName.forEach((item, index) => {
-        if (item.proId == row.proId) {
-          this.OnenewpacName.splice(index, 1);
-        }
-      });
-      return this.OnenewpacName.forEach((item) => {
+      this.queryParams.xianprice = 0; // 鍒濆鍖栫幇浠�
+      this.youhui = 0; // 鍒濆鍖栦紭鎯�
+
+      // 鍏堟壘鍒板苟鍒犻櫎椤圭洰
+      this.OnenewpacName = this.OnenewpacName.filter(item => item.proId !== row.proId);
+
+      // 鐒跺悗鏇存柊鎬讳环鍜岀幇浠�
+      this.OnenewpacName.forEach((item) => {
         this.queryParams.price += item.proPrice;
+        this.queryParams.xianprice += item.ysPrice || 0; // 纭繚ysPrice瀛樺湪
       });
+
+      // 璁$畻浼樻儬
+      if (this.queryParams.price > 0) {
+        this.youhui = (Math.floor((this.queryParams.xianprice / this.queryParams.price) * 100) / 100) * 10;
+      } else {
+        this.youhui = 0;
+      }
     },
 
     submitrighr() {
@@ -1258,7 +1314,7 @@
           this.OnenewpacName.forEach((item, index) => {
             this.queryParams.price += item.proPrice;
           });
-          this.youhui = (Math.floor((this.queryParams.xianprice / this.queryParams.price)*100)/100)*10
+          this.youhui = (Math.floor((this.queryParams.xianprice / this.queryParams.price) * 100) / 100) * 10
         });
       }
       // console.log(this.groupList[0].id, 9966);
@@ -1311,7 +1367,7 @@
       });
 
 
-   
+
 
       let data = {
         groupingName: this.forms.groupingName,

--
Gitblit v1.8.0