WXL (wul)
昨天 d3c60e18b95b50751f8088fa2d23cd8ff7f173bc
src/views/followvisit/discharge/index.vue
@@ -94,6 +94,8 @@
            :options="sourcetype"
            :props="{ expandTrigger: 'hover' }"
            @change="handleChange"
            filterable
            clearable
          ></el-cascader>
        </el-form-item>
@@ -241,12 +243,27 @@
          </div>
        </el-col>
      </el-row>
      <div class="selected-info">
        已选中
        <span style="color: #409eff; font-weight: bold">{{
          getSelectedCount()
        }}</span>
        条数据
        <el-button
          v-if="getSelectedCount() > 0"
          type="text"
          @click="clearAllSelection"
        >
          清除选中
        </el-button>
      </div>
      <el-table
        v-loading="loading"
        ref="userform"
        :data="userList"
        :row-class-name="tableRowClassName"
        @selection-change="handleSelectionChange"
        @select-all="handleSelectAll"
      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column
@@ -486,7 +503,6 @@
          prop="nurseName"
        />
        <el-table-column
          v-if="orgname != '丽水市中医院'"
          label="经管医生"
          align="center"
          key="managementDoctor"
@@ -1096,12 +1112,13 @@
      dynamicTags: ["选项一", "选项二", "选项三"], //选项
      inputVisible: false,
      Labelchange: false,
      ycvalue: "",
      ycvalue: 0,
      jgvalue: "",
      yfsvalue: "",
      inputValue: "",
      preachform: "",
      previewVisible: false, //影像随访预览弹框
      isRestoring: false,
      radio: "",
      radios: [],
      previewtype: 2, //预览影像随访类型
