WXL (wul)
23 小时以前 feb5a669dced68415bc7e32f237f77bf9842fe8b
src/views/sfstatistics/percentage/components/FirstFollowUp.vue
@@ -25,6 +25,26 @@
              show-summary
              :summary-method="getInnerSummaries"
            >
              <el-table-column label="" align="center" width="96" fixed="left">
                <template slot="header">
                  <div
                    style="
                      display: flex;
                      justify-content: space-between;
                      align-items: center;
                    "
                  >
                    <el-button
                      type="primary"
                      size="mini"
                      icon="el-icon-download"
                      @click="exportDoctorTable(props.row)"
                    >
                      导出
                    </el-button>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="医生姓名" prop="drname" align="center" />
              <el-table-column
                label="科室"
@@ -32,31 +52,82 @@
                prop="deptname"
                align="center"
              />
              <el-table-column
                label="出院人次"
                prop="dischargeCount"
                align="center"
              />
              <el-table-column
                label="出院人次"
                align="center"
                key="dischargeCount"
                prop="dischargeCount"
              />
              >
                <template slot-scope="scope">
                  <el-button
                    size="medium"
                    type="text"
                    @click="
                      handleViewDetails(
                        scope.row,
                        'dischargeCountInfo',
                        '出院患者列表',
                        '1'
                      )
                    "
                  >
                    <span class="button-zx">{{
                      scope.row.dischargeCount
                    }}</span>
                  </el-button>
                </template>
              </el-table-column>
              <el-table-column
                label="无需随访人次"
                align="center"
                width="100"
                key="nonFollowUp"
                prop="nonFollowUp"
              />
              >
                <template slot-scope="scope">
                  <el-button
                    size="medium"
                    type="text"
                    @click="
                      handleViewDetails(
                        scope.row,
                        'nonFollowUpInfo',
                        '无需随访列表',
                        '1'
                      )
                    "
                  >
                    <span class="button-zx">{{ scope.row.nonFollowUp }}</span>
                  </el-button>
                </template>
              </el-table-column>
              <el-table-column
                label="应随访人次"
                align="center"
                width="100"
                key="followUpNeeded"
                prop="followUpNeeded"
              />
              >
                <template slot-scope="scope">
                  <el-button
                    size="medium"
                    type="text"
                    @click="
                      handleViewDetails(
                        scope.row,
                        'followUpNeededInfo',
                        '应随访列表',
                        '1'
                      )
                    "
                  >
                    <span class="button-zx">{{
                      scope.row.followUpNeeded
                    }}</span>
                  </el-button>
                </template>
              </el-table-column>
              <el-table-column align="center" label="首次出院随访">
                <el-table-column
