From 35412dc0ad60ae6cbf09035914356be9c4e4c3a4 Mon Sep 17 00:00:00 2001
From: lkk <364857242@qq.com>
Date: 星期二, 10 六月 2025 16:38:44 +0800
Subject: [PATCH] 1

---
 src/components/jianqianwenzhen/index.vue |   68 +++++++++++++++++++++-------------
 1 files changed, 42 insertions(+), 26 deletions(-)

diff --git a/src/components/jianqianwenzhen/index.vue b/src/components/jianqianwenzhen/index.vue
index ce915fc..19172bc 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) {

--
Gitblit v1.8.0