@@ -1109,6 +1126,8 @@
      // 满意度调查数据
      scoreDialogVisible: false,
      selectedRows: [],
      selectedRowMap: new Map(), // key: row.id, value: row 数据
      // 级联选择器绑定值
      serviceStatusValue: 10,
      cascaderProps: {
@@ -1205,7 +1224,8 @@
        btstatus: "",
      },
      // endOut: 1,
      endOut: localStorage.getItem("orgname") == "丽水市中医院" ? 0 : 1, //0 出院时间(正序)    1 出院时间(倒序)   2 发送时间(正序)    3 发送时间(倒序)  7应随访日期(倒序) 应随访日期(正序)
      endOut:
        localStorage.getItem("orgname") == "景宁畲族自治县人民医院" ? 0 : 1, //0 出院时间(正序)    1 出院时间(倒序)   2 发送时间(正序)    3 发送时间(倒序)  7应随访日期(倒序) 应随访日期(正序)
      endOuts: [
        {
          value: 0,
@@ -1362,10 +1382,9 @@
    // 监听路由参数变化
    "$route.query": {
      handler(newQuery, oldQuery) {
        if (newQuery.errtype !== oldQuery.errtype) {
        if (newQuery?.errtype !== oldQuery?.errtype) {
          console.log(22);
          this.loadData(); // 重新加载数据
          this.loadData();
        }
      },
      immediate: true,
@@ -1434,7 +1453,7 @@
  },
  methods: {
    /** 查询随访服务列表 */
    getList(refresh) {
    async getList(refresh) {
      // 默认全部
      if (this.topqueryParams.searchscope == 3) {
        this.topqueryParams.leaveldeptcodes = store.getters.belongDepts.map(
@@ -1447,16 +1466,17 @@
        this.topqueryParams.endSendDateTime = this.formatDateToYYYYMMDDHHMMSS(
          this.getEndOfDay()
        );
      } else {
        // this.topqueryParams.endSendDateTime = null;
      }
      // 接受异常跳转
      if (this.errtype) {
        this.topqueryParams.leavehospitaldistrictcodes.push(
          this.leavehospitaldistrictcode
        );
      }
      this.loading = true;
      if (
        this.topqueryParams.leavehospitaldistrictcodes[0] &&
        this.topqueryParams.leaveldeptcodes[0]
@@ -1465,27 +1485,43 @@
      } else {
        this.topqueryParams.deptOrDistrict = 1;
      }
      if (!this.followupAuthority()) {
        this.$message.warning("未配置科室/病区相关权限不可查询");
        this.loading = false;
        return Promise.reject(new Error("无权限查询"));
      }
      getTaskservelist(this.topqueryParams).then((response) => {
      try {
        const response = await getTaskservelist(this.topqueryParams);
        // ✅ 第一步:先锁定恢复状态
        this.isRestoring = true;
        // ✅ 第二步:再更新数据(这会触发 selection-change,但被锁住了)
        this.userList = response.rows[0].serviceSubtaskList;
        this.total = response.total;
        // ✅ 第三步:恢复选中状态
        // this.restoreSelection();
        this.$nextTick(() => {
          this.restoreSelection();
        });
        // ✅ 第四步:处理其他数据
        if (refresh) {
          this.cardlist[0].value =
            Number(response.rows[0].wxsf) + Number(response.rows[0].xsf) || 0;
          // this.cardlist[1].value = response.rows[0].wzx;
          this.cardlist[1].value = response.rows[0].wxsf || 0;
          this.ycvalue = response.rows[0].yc;
          this.ycvalue = Number(response.rows[0].yc) || 0;
          this.jgvalue = response.rows[0].jg;
          this.cardlist[2].value = response.rows[0].xsf || 0;
          this.cardlist[3].value = response.rows[0].dsf || 0;
          this.cardlist[4].value = response.rows[0].ywc || 0;
          this.yfsvalue = response.rows[0].yfs;
        }
        this.loading = false;
        // ✅ 第五步:处理 preachform 等其他数据
        this.userList.forEach((item) => {
          let idArray = null;
          if (item.endtime) {
@@ -1499,17 +1535,26 @@
            }
            item.preachform = idArray.map((value) => {
              // 查找id对应的对象
              const item = this.checkboxlist.find(
                (item) => item.value == value
              );
              // 如果找到对应的id,返回label值,否则返回null
              return item ? item.label : null;
            });
          }
        });
        this.total = response.total;
      });
        this.loading = false;
        // ✅ 第六步:解锁
        this.$nextTick(() => {
          this.isRestoring = false;
        });
      } catch (error) {
        console.error("获取列表失败:", error);
        this.loading = false;
        this.isRestoring = false;
      }
    },
    loadData() {
      this.errtype = this.$route.query.errtype;
@@ -1589,7 +1634,7 @@
          Number(response.rows[0].wxsf) + Number(response.rows[0].xsf) || 0;
        this.cardlist[1].value = response.rows[0].wzx;
        this.cardlist[2].value = response.rows[0].ysf;
        this.ycvalue = response.rows[0].yc;
        this.ycvalue = Number(response.rows[0].yc) || 0;
        this.jgvalue = response.rows[0].jg;
        this.cardlist[3].value = response.rows[0].fssb;
        this.cardlist[4].value = response.rows[0].dsf;
@@ -1694,10 +1739,20 @@
    },
    // 患者范围处理
    handleChange(value) {
      let type = value[0];
      let code = value.slice(-1)[0];
      console.log("选择的患者范围:", value);
      // 清空之前的查询参数
      this.topqueryParams.leavehospitaldistrictcodes = [];
      this.topqueryParams.leaveldeptcodes = [];
      this.topqueryParams.searchscope = null;
      if (!value || value.length === 0) {
        return;
      }
      let type = value[0];
      let code = value.slice(-1)[0];
      if (type == 1) {
        this.topqueryParams.leaveldeptcodes.push(code);
        this.topqueryParams.leavehospitaldistrictcodes = [];
@@ -1761,9 +1816,17 @@
      this.handleQuery(1);
    },
    handleSelectionChange(rows) {
      this.selectedRows = rows.map((row) => {
        // 初始化评分字段
        return {
      // ✅ 如果是恢复选中状态触发的,直接返回
      if (this.isRestoring) {
        console.log("正在恢复选中状态,跳过 handleSelectionChange");
        return;
      }
      console.log("handleSelectionChange 被触发,选中行数:", rows.length);
      // 只做添加操作
      rows.forEach((row) => {
        this.selectedRowMap.set(row.id, {
          ...row,
          authenticity: row.authenticity || 0,
          weekFinish: row.weekFinish || 0,
@@ -1773,14 +1836,11 @@
          environment: row.environment || 0,
          doctorSatisfaction: row.doctorSatisfaction || 0,
          nurseSatisfaction: row.nurseSatisfaction || 0,
        };
        });
      });
      if (this.selectedRows.length > 0) {
        this.multiple = false;
      } else {
        this.multiple = true;
      }
      this.selectedRows = Array.from(this.selectedRowMap.values());
      this.multiple = this.selectedRows.length === 0;
    },
    // 计算总分
@@ -2080,6 +2140,7 @@
      const originalPageSize = this.topqueryParams.pageSize;
      this.topqueryParams.pageNum = null;
      this.topqueryParams.pageSize = null;
      this.topqueryParams.subIdList = this.selectedRows.map((item) => item.id);
      this.download(
        "smartor/serviceSubtask/patItemExport",
        {
@@ -2101,6 +2162,76 @@
        return "remind-row";
      }
      return "";
    },
    restoreSelection() {
      if (!this.$refs.userform) {
        console.log("表格引用不存在");
        return;
      }
      console.log("执行 restoreSelection");
      // 清除当前页的所有选中状态
      this.$refs.userform.clearSelection();
      // 找出当前页中哪些行是被选中的
      const toBeSelected = this.userList.filter((row) =>
        this.selectedRowMap.has(row.id)
      );
      console.log("需要恢复的行数:", toBeSelected.length);
      // 重新选中这些行
      toBeSelected.forEach((row) => {
        this.$refs.userform.toggleRowSelection(row, true);
      });
    },
    // ✅ 处理表头全选事件
    handleSelectAll(selection) {
      console.log("全选事件触发,选中行数:", selection.length);
      // 如果 selection 长度等于当前页行数,说明是全选
      if (selection.length === this.userList.length) {
        // 全选当前页
        this.userList.forEach((row) => {
          this.selectedRowMap.set(row.id, {
            ...row,
            authenticity: row.authenticity || 0,
            weekFinish: row.weekFinish || 0,
            standard: row.standard || 0,
            timeliness: row.timeliness || 0,
            library: row.library || 0,
            environment: row.environment || 0,
            doctorSatisfaction: row.doctorSatisfaction || 0,
            nurseSatisfaction: row.nurseSatisfaction || 0,
          });
        });
      } else {
        // 取消全选:清除当前页的选中状态
        this.userList.forEach((row) => {
          this.selectedRowMap.delete(row.id);
        });
      }
      // 更新 selectedRows
      this.selectedRows = Array.from(this.selectedRowMap.values());
      this.multiple = this.selectedRows.length === 0;
    },
    // 清除所有选中
    clearAllSelection() {
      this.selectedRowMap.clear();
      this.selectedRows = [];
      this.multiple = true;
      if (this.$refs.userform) {
        this.$refs.userform.clearSelection();
      }
    },
    // 获取选中数量
    getSelectedCount() {
      return this.selectedRowMap.size;
    },
    // 创建再次随访服务
    setupsubtask() {
@@ -2371,4 +2502,15 @@
  flex-shrink: 0;
  margin-top: 2px;
}
::v-deep .el-table__row.selected-row:hover > td {
  background-color: #e6f7ff !important;
}
/* 选中信息显示 */
.selected-info {
  padding: 10px 0;
  font-size: 14px;
  color: #666;
}
</style>