liusheng
2 天以前 bbbc478129f72b26e2ec4a2e981ed8698a96880c
src/views/Satisfaction/sfstatistics/components/FollowupStatistics.vue
@@ -9,6 +9,19 @@
        label-width="100px"
        class="query-form"
      >
        <el-form-item label="满意度类型" prop="satisfactionScope">
          <el-select
            v-model="satisfactionScope"
            placeholder="默认离院"
            clearable
            style="width: 150px"
            @change="handleSatisfactionScopeChange"
          >
            <el-option label="离院满意度" value="leave" />
            <el-option label="在院满意度" value="hospital" />
          </el-select>
        </el-form-item>
        <el-form-item label="统计类型" prop="statisticaltype">
          <el-select
            v-model="queryParams.statisticaltype"
@@ -137,10 +150,10 @@
        @selection-change="handleSelectionChange"
        :row-key="getRowKey"
      >
        <!-- 病区列 -->
        <!-- 病区列:住院满意度统计在院病区,其余统计出院病区 -->
        <el-table-column
          v-if="queryParams.statisticaltype == 1"
          label="出院病区"
          :label="wardColumnLabel"
          align="center"
          sortable
          key="leavehospitaldistrictname"
@@ -148,7 +161,11 @@
          :show-overflow-tooltip="true"
          :sort-method="sortChineseNumber"
          min-width="120"
        />
        >
          <template slot-scope="scope">
            {{ getWardName(scope.row) || "-" }}
          </template>
        </el-table-column>
        <!-- 科室列 -->
        <el-table-column
@@ -199,13 +216,14 @@
                scope.row.followUpRate !== undefined
              "
            >
              {{ formatPercent(scope.row.followUpRate) }}
              {{ scope.row.followUpRate }}
            </span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="orgname == '景宁畲族自治县人民医院'"
          label="及时率"
          align="center"
          key="rate"
@@ -322,6 +340,7 @@
        :row-data="currentRow"
        :topicList="topiclist"
        :query-params="queryParams"
        :topType="2"
        @close="topicVisible = false"
      />
    </el-dialog>
