qx
2025-06-12 2bb623a2fd4ed6155450c66c04706ca18e3dbcb7
src/views/doctor/inspectCheck/index.vue
@@ -55,6 +55,7 @@
    <span class="highlight">姓名:{{ infoList.tjCustomerName || "暂无" }}</span>
    <span class="highlight">性别:{{ infoList.tjCustomerSex == 0 ? "男" : infoList.tjCustomerSex == 1 ? "女" : "暂无" }}</span>
    <span class="highlight">年龄:{{ infoList.tjCustomerAge || "暂无" }}</span>
    <span class="highlight">门诊号:{{ infoList.cardId || "暂无" }}</span>
  </h3>
</div>
    <el-table border height="350" ref="tab1" :data="checkList" v-loading="loading" style="width: 100%"
@@ -87,6 +88,8 @@
  dicts: ["dict_tj_status"],
  data() {
    return {
        isProcessing: false, // 防止死循环
    isDeselection: false, // 标记是否为取消选中
      infoList: {},
      dis: false,
      code: null,
@@ -170,77 +173,99 @@
      return !row.brid ? "row-disabled" : "";
    },
    handleSelectionChange(val) {
      // console.log(val);
      /*  if (val.length > 1) {
        let del_row = val.shift();
        this.$refs.tb.toggleRowSelection(del_row, false); //设置这一行取消选中
handleSelectionChange(val) {
  // 防止重复触发
  if (this.isProcessingSelection) {
    console.log('正在处理选择,跳过重复触发');
    return;
  }
  this.isProcessingSelection = true;
  // 如果没有选中行,清空所有选择并跳过接口调用
  if (val.length === 0) {
    console.log('检测到取消选中,清空所有选择');
    this.$refs.firstTable.clearSelection();
    this.selectedFirstTable = null;
    this.checkList = [];
    this.isDeselection = true;
    this.$nextTick(() => {
      this.isProcessingSelection = false;
      this.$refs.firstTable.$forceUpdate(); // 强制刷新表格
    });
    return;
  }
  // 检查是否点击了全选按钮(val 长度等于表格总行数)
  if (val.length === this.exaLists.length) {
    console.log('检测到全选,选中所有行');
    this.selectedFirstTable = [...this.exaLists]; // 选中所有行
    this.$refs.firstTable.clearSelection();
    this.exaLists.forEach(row => {
      if (!row.brid) {
        console.warn(`名称为 ${row.name} 的行没有申请单号,跳过选择`);
        return;
      }
      console.log(val, 999); */
      this.$refs.firstTable.toggleRowSelection(row, true, false);
    });
  } else {
    // 获取最新选中的行
    const latestSelectedRow = val[val.length - 1];
      if (val.length > 0) {
        // const selectedRow = val[0];
        // console.log(val[0], 555);
        this.selectedFirstTable = val;
        console.log("当前选中的行数据:", this.selectedFirstTable);
        this.fetchRightTableData(val);
      } else {
        this.selectedFirstTable = null;
        this.checkList = [];
      }
    // 检查是否点击了已选中的行(取消所有选中)
    const isTogglingSelectedRow = this.selectedFirstTable && this.selectedFirstTable.some(row => row.tempId === latestSelectedRow.tempId);
    if (isTogglingSelectedRow) {
      console.log('点击已选中行,取消所有选中');
      this.$refs.firstTable.clearSelection();
      this.selectedFirstTable = null;
      this.checkList = [];
      this.isDeselection = true;
      this.$nextTick(() => {
        if (isDeselection) {
          console.log('检测到取消选中,清空所有选择');
          this.exaLists.forEach(row => {
            if (!row.brid) {
              console.warn(`名称为 ${row.name} 的行没有申请单号,跳过选择`);
              return;
            }
            this.$refs.firstTable.toggleRowSelection(row, false, false);
          });
          this.checkList = [];
        } else if (val.length > 0) {
          const firstSelectedRow = val[0];
          let filterKey = firstSelectedRow.checkParts ? 'checkParts' : 'brid';
          let filterValue = firstSelectedRow.checkParts || firstSelectedRow.brid;
          const checkPartsMatches = this.exaLists.filter(row => row.checkParts === firstSelectedRow.checkParts);
          if (firstSelectedRow.checkParts && checkPartsMatches.length <= 1) {
            filterKey = 'brid';
            filterValue = firstSelectedRow.brid;
          }
          console.log(`按 ${filterKey} 筛选: ${filterValue}`);
          const selectedSet = new Set(this.exaLists
            .filter(row => row[filterKey] === filterValue)
            .map(item => item.tempId));
          console.log(`选中的 ${filterKey} 集合 (tempId):`, selectedSet);
          this.exaLists.forEach(row => {
            if (!row.brid) {
              console.warn(`名称为 ${row.name} 的行没有申请单号,跳过选择`);
              return;
            }
            const shouldSelect = selectedSet.has(row.tempId);
            console.log(`行 tempId: ${row.tempId}, ${filterKey}: ${row[filterKey]},是否选中: ${shouldSelect}`);
            this.$refs.firstTable.toggleRowSelection(row, shouldSelect, false);
          });
          if (!this.isFetchingRightTableData) {
            this.isFetchingRightTableData = true;
            this.fetchRightTableData().finally(() => {
              this.isFetchingRightTableData = false;
            });
          }
        } else {
          console.log('无选中行,清空 checkList');
          this.checkList = [];
        }
        this.isProcessingSelection = false;
        this.$refs.firstTable.$forceUpdate(); // 强制刷新表格
      });
    },
      return;
    }
    // 正常选中逻辑:根据 brid 筛选
    const filterKey = 'brid';
    const filterValue = latestSelectedRow.brid;
    console.log(`按 ${filterKey} 筛选: ${filterValue}`);
    // 清空所有选中状态
    this.$refs.firstTable.clearSelection();
    // 选中与 brid 匹配的行
    const rowsToSelect = this.exaLists.filter(row => row.brid === filterValue);
    rowsToSelect.forEach(row => {
      if (!row.brid) {
        console.warn(`名称为 ${row.name} 的行没有申请单号,跳过选择`);
        return;
      }
      this.$refs.firstTable.toggleRowSelection(row, true, false);
    });
    // 更新 selectedFirstTable 为 brid 匹配的行
    this.selectedFirstTable = rowsToSelect;
  }
  // 调用右侧表格数据
  if (!this.isFetchingRightTableData && this.selectedFirstTable.length > 0) {
    this.isFetchingRightTableData = true;
    this.fetchRightTableData().finally(() => {
      this.isFetchingRightTableData = false;
      this.$nextTick(() => {
        // 仅更新样式,不触发新事件
        this.$refs.firstTable.$forceUpdate();
        this.isProcessingSelection = false;
      });
    });
  } else {
    this.isProcessingSelection = false;
  }
  // 重置 isDeselection 状态
  this.isDeselection = false;
},
    fetchRightTableData() {
      const code = this.queryParams.tjNum;
      if (!code) {