WXL (wul)
昨天 d3c60e18b95b50751f8088fa2d23cd8ff7f173bc
src/views/followvisit/discharge/index.vue
@@ -243,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
@@ -1103,6 +1118,7 @@
      inputValue: "",
      preachform: "",
      previewVisible: false, //影像随访预览弹框
      isRestoring: false,
      radio: "",
      radios: [],
      previewtype: 2, //预览影像随访类型
@@ -1110,6 +1126,8 @@
      // 满意度调查数据
      scoreDialogVisible: false,
      selectedRows: [],
      selectedRowMap: new Map(), // key: row.id, value: row 数据
      // 级联选择器绑定值
      serviceStatusValue: 10,
      cascaderProps: {
@@ -1435,7 +1453,7 @@
  },
  methods: {
    /** 查询随访服务列表 */
    getList(refresh) {
    async getList(refresh) {
      // 默认全部
      if (this.topqueryParams.searchscope == 3) {
        this.topqueryParams.leaveldeptcodes = store.getters.belongDepts.map(
@@ -1448,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]
@@ -1466,18 +1485,33 @@
      } 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 = Number(response.rows[0].yc) || 0;
          this.jgvalue = response.rows[0].jg;
@@ -1486,7 +1520,8 @@
          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) {
@@ -1500,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;
@@ -1772,11 +1816,17 @@
      this.handleQuery(1);
    },
    handleSelectionChange(rows) {
      console.log(rows, 911);
      // ✅ 如果是恢复选中状态触发的,直接返回
      if (this.isRestoring) {
        console.log("正在恢复选中状态,跳过 handleSelectionChange");
        return;
      }
      this.selectedRows = rows.map((row) => {
        // 初始化评分字段
        return {
      console.log("handleSelectionChange 被触发,选中行数:", rows.length);
      // 只做添加操作
      rows.forEach((row) => {
        this.selectedRowMap.set(row.id, {
          ...row,
          authenticity: row.authenticity || 0,
          weekFinish: row.weekFinish || 0,
@@ -1786,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;
    },
    // 计算总分
@@ -2116,6 +2163,76 @@
      }
      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() {
      this.$refs["zcform"].validate((valid) => {
@@ -2385,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>