@@ -347,6 +366,9 @@
  },
  data() {
    return {
      // 满意度类型:leave=离院满意度(按出院病区统计),hospital=在院满意度(按在院病区统计)
      satisfactionScope: "leave",
      // 查询参数
      queryParams: {
        statisticaltype: 1,
@@ -371,7 +393,25 @@
      flatArraydept: [],
      // 服务类型选项
      options: [],
      options: [
        {
          value: 6,
          label: "住院满意度",
          raw: {
            cssClass: "",
            listClass: "",
          },
        },
        {
          value: 14,
          label: "门诊满意度",
          raw: {
            cssClass: "",
            listClass: "",
          },
        },
      ],
      // 表格数据
      userList: [],
@@ -381,6 +421,7 @@
      // 加载状态
      loading: false,
      orgname: "",
      // 选中的行
      ids: [],
@@ -438,7 +479,22 @@
    };
  },
  computed: {
    // 是否按「在院满意度」口径统计:在院患者按在院病区(hospitaldistrictcodes)统计,
    // 离院满意度仍按出院病区(leavehospitaldistrictcodes)统计
    isInHospitalSatisfaction() {
      return this.satisfactionScope === "hospital";
    },
    // 病区列标题
    wardColumnLabel() {
      return this.isInHospitalSatisfaction ? "在院病区" : "出院病区";
    },
  },
  created() {
    this.orgname = localStorage.getItem("orgname");
    this.initData();
  },
@@ -446,7 +502,7 @@
    // 初始化数据
    async initData() {
      await this.getDeptTree();
      await this.getList();
      // await this.getList();
    },
    // 获取科室树
@@ -501,16 +557,20 @@
        // 处理病区/科室选择
        if (params.statisticaltype == 1) {
          // 病区统计
          if (params.leavehospitaldistrictcodes.includes("all")) {
            // 如果选择了"全部",则移除"all"值
            params.leavehospitaldistrictcodes =
              params.leavehospitaldistrictcodes.filter(
                (item) => item !== "all"
              );
            // 如果需要传所有病区代码,可以从store中获取
            params.leavehospitaldistrictcodes = (
              this.$store.getters.belongWards || []
            ).map((ward) => ward.districtCode);
          let wardCodes = params.leavehospitaldistrictcodes || [];
          if (wardCodes.includes("all")) {
            // 如果选择了"全部",则使用当前用户所属的全部病区
            wardCodes = (this.$store.getters.belongWards || []).map(
              (ward) => ward.districtCode
            );
          }
          // 住院满意度针对在院患者,按在院病区(hospitaldistrictcodes)统计;
          // 出院随访等其他服务类型仍按出院病区(leavehospitaldistrictcodes)统计
          delete params.leavehospitaldistrictcodes;
          if (this.isInHospitalSatisfaction) {
            params.hospitaldistrictcodes = wardCodes;
          } else {
            params.leavehospitaldistrictcodes = wardCodes;
          }
        } else if (params.statisticaltype == 2) {
          // 科室统计
@@ -537,8 +597,8 @@
      }
    },
    sortChineseNumber(aRow, bRow) {
      const a = aRow.leavehospitaldistrictname;
      const b = bRow.leavehospitaldistrictname;
      const a = this.getWardName(aRow);
      const b = this.getWardName(bRow);
      // 中文数字到阿拉伯数字的映射(扩展到45)
      const chineseNumMap = {
@@ -698,14 +758,12 @@
          return -1;
        };
        const indexA = getIndex(a.leavehospitaldistrictname);
        const indexB = getIndex(b.leavehospitaldistrictname);
        const indexA = getIndex(this.getWardName(a));
        const indexB = getIndex(this.getWardName(b));
        // 排序逻辑
        if (indexA === -1 && indexB === -1) {
          return (a.leavehospitaldistrictname || "").localeCompare(
            b.leavehospitaldistrictname || ""
          );
          return this.getWardName(a).localeCompare(this.getWardName(b));
        }
        if (indexA === -1) return 1;
        if (indexB === -1) return -1;
@@ -725,6 +783,12 @@
    // 处理查询
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 切换满意度类型(离院/在院)后重新查询
    handleSatisfactionScopeChange() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
@@ -766,8 +830,14 @@
    // 获取行key
    getRowKey(row) {
      return row.statisticaltype === 1
        ? row.leavehospitaldistrictcode
        ? row.hospitaldistrictcode || row.leavehospitaldistrictcode
        : row.deptcode;
    },
    // 病区名称:住院满意度接口返回在院病区字段,其余返回出院病区字段
    getWardName(row) {
      if (!row) return "";
      return row.hospitaldistrictname || row.leavehospitaldistrictname || "";
    },
    // 格式化百分比
@@ -805,8 +875,18 @@
        }
        if (this.queryParams.statisticaltype == 1) {
          this.topicvalue.name = row.leavehospitaldistrictname;
          params.leavehospitaldistrictcodes = [row.leavehospitaldistrictcode];
          this.topicvalue.name = this.getWardName(row);
          // 住院满意度按在院病区统计,其余按出院病区统计
          if (this.isInHospitalSatisfaction) {
            delete params.leavehospitaldistrictcodes;
            params.hospitaldistrictcodes = [
              row.hospitaldistrictcode || row.leavehospitaldistrictcode,
            ];
          } else {
            params.leavehospitaldistrictcodes = [
              row.leavehospitaldistrictcode,
            ];
          }
        } else {
          this.topicvalue.name = row.deptname;
          params.deptcodes = [row.deptcode];
@@ -814,8 +894,7 @@
        const response = await getSfStatisticsJoyInfo(params);
        this.topiclist = response.data || [];
      this.topicVisible = true;
        this.topicVisible = true;
      } catch (error) {
        console.error("获取满意度详情失败:", error);
        this.$message.error("获取详情失败");
@@ -835,23 +914,54 @@
        // 构建日期范围字符串
        let dateRangeString = "";
        let sheetNameSuffix = "";
        const isLishuiHospital = this.orgname == "丽水市中医院";
        if (
          this.queryParams.dateRange &&
          this.queryParams.dateRange.length === 2
        ) {
          const startDateFormatted = this.queryParams.dateRange[0];
          const endDateFormatted = this.queryParams.dateRange[1];
          dateRangeString = `${startDateFormatted}至${endDateFormatted}`;
          sheetNameSuffix = `${startDateFormatted}至${endDateFormatted}`;
          const startDateStr = this.queryParams.dateRange[0];
          const endDateStr = this.queryParams.dateRange[1];
          if (isLishuiHospital) {
            // 丽水市中医院:只显示年月
            const formatMonthOnly = (dateTimeStr) => {
              const date = new Date(dateTimeStr);
              const year = date.getFullYear();
              const month = date.getMonth() + 1;
              return `${year}年${month}月`;
            };
            const startDateFormatted = formatMonthOnly(startDateStr);
            const endDateFormatted = formatMonthOnly(endDateStr);
            dateRangeString = `${startDateFormatted}至${endDateFormatted}`;
            sheetNameSuffix = `${startDateFormatted}至${endDateFormatted}`;
          } else {
            // 其他医院:显示年月日
            const formatDateForDisplay = (dateTimeStr) => {
              return dateTimeStr.split(" ")[0];
            };
            const startDateFormatted = formatDateForDisplay(startDateStr);
            const endDateFormatted = formatDateForDisplay(endDateStr);
            dateRangeString = `${startDateFormatted}至${endDateFormatted}`;
            sheetNameSuffix = `${startDateFormatted}至${endDateFormatted}`;
          }
        } else {
          const now = new Date();
          const currentMonth = now.getMonth() + 1;
          dateRangeString = `${currentMonth}月`;
          sheetNameSuffix = `${currentMonth}月`;
          const currentYear = now.getFullYear();
          if (isLishuiHospital) {
            // 丽水市中医院:显示年月
            dateRangeString = `${currentYear}年${currentMonth}月`;
            sheetNameSuffix = `${currentYear}年${currentMonth}月`;
          } else {
            // 其他医院:显示月份
            dateRangeString = `${currentMonth}月`;
            sheetNameSuffix = `${currentMonth}月`;
          }
        }
        const excelName = `随访统计表_${dateRangeString}.xlsx`;
        const excelName = `满意度随访统计表_${dateRangeString}.xlsx`;
        const worksheetName = `随访统计_${sheetNameSuffix}`;
        // 创建Excel工作簿
@@ -905,13 +1015,13 @@
        // 添加总标题
        worksheet.mergeCells(1, 1, 1, 10);
        const titleCell = worksheet.getCell(1, 1);
        titleCell.value = `随访统计表(${sheetNameSuffix})`;
        titleCell.value = `满意度随访统计表(${sheetNameSuffix})`;
        titleCell.style = titleStyle;
        worksheet.getRow(1).height = 35;
        // 添加表头
        const headers = [
          this.queryParams.statisticaltype == 1 ? "出院病区" : "科室",
          this.queryParams.statisticaltype == 1 ? this.wardColumnLabel : "科室",
          "出院人次",
          "无需随访人次",
          "应随访人次",
@@ -932,7 +1042,7 @@
        this.userList.forEach((item) => {
          const dataRow = worksheet.addRow([
            this.queryParams.statisticaltype == 1
              ? item.leavehospitaldistrictname
              ? this.getWardName(item)
              : item.deptname,
            item.dischargeCount || 0,
            item.nonFollowUp || 0,