qx
2025-06-12 a9929166ee6f4def812519684a739336c7202531
src/components/jianqianwenzhen/index.vue
@@ -79,12 +79,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
              >年
@@ -99,10 +99,10 @@
              <el-input @focus="change" type="textarea" rows="4" v-model="form.contactPoison" placeholder="请输入接触毒物"
                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"
                placeholder="请选择体检危害因素"
                clearable
                style="width: 180px"
@@ -117,12 +117,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"
@@ -836,13 +836,15 @@
        dwmc: "",
        ygdw: "",
        gongLing: "",
        zgongLing: "",
        jhgl: "",
        yjsfyc: "", // 是否异常
        ycms: "", // 异常描述
        xiyan: "",
        xiyanpinlv: "",
        xiyanyear: "",
        yinjiu: "",
        jcwhys: "",
        tjwhys: "",
        yinjiupinlv: "",
        yinjiuyear: "",
        qita: "",
@@ -1044,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 {
        // 如果有数据库项,要调用接口删除
        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) {
@@ -1252,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;
      }
      // 调接口删除数据库项
      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);
@@ -1275,7 +1335,7 @@
      } else {
        this.$message.warning("请先选择要删除的项");
      }
    },
    }, */
    handlebingChange(selection) {
      this.bingshiall = [];
      this.bingshiall = selection;