From a9929166ee6f4def812519684a739336c7202531 Mon Sep 17 00:00:00 2001
From: qx <1084500556@qq.com>
Date: 星期四, 12 六月 2025 16:53:07 +0800
Subject: [PATCH] Merge branch 'master' of http://101.42.27.146:5001/r/ltkj_peisweb_region

---
 src/components/jianqianwenzhen/index.vue |  112 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 85 insertions(+), 27 deletions(-)

diff --git a/src/components/jianqianwenzhen/index.vue b/src/components/jianqianwenzhen/index.vue
index ce915fc..00a748e 100644
--- a/src/components/jianqianwenzhen/index.vue
+++ b/src/components/jianqianwenzhen/index.vue
@@ -843,8 +843,8 @@
         xiyanpinlv: "",
         xiyanyear: "",
         yinjiu: "",
-        jcwhys:"",
-        tjwhys:"",
+        jcwhys: "",
+        tjwhys: "",
         yinjiupinlv: "",
         yinjiuyear: "",
         qita: "",
@@ -1046,33 +1046,49 @@
       }
       this.$forceUpdate();
     },
-
-    delezz() {
-      if (this.selectedZhiyezz && this.selectedZhiyezz.length > 0) {
-        const historyId = this.selectedZhiyezz.map((item) => item.diseaseId);
-        console.log(historyId, "鍑嗗鍒犻櫎鐨� diseaseId");
-
-        // 鍙戣姹�
-        removeAskHistorys(historyId).then((res) => {
-          console.log(res, "鍒犻櫎鎺ュ彛鍝嶅簲");
-
-          this.$message.success("鍒犻櫎鎴愬姛");
-
-          // 鎺ュ彛鎴愬姛鍚庡啀鏈湴鍒犻櫎
-          this.form.zhiyezzList = this.form.zhiyezzList.filter(
-            (item) =>
-              !this.selectedZhiyezz.some(
-                (selected) => selected.diseaseId === item.diseaseId
-              )
-          );
-
-          this.selectedZhiyezz = [];
-          this.$forceUpdate();
-        });
-      } else {
+    async delezz() {
+      if (!this.selectedZhiyezz?.length) {
         this.$message.warning("璇峰厛閫夋嫨瑕佸垹闄ょ殑椤�");
+        return;
       }
+
+      // 鎷嗗垎鈥滄湰鍦版暟鎹�濆拰鈥滄暟鎹簱鏁版嵁鈥�
+      const localItems = this.selectedZhiyezz.filter((item) => !item.diseaseId);
+      const dbItems = this.selectedZhiyezz.filter((item) => item.diseaseId);
+
+      // 鍏堝浠戒竴涓嬪綋鍓嶅垪琛紝鏂逛究鍑洪敊鏃舵仮澶�
+      const backupList = [...this.form.zhiyezzList];
+
+      // 鍒犻櫎鏈湴鏂板椤癸紙涓嶉渶瑕佽皟鎺ュ彛锛�
+      this.form.zhiyezzList = this.form.zhiyezzList.filter(
+        (item) => !localItems.includes(item)
+      );
+
+      try {
+        // 濡傛灉鏈夋暟鎹簱椤癸紝瑕佽皟鐢ㄦ帴鍙e垹闄�
+        if (dbItems.length) {
+          const deletedIds = dbItems.map((item) => item.diseaseId);
+          const res = await removeAskHistorys(deletedIds);
+          if (res?.code !== 200) throw new Error("鍒犻櫎澶辫触");
+
+          // 鎺ュ彛鎴愬姛锛屽啀浠庨〉闈㈢Щ闄ゆ暟鎹簱鏁版嵁
+          this.form.zhiyezzList = this.form.zhiyezzList.filter(
+            (item) => !dbItems.includes(item)
+          );
+          this.$message.success("鍒犻櫎鎴愬姛");
+        }
+      } catch (err) {
+        // 鍒犻櫎澶辫触
+        this.form.zhiyezzList = backupList;
+        this.$message.error("鍒犻櫎澶辫触");
+        console.error(err);
+      }
+
+      // 娓呯┖閫変腑
+      this.selectedZhiyezz = [];
+      this.$forceUpdate();
     },
+
     // 鏂板琛�
     addmembers() {
       if (this.form.cusName) {
@@ -1254,6 +1270,48 @@
       }
     },
     delemembers() {
+      if (!this.bingshiall || this.bingshiall.length === 0) {
+        this.$message.warning("璇峰厛閫夋嫨瑕佸垹闄ょ殑椤�");
+        return;
+      }
+
+      // 鍖哄垎鏂板椤瑰拰鏁版嵁搴撻」
+      const localItems = this.bingshiall.filter((item) => !item.diseaseId); // 鏂板鐨�
+      const dbItems = this.bingshiall.filter((item) => item.diseaseId); // 鏁版嵁搴撳凡鏈夌殑
+
+      // 鍏堝垹闄ゆ柊澧炵殑锛堟湰鍦扮洿鎺ュ垹锛�
+      if (localItems.length > 0) {
+        this.form.tjAskHistorysList = this.form.tjAskHistorysList.filter(
+          (item) => !localItems.includes(item)
+        );
+      }
+
+      if (dbItems.length === 0) {
+        // 鍙湁鏂板椤癸紝鏃犻渶璋冪敤鎺ュ彛锛岀洿鎺ユ竻绌洪�変腑锛岄��鍑�
+        this.bingshiall = [];
+        this.$forceUpdate();
+        return;
+      }
+
+      // 璋冩帴鍙e垹闄ゆ暟鎹簱椤�
+      const historyId = dbItems.map((item) => item.diseaseId);
+      removeAskHistorys(historyId)
+        .then((res) => {
+          this.$message.success("鍒犻櫎鎴愬姛");
+          // 鎺ュ彛鎴愬姛鍚庡垹闄ゆ暟鎹簱椤�
+          this.form.tjAskHistorysList = this.form.tjAskHistorysList.filter(
+            (item) =>
+              !dbItems.some((selected) => selected.diseaseId === item.diseaseId)
+          );
+          this.bingshiall = [];
+          this.$forceUpdate();
+        })
+        .catch(() => {
+          this.$message.warning("鍒犻櫎澶辫触");
+        });
+    },
+
+    /* delemembers() {
       if (this.bingshiall && this.bingshiall.length > 0) {
         const historyId = this.bingshiall.map((item) => item.diseaseId);
 
@@ -1277,7 +1335,7 @@
       } else {
         this.$message.warning("璇峰厛閫夋嫨瑕佸垹闄ょ殑椤�");
       }
-    },
+    }, */
     handlebingChange(selection) {
       this.bingshiall = [];
       this.bingshiall = selection;

--
Gitblit v1.8.0