1
lkk
2025-06-10 c1cf70d01a5b11075170cfc6278a213833d1f799
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
          });
@@ -1032,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) => {
@@ -1108,7 +1106,7 @@
      });
    },
    addzj() {
    /*  addzj() {
      if (this.form.cusName) {
        if (!this.form.zhiyezzList) {
          this.form.zhiyezzList = [];
@@ -1135,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 {
        // 如果有数据库项,要调用接口删除
        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();
    },
    // 新增行
@@ -1317,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;
      }
      // 调接口删除数据库项
      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);
@@ -1340,7 +1421,7 @@
      } else {
        this.$message.warning("请先选择要删除的项");
      }
    },
    }, */
    handlebingChange(selection) {
      this.bingshiall = [];
@@ -1354,20 +1435,11 @@
      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)));
      // 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);
@@ -1382,7 +1454,7 @@
              id: match ? match.id : "",
            };
          });
          console.log(this.form, 1236);
          // console.log(this.form, 1236);
          updateHistory(this.form)
            .then((response) => {