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

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

diff --git a/src/components/jianqianwenzhen/index.vue b/src/components/jianqianwenzhen/index.vue
index b3c5140..082bc96 100644
--- a/src/components/jianqianwenzhen/index.vue
+++ b/src/components/jianqianwenzhen/index.vue
@@ -1020,7 +1020,6 @@
             }
             this.form.tjAskHistorysList = response.data.tjAskHistorysList;
             this.form.zhiyezzList = response.data.zhiyezzList;
-            console.log(response.data.tjAskHistorysList, 123456);
 
             // this.isdisabled= true
           });
@@ -1107,7 +1106,7 @@
       });
     },
 
-    addzj() {
+    /*  addzj() {
       if (this.form.cusName) {
         if (!this.form.zhiyezzList) {
           this.form.zhiyezzList = [];
@@ -1134,36 +1133,78 @@
           });
         }
       } else {
-        Message.warning("璇峰厛濉啓瀹㈡埛鍚�");
+        this.$message.warning("璇峰厛濉啓瀹㈡埛鍚�");
       }
       this.$forceUpdate();
+    }, */
+
+    addzj() {
+      if (!this.form.cusName) {
+        this.$message.warning("璇峰厛濉啓瀹㈡埛鍚�");
+        return;
+      }
+
+      if (!this.form.zhiyezzList) {
+        this.form.zhiyezzList = [];
+      }
+
+      this.form.zhiyezzList.push({
+        id: Date.now(), // 鐢ㄦ椂闂存埑褰撴湰鍦板敮涓� id
+        diseaseId: null, // 鍏抽敭锛佹槑纭爣璇嗏�滆繕娌″瓨杩涙暟鎹簱鈥�
+        isLocal: true, // 鍙�夛紝渚夸簬鍚庣画澶勭悊
+        diseaseName: "",
+        diseaseData: "",
+        diseaseCompany: "",
+        isOk: "",
+        remark: "",
+        icdId: "",
+        type: "",
+      });
+
+      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();
     },
 
     // 鏂板琛�
@@ -1316,6 +1357,47 @@
     },
 
     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);
 
@@ -1339,7 +1421,7 @@
       } else {
         this.$message.warning("璇峰厛閫夋嫨瑕佸垹闄ょ殑椤�");
       }
-    },
+    }, */
 
     handlebingChange(selection) {
       this.bingshiall = [];
@@ -1355,9 +1437,9 @@
     },
 
     submitForm() {
-      console.log("鎻愪氦鍓� form:", JSON.parse(JSON.stringify(this.form)));
+      // console.log("鎻愪氦鍓� form:", JSON.parse(JSON.stringify(this.form)));
       this.$refs.form.validate((valid) => {
-        console.log("鏍¢獙鍚� form:", JSON.parse(JSON.stringify(this.form)));
+        // console.log("鏍¢獙鍚� form:", JSON.parse(JSON.stringify(this.form)));
         if (valid) {
           this.$emit("submitLoading", true);
 
@@ -1372,7 +1454,7 @@
               id: match ? match.id : "",
             };
           });
-          console.log(this.form, 1236);
+          // console.log(this.form, 1236);
 
           updateHistory(this.form)
             .then((response) => {

--
Gitblit v1.8.0