@@ -64,25 +135,118 @@
                  align="center"
                  key="needFollowUp"
                  prop="needFollowUp"
                />
                >
                  <template slot-scope="scope">
                    <el-button
                      size="medium"
                      type="text"
                      @click="
                        handleViewDetails(
                          scope.row,
                          'needFollowUpInfo',
                          '需随访列表',
                          '1'
                        )
                      "
                    >
                      <span class="button-zx">{{
                        scope.row.needFollowUp
                      }}</span>
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column
                  label="待随访"
                  align="center"
                  key="pendingFollowUp"
                  prop="pendingFollowUp"
                />
                >
                  <template slot-scope="scope">
                    <el-button
                      size="medium"
                      type="text"
                      @click="
                        handleViewDetails(
                          scope.row,
                          'pendingFollowUpInfo',
                          '待随访列表',
                          '1'
                        )
                      "
                    >
                      <span class="button-zx">{{
                        scope.row.pendingFollowUp
                      }}</span>
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column
                  label="随访成功"
                  align="center"
                  key="followUpSuccess"
                  prop="followUpSuccess"
                />
                >
                  <template slot-scope="scope">
                    <el-button
                      size="medium"
                      type="text"
                      @click="
                        handleViewDetails(
                          scope.row,
                          'followUpSuccessInfo',
                          '随访成功列表',
                          '1'
                        )
                      "
                    >
                      <span class="button-zx">{{
                        scope.row.followUpSuccess
                      }}</span>
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column
                  label="随访失败"
                  align="center"
                  key="followUpFail"
                  prop="followUpFail"
                />
                >
                  <template slot-scope="scope">
                    <el-button
                      size="medium"
                      type="text"
                      @click="
                        handleViewDetails(
                          scope.row,
                          'followUpFailInfo',
                          '随访失败列表',
                          '1'
                        )
                      "
                    >
                      <span class="button-zx">{{
                        scope.row.followUpFail
                      }}</span>
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column
                  label="成功率"
                  align="center"
                  width="120"
                  key="successRate"
                  prop="successRate"
                >
                  <template slot-scope="scope">
                    <span class="success-rate">{{
                      calculateSuccessRate(
                        scope.row.followUpSuccess,
                        scope.row.needFollowUp,
                        scope.row.pendingFollowUp
                      )
                    }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="随访率"
                  align="center"
@@ -115,19 +279,93 @@
                  align="center"
                  key="manual"
                  prop="manual"
                />
                >
                  <template slot-scope="scope">
                    <el-button
                      size="medium"
                      type="text"
                      @click="
                        handleViewDetails(
                          scope.row,
                          'manualInfo',
                          '人工随访列表',
                          '1'
                        )
                      "
                    >
                      <span class="button-zx">{{ scope.row.manual }}</span>
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column
                  label="语音"
                  align="center"
                  key="voice"
                  prop="voice"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="medium"
                      type="text"
                      @click="
                        handleViewDetails(
                          scope.row,
                          'voiceInfo',
                          '语音随访列表',
                          '1'
                        )
                      "
                    >
                      <span class="button-zx">{{ scope.row.voice }}</span>
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column
                  label="短信"
                  align="center"
                  key="sms"
                  prop="sms"
                />
                >
                  <template slot-scope="scope">
                    <el-button
                      size="medium"
                      type="text"
                      @click="
                        handleViewDetails(
                          scope.row,
                          'smsInfo',
                          '短信随访列表',
                          '1'
                        )
                      "
                    >
                      <span class="button-zx">{{ scope.row.sms }}</span>
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column
                  label="微信"
                  align="center"
                  key="weChat"
                  prop="weChat"
                />
                >
                  <template slot-scope="scope">
                    <el-button
                      size="medium"
                      type="text"
                      @click="
                        handleViewDetails(
                          scope.row,
                          'weChatInfo',
                          '微信随访列表',
                          '1'
                        )
                      "
                    >
                      <span class="button-zx">{{ scope.row.weChat }}</span>
                    </el-button>
                  </template>
                </el-table-column>
              </el-table-column>
            </el-table>
          </template>
@@ -135,6 +373,7 @@
        <!-- 表格列定义 -->
        <el-table-column
          v-if="queryParams.statisticaltype == 1"
          label="出院病区"
          align="center"
          sortable
@@ -145,6 +384,7 @@
          :sort-method="sortChineseNumber"
        />
        <el-table-column
          v-if="queryParams.statisticaltype == 2"
          label="科室"
          align="center"
          key="deptname"
@@ -156,21 +396,61 @@
          align="center"
          key="dischargeCount"
          prop="dischargeCount"
        />
        >
          <template slot-scope="scope">
            <el-button
              size="medium"
              type="text"
              @click="
                handleViewDetails(
                  scope.row,
                  'dischargeCountInfo',
                  '出院患者列表'
                )
              "
            >
              <span class="button-zx">{{ scope.row.dischargeCount }}</span>
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          label="无需随访人次"
          align="center"
          width="100"
          key="nonFollowUp"
          prop="nonFollowUp"
        />
        >
          <template slot-scope="scope">
            <el-button
              size="medium"
              type="text"
              @click="
                handleViewDetails(scope.row, 'nonFollowUpInfo', '无需随访列表')
              "
            >
              <span class="button-zx">{{ scope.row.nonFollowUp }}</span>
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          label="应随访人次"
          align="center"
          width="100"
          key="followUpNeeded"
          prop="followUpNeeded"
        />
        >
          <template slot-scope="scope">
            <el-button
              size="medium"
              type="text"
              @click="
                handleViewDetails(scope.row, 'followUpNeededInfo', '应随访列表')
              "
            >
              <span class="button-zx">{{ scope.row.followUpNeeded }}</span>
            </el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" label="首次出院随访">
          <el-table-column
@@ -258,6 +538,23 @@
            </template>
          </el-table-column>
          <el-table-column
            label="成功率"
            align="center"
            width="120"
            key="successRate"
            prop="successRate"
          >
            <template slot-scope="scope">
              <span class="success-rate">{{
                calculateSuccessRate(
                  scope.row.followUpSuccess,
                  scope.row.needFollowUp,
                  scope.row.pendingFollowUp
                )
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="随访率"
            align="center"
            width="120"
@@ -302,6 +599,19 @@
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="语音" align="center" key="voice" prop="voice">
            <template slot-scope="scope">
              <el-button
                size="medium"
                type="text"
                @click="
                  handleViewDetails(scope.row, 'voiceInfo', '语音随访列表')
                "
              >
                <span class="button-zx">{{ scope.row.voice }}</span>
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="短信" align="center" key="sms" prop="sms">
            <template slot-scope="scope">
              <el-button
@@ -335,7 +645,9 @@
        <!-- 随访情况列(仅丽水市中医院显示) -->
        <el-table-column
          v-if="orgname == '丽水市中医院'"
          v-if="
            orgname == '丽水市中医院' || orgname == '景宁畲族自治县人民医院'
          "
          align="center"
          label="随访情况"
        >
@@ -388,6 +700,9 @@
</template>
<script>
import { getSfStatisticsHyperlink } from "@/api/AiCentre/index";
import store from "@/store";
import { getSfStatistics, selectTimelyRate } from "@/api/system/user";
import ExcelJS from "exceljs";
import { saveAs } from "file-saver";
@@ -423,6 +738,7 @@
      expands: [],
      ids: [],
      patientqueryParams: { pn: 1, ps: 10 },
      tasktypes: store.getters.tasktypes,
    };
  },
  methods: {
@@ -442,7 +758,7 @@
      delete params.leavehospitaldistrictcodes.all;
      delete params.deptcodes.all;
      params.rateDay = 7;
      getSfStatistics(params)
        .then((response) => {
          this.tableData = this.customSort(response.data);
@@ -655,6 +971,8 @@
      if (!row.doctorStats) {
        this.loading = true;
        params.rateDay = 7;
        getSfStatistics(params).then((res) => {
          this.$set(row, "doctorStats", res.data);
          this.expands = [this.getRowKey(row)];
@@ -664,7 +982,23 @@
        this.expands = [this.getRowKey(row)];
      }
    },
    // 计算成功率的方法
    calculateSuccessRate(followUpSuccess, needFollowUp, pendingFollowUp) {
      const success = Number(followUpSuccess) || 0;
      const need = Number(needFollowUp) || 0;
      const pending = Number(pendingFollowUp) || 0;
      // 分母 = 需随访 - 待随访
      const denominator = need - pending;
      if (denominator <= 0) {
        return "0.00%";
      }
      const rate = (success / denominator) * 100;
      return rate.toFixed(2) + "%";
    },
    // 在统计汇总方法中处理成功率
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
@@ -674,12 +1008,36 @@
          sums[index] = "合计";
          return;
        }
        if (index === 1 || index === 2) {
        if (index === 1) {
          sums[index] = "/";
          return;
        }
        if (column.property === "followUpRate" || column.property === "rate") {
        if (column.property === "successRate") {
          // 成功率需要重新计算总的成功率,而不是平均值
          const totalSuccess = data.reduce((sum, item) => {
            return sum + (Number(item.followUpSuccess) || 0);
          }, 0);
          const totalNeed = data.reduce((sum, item) => {
            return sum + (Number(item.needFollowUp) || 0);
          }, 0);
          const totalPending = data.reduce((sum, item) => {
            return sum + (Number(item.pendingFollowUp) || 0);
          }, 0);
          const denominator = totalNeed - totalPending;
          if (denominator > 0) {
            sums[index] = ((totalSuccess / denominator) * 100).toFixed(2) + "%";
          } else {
            sums[index] = "0.00%";
          }
        } else if (
          column.property === "followUpRate" ||
          column.property === "rate"
        ) {
          const percentageValues = data
            .map((item) => {
              const value = item[column.property];
@@ -736,7 +1094,31 @@
          return;
        }
        if (column.property === "followUpRate" || column.property === "rate") {
        if (column.property === "successRate") {
          // 成功率需要重新计算总的成功率,而不是平均值
          const totalSuccess = data.reduce((sum, item) => {
            return sum + (Number(item.followUpSuccess) || 0);
          }, 0);
          const totalNeed = data.reduce((sum, item) => {
            return sum + (Number(item.needFollowUp) || 0);
          }, 0);
          const totalPending = data.reduce((sum, item) => {
            return sum + (Number(item.pendingFollowUp) || 0);
          }, 0);
          const denominator = totalNeed - totalPending;
          if (denominator > 0) {
            sums[index] = ((totalSuccess / denominator) * 100).toFixed(2) + "%";
          } else {
            sums[index] = "0.00%";
          }
        } else if (
          column.property === "followUpRate" ||
          column.property === "rate"
        ) {
          const percentageValues = data
            .map((item) => {
              const value = item[column.property];
@@ -787,71 +1169,363 @@
      this.ids = selection.map((item) => item.tagid);
    },
    handleViewDetails(row, infoKey, titleSuffix) {
    handleViewDetails(row, infoKey, titleSuffix, type) {
      const title = `${
        row.leavehospitaldistrictname || row.deptname
      }${titleSuffix}`;
      this.$emit("view-details", row[infoKey], title);
      this.$emit("view-details", row, infoKey, title, type);
    },
    handleSeeDetails(row) {
      this.$emit("see-details", row);
    },
    // 主表导出
    async exportTable() {
      try {
        let dateRangeString = "";
        let sheetNameSuffix = "";
  try {
    let dateRangeString = "";
    let sheetNameSuffix = "";
    // 判断是否是丽水市中医院
    const isLishuiHospital = this.orgname == "丽水市中医院";
    if (
      this.queryParams.dateRange &&
      this.queryParams.dateRange.length === 2
    ) {
      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;
      const currentYear = now.getFullYear();
      if (isLishuiHospital) {
        // 丽水市中医院:显示年月
        dateRangeString = `${currentYear}年${currentMonth}月`;
        sheetNameSuffix = `${currentYear}年${currentMonth}月`;
      } else {
        // 其他医院:显示月份
        dateRangeString = `${currentMonth}月`;
        sheetNameSuffix = `${currentMonth}月`;
      }
    }
    // 根据 serviceType 生成随访类型名称
    let serviceTypeName = "首次出院随访"; // 文件名使用的名称
    let sheetTypeName = "首次随访"; // 工作表使用的名称(简化版)
    if (this.queryParams.serviceType && Array.isArray(this.queryParams.serviceType) && this.queryParams.serviceType.length > 0) {
      if (this.tasktypes && Array.isArray(this.tasktypes)) {
        // 过滤出匹配的随访类型
        const matchedTypes = this.tasktypes.filter(task =>
          this.queryParams.serviceType.includes(task.value)
        );
        if (matchedTypes.length === 1) {
          // 单个类型
          const label = matchedTypes[0].label;
          serviceTypeName = `首次${label}`;
          sheetTypeName = `首次${label}`;
        } else if (matchedTypes.length > 1) {
          // 多个类型
          const typeNames = matchedTypes.map(task => task.label);
          // 文件名:用斜杠分隔
          serviceTypeName = `首次${typeNames.join("/")}`;
          // 工作表名:使用第一个类型或简化名称
          if (matchedTypes.length <= 2) {
            // 如果只有2个类型,都显示
            sheetTypeName = `首次${typeNames[0]}等`;
          } else {
            // 如果超过2个类型,只显示第一个
            sheetTypeName = `首次${typeNames[0]}等`;
          }
        } else if (this.queryParams.serviceType.length > 0) {
          // 如果没有匹配的,使用原始值
          const typeStr = this.queryParams.serviceType.join("/");
          serviceTypeName = `首次${typeStr}`;
          sheetTypeName = "首次随访";
        }
      } else if (this.queryParams.serviceType.length > 0) {
        // 如果没有 tasktypes,使用原始值
        const typeStr = this.queryParams.serviceType.join("/");
        serviceTypeName = `首次${typeStr}`;
        sheetTypeName = "首次随访";
      }
    }
    const excelName = `${serviceTypeName}统计表_${dateRangeString}.xlsx`;
    // 清理工作表名称,移除非法字符
    const cleanSheetName = (name) => {
      // Excel工作表名不能包含的字符: * ? : \ / [ ]
      return name.replace(/[*?:\\/[\]]/g, ' ');
    };
    const worksheetName = cleanSheetName(`${sheetTypeName}统计_${sheetNameSuffix}`);
    if (!this.tableData || this.tableData.length === 0) {
      this.$message.warning(`暂无${serviceTypeName}数据可导出`);
      return false;
    }
    const workbook = new ExcelJS.Workbook();
    const worksheet = workbook.addWorksheet(worksheetName);
    // 构建表格
    this.buildExportSheet(worksheet, sheetNameSuffix);
    const buffer = await workbook.xlsx.writeBuffer();
    const blob = new Blob([buffer], {
      type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    });
    saveAs(blob, excelName);
    this.$message.success("导出成功");
    return true;
  } catch (error) {
    console.error("导出失败:", error);
    this.$message.error(`导出失败: ${error.message}`);
    return false;
  }
},
    // 子表导出
    /** 导出医生子表 */
    async exportDoctorTable(row) {
      try {
        const areaName =
          row.leavehospitaldistrictname || row.deptname || "未知病区";
        let dateRangeString = "";
        if (
          this.queryParams.dateRange &&
          this.queryParams.dateRange.length === 2
        ) {
          const startDateStr = this.queryParams.dateRange[0];
          const endDateStr = this.queryParams.dateRange[1];
          const formatDateForDisplay = (dateTimeStr) => {
            return dateTimeStr.split(" ")[0];
          };
          const startDateFormatted = formatDateForDisplay(startDateStr);
          const endDateFormatted = formatDateForDisplay(endDateStr);
          dateRangeString = `${startDateFormatted}至${endDateFormatted}`;
          sheetNameSuffix = `${startDateFormatted}至${endDateFormatted}`;
          const start = this.queryParams.dateRange[0].split(" ")[0];
          const end = this.queryParams.dateRange[1].split(" ")[0];
          dateRangeString = `${start}至${end}`;
        } else {
          const now = new Date();
          const currentMonth = now.getMonth() + 1;
          dateRangeString = `${currentMonth}月`;
          sheetNameSuffix = `${currentMonth}月`;
          dateRangeString = `${new Date().getMonth() + 1}月`;
        }
        const excelName = `首次出院随访统计表_${dateRangeString}.xlsx`;
        const worksheetName = `首次随访统计_${sheetNameSuffix}`;
        const fileName = `${areaName}医生随访列表_${dateRangeString}.xlsx`;
        const sheetName = `${areaName}医生随访`;
        if (!this.tableData || this.tableData.length === 0) {
          this.$message.warning("暂无首次随访数据可导出");
          return false;
        if (!row.doctorStats || row.doctorStats.length === 0) {
          this.$message.warning("当前病区暂无医生随访数据");
          return;
        }
        const workbook = new ExcelJS.Workbook();
        const worksheet = workbook.addWorksheet(worksheetName);
        const worksheet = workbook.addWorksheet(sheetName);
        console.log(111);
        // 构建表格
        this.buildExportSheet(worksheet, sheetNameSuffix);
        this.buildDoctorExportSheet(worksheet, row.doctorStats, areaName);
        console.log(222);
        const buffer = await workbook.xlsx.writeBuffer();
        const blob = new Blob([buffer], {
          type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        });
        saveAs(blob, excelName);
        saveAs(
          new Blob([buffer], {
            type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
          }),
          fileName
        );
        this.$message.success("导出成功");
        return true;
      } catch (error) {
        console.error("导出失败:", error);
        this.$message.error(`导出失败: ${error.message}`);
        return false;
        this.$message.success("医生随访列表导出成功");
      } catch (err) {
        console.error(err);
        this.$message.error("导出失败");
      }
    },
    buildDoctorExportSheet(worksheet, data, areaName) {
      const titleStyle = {
        font: { name: "微软雅黑", size: 16, bold: true },
        alignment: { horizontal: "center", vertical: "middle" },
      };
      const headerStyle = {
        font: { name: "微软雅黑", size: 11, bold: true },
        fill: {
          type: "pattern",
          pattern: "solid",
          fgColor: { argb: "FFF5F7FA" },
        },
        alignment: { horizontal: "center", vertical: "middle", wrapText: true },
        border: {
          top: { style: "thin" },
          left: { style: "thin" },
          bottom: { style: "thin" },
          right: { style: "thin" },
        },
      };
      const cellStyle = {
        font: { name: "宋体", size: 10 },
        alignment: { horizontal: "center", vertical: "middle" },
        border: {
          top: { style: "thin" },
          left: { style: "thin" },
          bottom: { style: "thin" },
          right: { style: "thin" },
        },
      };
      // 标题
      worksheet.mergeCells(1, 1, 1, 10);
      worksheet.getCell(1, 1).value = `${areaName}医生随访列表`;
      worksheet.getCell(1, 1).style = titleStyle;
      worksheet.getRow(1).height = 30;
      // 表头
      const headers = [
        "医生姓名",
        "科室",
        "出院人次",
        "无需随访",
        "应随访",
        "需随访",
        "待随访",
        "随访成功",
        "随访失败",
        "成功率", // 新增
        "随访率", // 原来在成功率位置
      ];
      const headerRow = worksheet.addRow(headers);
      headerRow.eachCell((cell) => {
        cell.style = headerStyle;
      });
      worksheet.getRow(2).height = 25;
      // 数据
      data.forEach((item) => {
        const row = worksheet.addRow([
          item.drname,
          item.deptname,
          item.dischargeCount,
          item.nonFollowUp,
          item.followUpNeeded,
          item.needFollowUp,
          item.pendingFollowUp,
          item.followUpSuccess,
          item.followUpFail,
          this.calculateSuccessRate(
            item.followUpSuccess,
            item.needFollowUp,
            item.pendingFollowUp
          ),
          item.followUpRate,
        ]);
        row.eachCell((cell) => {
          cell.style = cellStyle;
        });
      });
      // 小计行
      const summaryRow = worksheet.addRow(this.getDoctorExportSummary(data));
      summaryRow.eachCell((cell) => {
        cell.font = { bold: true };
        cell.fill = {
          type: "pattern",
          pattern: "solid",
          fgColor: { argb: "FFF5F7FA" },
        };
      });
      // 列宽
      worksheet.columns = [
        { width: 15 },
        { width: 15 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 }, // 成功率
        { width: 12 }, // 随访率
      ];
    },
    getDoctorExportSummary(data) {
      const sums = ["小计"];
      const keys = [
        "dischargeCount",
        "nonFollowUp",
        "followUpNeeded",
        "needFollowUp",
        "pendingFollowUp",
        "followUpSuccess",
        "followUpFail",
      ];
      keys.forEach((key) => {
        sums.push(data.reduce((t, r) => t + (Number(r[key]) || 0), 0));
      });
      // 成功率(平均值)
      const successRates = data
        .map((item) => {
          const success = Number(item.followUpSuccess) || 0;
          const need = Number(item.needFollowUp) || 0;
          const pending = Number(item.pendingFollowUp) || 0;
          const denominator = need - pending;
          if (denominator <= 0) return 0;
          return success / denominator;
        })
        .filter((rate) => !isNaN(rate));
      sums.push(
        successRates.length
          ? (
              (successRates.reduce((a, b) => a + b, 0) / successRates.length) *
              100
            ).toFixed(2) + "%"
          : "0.00%"
      );
      // 随访率(平均值)
      const followUpRates = data
        .map((i) => this.extractPercentageValue(i.followUpRate))
        .filter(Boolean);
      sums.push(
        followUpRates.length
          ? (
              (followUpRates.reduce((a, b) => a + b, 0) /
                followUpRates.length) *
              100
            ).toFixed(2) + "%"
          : "0.00%"
      );
      return sums;
    },
    buildExportSheet(worksheet, sheetNameSuffix) {
      const titleStyle = {
        font: {
@@ -946,11 +1620,13 @@
        "待随访",
        "随访成功",
        "随访失败",
        "随访率",
        "及时率",
        "成功率", // 新增
        "随访率", // 原位置后移
        "及时率", // 及时率后移
        "人工",
        "短信",
        "微信",
        "语音", // 修正:应该是语音
        "短信", // 短信
        "微信", // 微信
      ];
      secondRowHeaders.forEach((header, index) => {
@@ -973,7 +1649,7 @@
      worksheet.getCell(2, 5).value = "无需随访人次";
      worksheet.getCell(2, 6).value = "应随访人次";
      worksheet.mergeCells(2, 7, 2, 15);
      worksheet.mergeCells(2, 7, 2, 16); // 从7合并到16(原来是7-15)
      worksheet.getCell(2, 7).value = "首次出院随访";
      worksheet.getCell(2, 7).style = headerStyle;
@@ -994,15 +1670,21 @@
            item.pendingFollowUp || 0,
            item.followUpSuccess || 0,
            item.followUpFail || 0,
            item.followUpRate || "0%",
            item.rate ? (Number(item.rate) * 100).toFixed(2) + "%" : "0%",
            // 成功率 - 需要动态计算
            this.calculateSuccessRate(
              item.followUpSuccess,
              item.needFollowUp,
              item.pendingFollowUp
            ),
            item.followUpRate || "0%", // 随访率
            item.rate ? (Number(item.rate) * 100).toFixed(2) + "%" : "0%", // 及时率
            item.manual || 0,
            item.sms || 0,
            item.weChat || 0,
            item.voice || 0, // 语音
            item.sms || 0, // 短信
            item.weChat || 0, // 微信
          ],
          rowIndex + 4
        );
        dataRow.eachCell((cell) => {
          cell.style = cellStyle;
        });
@@ -1032,11 +1714,13 @@
        { width: 10 },
        { width: 10 },
        { width: 10 },
        { width: 12 },
        { width: 12 },
        { width: 8 },
        { width: 8 },
        { width: 8 },
        { width: 12 }, // 成功率
        { width: 12 }, // 随访率
        { width: 12 }, // 及时率
        { width: 8 }, // 人工
        { width: 8 }, // 语音
        { width: 8 }, // 短信
        { width: 8 }, // 微信
      ];
    },
@@ -1045,18 +1729,20 @@
        "合计",
        "/",
        "/",
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        "0%",
        "0%",
        0,
        0,
        0,
        0, // 3: dischargeCount
        0, // 4: nonFollowUp
        0, // 5: followUpNeeded
        0, // 6: needFollowUp
        0, // 7: pendingFollowUp
        0, // 8: followUpSuccess
        0, // 9: followUpFail
        "0%", // 10: 成功率
        "0%", // 11: 随访率
        "0%", // 12: 及时率
        0, // 13: manual
        0, // 14: voice
        0, // 15: sms
        0, // 16: weChat
      ];
      this.tableData.forEach((item) => {
@@ -1067,42 +1753,51 @@
        summaries[7] += Number(item.pendingFollowUp) || 0;
        summaries[8] += Number(item.followUpSuccess) || 0;
        summaries[9] += Number(item.followUpFail) || 0;
        summaries[12] += Number(item.manual) || 0;
        summaries[13] += Number(item.sms) || 0;
        summaries[14] += Number(item.weChat) || 0;
        summaries[13] += Number(item.manual) || 0;
        summaries[14] += Number(item.voice) || 0;
        summaries[15] += Number(item.sms) || 0;
        summaries[16] += Number(item.weChat) || 0;
      });
      // 成功率计算
      const totalSuccess = summaries[8]; // followUpSuccess的总和
      const totalNeed = summaries[6]; // needFollowUp的总和
      const totalPending = summaries[7]; // pendingFollowUp的总和
      const denominator = totalNeed - totalPending;
      if (denominator > 0) {
        summaries[10] = ((totalSuccess / denominator) * 100).toFixed(2) + "%";
      } else {
        summaries[10] = "0.00%";
      }
      // 随访率计算
      const followUpRateValues = this.tableData
        .map((item) => this.extractPercentageValue(item.followUpRate))
        .filter((value) => value !== null);
      const rateValues = this.tableData
        .map((item) => this.extractPercentageValue(item.rate))
        .filter((value) => value !== null);
      if (followUpRateValues.length > 0) {
        const avgFollowUpRate =
          followUpRateValues.reduce((sum, val) => sum + val, 0) /
          followUpRateValues.length;
        summaries[10] = (avgFollowUpRate * 100).toFixed(2) + "%";
        summaries[11] = (avgFollowUpRate * 100).toFixed(2) + "%";
      }
      // 及时率计算
      const rateValues = this.tableData
        .map((item) => this.extractPercentageValue(item.rate))
        .filter((value) => value !== null);
      if (rateValues.length > 0) {
        const avgRate =
          rateValues.reduce((sum, val) => sum + val, 0) / rateValues.length;
        summaries[11] = (avgRate * 100).toFixed(2) + "%";
        summaries[12] = (avgRate * 100).toFixed(2) + "%";
      }
      summaries[3] = this.formatNumber(summaries[3]);
      summaries[4] = this.formatNumber(summaries[4]);
      summaries[5] = this.formatNumber(summaries[5]);
      summaries[6] = this.formatNumber(summaries[6]);
      summaries[7] = this.formatNumber(summaries[7]);
      summaries[8] = this.formatNumber(summaries[8]);
      summaries[9] = this.formatNumber(summaries[9]);
      summaries[12] = this.formatNumber(summaries[12]);
      summaries[13] = this.formatNumber(summaries[13]);
      summaries[14] = this.formatNumber(summaries[14]);
      // 格式化数字
      [3, 4, 5, 6, 7, 8, 9, 13, 14, 15, 16].forEach((index) => {
        summaries[index] = this.formatNumber(summaries[index]);
      });
      return summaries;
    },
@@ -1117,8 +1812,8 @@
      return isNaN(num) ? null : num;
    },
    selectTimelyRate(row, dateRange) {
      console.log(row, dateRange, 88);
    selectTimelyRate(row, queryParams) {
      console.log(row, queryParams, 88);
      // const params = {
      //   ...this.patientqueryParams,
@@ -1126,9 +1821,19 @@
      //   endtime: this.parseTime(dateRange[1]),
      //   deptcode: row.deptcode,
      // };
      this.patientqueryParams.starttime = this.parseTime(dateRange[0]);
      this.patientqueryParams.endtime = this.parseTime(dateRange[1]);
      this.patientqueryParams.starttime = this.parseTime(
        queryParams.dateRange[0]
      );
      this.patientqueryParams.endtime = this.parseTime(
        queryParams.dateRange[1]
      );
      this.patientqueryParams.deptcode = row.deptcode;
      console.log(1);
      this.patientqueryParams.serviceTypes = queryParams.serviceType
        ? queryParams.serviceType.join(",")
        : null;
      return selectTimelyRate(this.patientqueryParams);
    },
    selectTimelyRates(dateRange) {