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 |  183 +++++++++++++++++++++++++++++++++------------
 1 files changed, 132 insertions(+), 51 deletions(-)

diff --git a/src/components/jianqianwenzhen/index.vue b/src/components/jianqianwenzhen/index.vue
index 5b95b89..082bc96 100644
--- a/src/components/jianqianwenzhen/index.vue
+++ b/src/components/jianqianwenzhen/index.vue
@@ -83,12 +83,12 @@
             </el-form-item>
             <el-form-item
               label="鎺ヨЕ鏈夊鐗╁伐榫�"
-              prop="zgongLing"
+              prop="jhgl"
               label-width="150px"
             >
               <!-- <el-input v-model="form.cusName" placeholder="璇疯緭鍏ュ伐榫�" style="width: 150px" />骞� -->
               <el-input-number
-                v-model="form.zgongLing"
+                v-model="form.jhgl"
                 label="璇疯緭鍏ユ帴瑙︽湁瀹崇墿宸ラ緞"
               ></el-input-number
               >骞�
@@ -108,10 +108,11 @@
                 style="width: 700px"
               />
             </el-form-item> -->
-            <el-form-item label="浣撴鍗卞鍥犵礌" prop="tjwhyx">
+            <el-form-item label="浣撴鍗卞鍥犵礌" prop="tjwhys">
               <el-select
                 filterable
-                v-model="form.tjwhyx"
+                v-model="form.tjwhys"
+                @change="handleTjwhysChange"
                 placeholder="璇烽�夋嫨浣撴鍗卞鍥犵礌"
                 clearable
                 style="width: 180px"
@@ -126,12 +127,12 @@
             </el-form-item>
             <el-form-item
               label="鎺ヨЕ鍗卞鍥犵礌"
-              prop="tcwhyx"
+              prop="jcwhys"
               style="margin-left: 30px"
             >
               <el-select
                 filterable
-                v-model="form.tcwhyx"
+                v-model="form.jcwhys"
                 placeholder="璇烽�夋嫨鎺ヨЕ鍗卞鍥犵礌"
                 clearable
                 style="width: 180px"
@@ -913,9 +914,11 @@
         dwmc: "",
         ygdw: "",
         gongLing: "",
-        zgongLing: "",
+        jhgl: "",
         yjsfyc: "", // 鏄惁寮傚父
         ycms: "", // 寮傚父鎻忚堪
+        tjwhys: "",
+        jcwhys: "",
         xiyan: "",
         xiyanpinlv: "",
         xiyanyear: "",
@@ -1017,7 +1020,6 @@
             }
             this.form.tjAskHistorysList = response.data.tjAskHistorysList;
             this.form.zhiyezzList = response.data.zhiyezzList;
-            console.log(response.data.tjAskHistorysList, 123456);
 
             // this.isdisabled= true
           });
@@ -1029,9 +1031,8 @@
   created() {
     this.getList();
     this.getzhenzhuangList();
-    console.log(this.form.cusSex, 15555);
-    console.log("鎺ユ敹", this.jianqianwenzhendata);
-    // console.log(this.dict.type.sys_yes_no,666666);
+    // console.log(this.form.cusSex, 15555);
+    // console.log("鎺ユ敹", this.jianqianwenzhendata);
 
     if (this.jianqianwenzhendata.length == 1) {
       this.jianqianwenzhendata.forEach((item) => {
@@ -1095,13 +1096,17 @@
       });
     },
 
+    handleTjwhysChange(val) {
+      console.log("tjwhys changed:", val);
+    },
+
     getzhenzhuangList() {
       getZhengZhuang().then((response) => {
         this.zhenghuzangList = response.data;
       });
     },
 
-    addzj() {
+    /*  addzj() {
       if (this.form.cusName) {
         if (!this.form.zhiyezzList) {
           this.form.zhiyezzList = [];
@@ -1128,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();
     },
 
     // 鏂板琛�
@@ -1308,9 +1355,49 @@
         });
       }
     },
- 
 
     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);
 
@@ -1334,7 +1421,7 @@
       } else {
         this.$message.warning("璇峰厛閫夋嫨瑕佸垹闄ょ殑椤�");
       }
-    },
+    }, */
 
     handlebingChange(selection) {
       this.bingshiall = [];
@@ -1348,21 +1435,14 @@
       this.chageall = [];
       this.chageall = selection;
     },
-    /** 鎻愪氦鎸夐挳 */
-    /* submitForm() {
-      // this.form.tjAskHistorysList.forEach(element=>{
-      //   element.icdId = this.icdId;
-      // })
-      updateHistory(this.form).then((response) => {
-        this.$modal.msgSuccess("淇敼鎴愬姛");
-        this.form = response.data;
-      });
-    }, */
+
     submitForm() {
+      // console.log("鎻愪氦鍓� form:", JSON.parse(JSON.stringify(this.form)));
       this.$refs.form.validate((valid) => {
+        // console.log("鏍¢獙鍚� form:", JSON.parse(JSON.stringify(this.form)));
         if (valid) {
           this.$emit("submitLoading", true);
-          // this.form.medicalHistory =this.form.mediHistory
+
           const selected = this.form.mediHistoryq || [];
 
           this.form.medicalHistory = selected.map((name) => {
@@ -1370,14 +1450,15 @@
             // console.log(match);
 
             return {
-              icdname: match.icdname,
+              icdname: match ? match.icdname : "",
               id: match ? match.id : "",
             };
           });
-          console.log(this.form.medicalHistory, 1236);
+          // console.log(this.form, 1236);
 
           updateHistory(this.form)
             .then((response) => {
+              console.log("鎺ュ彛杩斿洖鏁版嵁", response.data);
               this.$message.success("淇敼鎴愬姛");
               // this.form = response.data; // 鏇存柊琛ㄥ崟鏁版嵁
 

--
Gitblit v1.8.0