WXL (wul)
2026-11-09 da65acd978c10cf75c91334ee1a768e7d82884f7
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,31 +135,185 @@
                  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
                  v-if="!isTargetHospital"
                  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
                  v-if="isTargetHospital"
                  label="待随访"
                  align="center"
                >
                  <el-table-column
                    label="待发送"
                    align="center"
                    key="pendingFollowUpWaitSend"
                    prop="pendingFollowUpWaitSend"
                  >
                    <template slot-scope="scope">
                      <el-button
                        size="medium"
                        type="text"
                        @click="
                          handleViewDetails(
                            scope.row,
                            'pendingFollowUpWaitSendInfo',
                            '待发送列表',
                            '1'
                          )
                        "
                      >
                        <span class="button-zx">{{
                          scope.row.pendingFollowUpWaitSend
                        }}</span>
                      </el-button>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="已发送"
                    align="center"
                    key="pendingFollowUpSent"
                    prop="pendingFollowUpSent"
                  >
                    <template slot-scope="scope">
                      <el-button
                        size="medium"
                        type="text"
                        @click="
                          handleViewDetails(
                            scope.row,
                            'pendingFollowUpSentInfo',
                            '已发送列表',
                            '1'
                          )
                        "
                      >
                        <span class="button-zx">{{
                          scope.row.pendingFollowUpSent
                        }}</span>
                      </el-button>
                    </template>
                  </el-table-column>
                </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
                  v-if="!isTargetHospital"
                  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
                  v-if="orgname != '景宁畲族自治县人民医院'"
                  label="成功率"
                  align="center"
                  width="120"
                  key="successRate"
                  prop="successRate"
                  :render-header="Tooltipcgl"
                >
                  <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"
                  key="followUpRate"
                  prop="followUpRate"
                  :render-header="Tooltipsfl"
                />
                <el-table-column
                  v-if="orgname != '丽水市中医院'"
@@ -97,6 +322,7 @@
                  width="120"
                  key="rate"
                  prop="rate"
                  :render-header="Tooltipjsl"
                >
                  <template slot-scope="scope">
                    <el-button
@@ -104,9 +330,9 @@
                      type="text"
                      @click="handleSeeDetails(scope.row)"
                    >
                      <span class="button-zx"
                        >{{ (Number(scope.row.rate) * 100).toFixed(2) }}%</span
                      >
                      <span class="button-zx">{{
                        getTimelyRateText(scope.row)
                      }}</span>
                    </el-button>
                  </template>
                </el-table-column>
@@ -115,19 +341,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 +435,7 @@
        <!-- 表格列定义 -->
        <el-table-column
          v-if="queryParams.statisticaltype == 1"
          label="出院病区"
          align="center"
          sortable
@@ -145,6 +446,7 @@
          :sort-method="sortChineseNumber"
        />
        <el-table-column
          v-if="queryParams.statisticaltype == 2"
          label="科室"
          align="center"
          key="deptname"
@@ -156,21 +458,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
@@ -192,6 +534,7 @@
            </template>
          </el-table-column>
          <el-table-column
            v-if="!isTargetHospital"
            label="待随访"
            align="center"
            key="pendingFollowUp"
@@ -212,6 +555,60 @@
                <span class="button-zx">{{ scope.row.pendingFollowUp }}</span>
              </el-button>
            </template>
          </el-table-column>
          <el-table-column
            v-if="isTargetHospital"
            label="待随访"
            align="center"
          >
            <el-table-column
              label="待发送"
              align="center"
              key="pendingFollowUpWaitSend"
              prop="pendingFollowUpWaitSend"
            >
              <template slot-scope="scope">
                <el-button
                  size="medium"
                  type="text"
                  @click="
                    handleViewDetails(
                      scope.row,
                      'pendingFollowUpWaitSendInfo',
                      '待发送列表'
                    )
                  "
                >
                  <span class="button-zx">{{
                    scope.row.pendingFollowUpWaitSend
                  }}</span>
                </el-button>
              </template>
            </el-table-column>
            <el-table-column
              label="已发送"
              align="center"
              key="pendingFollowUpSent"
              prop="pendingFollowUpSent"
            >
              <template slot-scope="scope">
                <el-button
                  size="medium"
                  type="text"
                  @click="
                    handleViewDetails(
                      scope.row,
                      'pendingFollowUpSentInfo',
                      '已发送列表'
                    )
                  "
                >
                  <span class="button-zx">{{
                    scope.row.pendingFollowUpSent
                  }}</span>
                </el-button>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column
            label="随访成功"
@@ -236,6 +633,7 @@
            </template>
          </el-table-column>
          <el-table-column
            v-if="!isTargetHospital"
            label="随访失败"
            align="center"
            key="followUpFail"
@@ -258,11 +656,31 @@
            </template>
          </el-table-column>
          <el-table-column
            v-if="orgname != '景宁畲族自治县人民医院'"
            label="成功率"
            align="center"
            width="120"
            key="successRate"
            prop="successRate"
            :render-header="Tooltipcgl"
          >
            <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"
            key="followUpRate"
            prop="followUpRate"
            :render-header="Tooltipsfl"
          />
          <el-table-column
            v-if="orgname != '丽水市中医院'"
@@ -271,6 +689,7 @@
            width="120"
            key="rate"
            prop="rate"
            :render-header="Tooltipjsl"
          >
            <template slot-scope="scope">
              <el-button
@@ -278,13 +697,231 @@
                type="text"
                @click="handleSeeDetails(scope.row)"
              >
                <span class="button-zx"
                  >{{ (Number(scope.row.rate) * 100).toFixed(2) }}%</span
                >
                <span class="button-zx">{{
                  getTimelyRateText(scope.row)
                }}</span>
              </el-button>
            </template>
          </el-table-column>
          <el-table-column
            v-if="orgname == '缙云县人民医院'"
            label="及时随访人次"
            align="center"
            key="timelyFollowUp"
            prop="timelyFollowUp"
            width="138"
          >
            <template slot-scope="scope">
              <el-button
                size="medium"
                type="text"
                @click="
                  handleViewDetails(
                    scope.row,
                    'timelyFollowUpInfo',
                    '及时随访列表'
                  )
                "
              >
                <span class="button-zx">{{ scope.row.timelyFollowUp }}</span>
              </el-button>
            </template>
          </el-table-column>
          <el-table-column v-if="isTargetHospital" label="语音" align="center">
            <el-table-column
              label="发送数"
              align="center"
              key="voice"
              prop="voice"
              :render-header="Tooltipfswc"
            >
              <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="voiceSuccess"
              prop="voiceSuccess"
              :render-header="Tooltipzzwc"
            >
              <template slot-scope="scope">
                <el-button
                  size="medium"
                  type="text"
                  @click="
                    handleViewDetails(
                      scope.row,
                      'voiceSuccessInfo',
                      '最终完成语音随访列表'
                    )
                  "
                >
                  <span class="button-zx">{{ scope.row.voiceSuccess }}</span>
                </el-button>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column v-if="isTargetHospital" label="微信" align="center">
            <el-table-column
              label="发送数"
              align="center"
              key="weChat"
              prop="weChat"
              :render-header="Tooltipfswc"
            >
              <template slot-scope="scope">
                <el-button
                  size="medium"
                  type="text"
                  @click="
                    handleViewDetails(
                      scope.row,
                      'weChatInfo',
                      '发送完成微信随访列表'
                    )
                  "
                >
                  <span class="button-zx">{{ scope.row.weChat }}</span>
                </el-button>
              </template>
            </el-table-column>
            <el-table-column
              label="成功数"
              align="center"
              key="weChatSuccess"
              prop="weChatSuccess"
              :render-header="Tooltipzzwc"
            >
              <template slot-scope="scope">
                <el-button
                  size="medium"
                  type="text"
                  @click="
                    handleViewDetails(
                      scope.row,
                      'weChatSuccessInfo',
                      '最终完成微信随访列表'
                    )
                  "
                >
                  <span class="button-zx">{{ scope.row.weChatSuccess }}</span>
                </el-button>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column v-if="isTargetHospital" label="短信" align="center">
            <el-table-column
              label="发送数"
              align="center"
              key="sms"
              prop="sms"
              :render-header="Tooltipfswc"
            >
              <template slot-scope="scope">
                <el-button
                  size="medium"
                  type="text"
                  @click="
                    handleViewDetails(
                      scope.row,
                      'smsInfo',
                      '发送完成短信随访列表'
                    )
                  "
                >
                  <span class="button-zx">{{ scope.row.sms }}</span>
                </el-button>
              </template>
            </el-table-column>
            <el-table-column
              label="成功数"
              align="center"
              key="smsSuccess"
              prop="smsSuccess"
              :render-header="Tooltipzzwc"
            >
              <template slot-scope="scope">
                <el-button
                  size="medium"
                  type="text"
                  @click="
                    handleViewDetails(
                      scope.row,
                      'smsSuccessInfo',
                      '最终完成短信随访列表'
                    )
                  "
                >
                  <span class="button-zx">{{ scope.row.smsSuccess }}</span>
                </el-button>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column v-if="isTargetHospital" label="人工" align="center">
            <el-table-column
              label="发送数"
              align="center"
              key="manual"
              prop="manual"
              :render-header="Tooltipfswc"
            >
              <template slot-scope="scope">
                <el-button
                  size="medium"
                  type="text"
                  @click="
                    handleViewDetails(
                      scope.row,
                      'manualInfo',
                      '发送完成人工随访列表'
                    )
                  "
                >
                  <span class="button-zx">{{ scope.row.manual }}</span>
                </el-button>
              </template>
            </el-table-column>
            <el-table-column
              label="成功数"
              align="center"
              key="manualSuccess"
              prop="manualSuccess"
              :render-header="Tooltipzzwc"
            >
              <template slot-scope="scope">
                <el-button
                  size="medium"
                  type="text"
                  @click="
                    handleViewDetails(
                      scope.row,
                      'manualSuccessInfo',
                      '最终完成人工随访列表'
                    )
                  "
                >
                  <span class="button-zx">{{ scope.row.manualSuccess }}</span>
                </el-button>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column
            v-if="!isTargetHospital"
            label="人工"
            align="center"
            key="manual"
@@ -302,7 +939,32 @@
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="短信" align="center" key="sms" prop="sms">
          <el-table-column
            v-if="!isTargetHospital"
            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
            v-if="!isTargetHospital"
            label="短信"
            align="center"
            key="sms"
            prop="sms"
          >
            <template slot-scope="scope">
              <el-button
                size="medium"
@@ -314,6 +976,7 @@
            </template>
          </el-table-column>
          <el-table-column
            v-if="!isTargetHospital"
            label="微信"
            align="center"
            key="weChat"
@@ -333,9 +996,9 @@
          </el-table-column>
        </el-table-column>
        <!-- 随访情况列(仅丽水市中医院显示) -->
        <!-- 随访情况列(丽水市中医院已移到综合统计,此处仅景宁畲族自治县人民医院显示) -->
        <el-table-column
          v-if="orgname == '丽水市中医院'"
          v-if="orgname == '景宁畲族自治县人民医院'"
          align="center"
          label="随访情况"
        >
@@ -388,6 +1051,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,7 +1089,16 @@
      expands: [],
      ids: [],
      patientqueryParams: { pn: 1, ps: 10 },
      tasktypes: store.getters.tasktypes,
    };
  },
  computed: {
    isTargetHospital() {
      return (
        this.orgname == "第一人民医院湖滨院区" ||
        this.orgname == "第一人民医院吴山院区"
      );
    },
  },
  methods: {
    loadData() {
@@ -442,8 +1117,8 @@
      delete params.leavehospitaldistrictcodes.all;
      delete params.deptcodes.all;
      getSfStatistics(params)
      params.rateDay = this.orgname == "龙泉市人民医院" ? 21 : 7;
      return getSfStatistics(params)
        .then((response) => {
          this.tableData = this.customSort(response.data);
        })
@@ -469,167 +1144,23 @@
    },
    customSort(data) {
      const order = [
        "一",
        "二",
        "三",
        "四",
        "五",
        "六",
        "七",
        "八",
        "九",
        "十",
        "十一",
        "十二",
        "十三",
        "十四",
        "十五",
        "十六",
        "十七",
        "十八",
        "十九",
        "二十",
        "二十一",
        "二十二",
        "二十三",
        "二十四",
        "二十五",
        "二十六",
        "二十七",
        "二十八",
        "二十九",
        "三十",
        "三十一",
        "三十二",
        "三十三",
        "三十四",
        "三十五",
        "三十六",
        "三十七",
        "三十八",
        "三十九",
        "四十",
        "四十一",
        "四十二",
        "四十三",
        "四十四",
        "四十五",
      ];
      return data.sort((a, b) => {
        const getIndex = (name) => {
          if (!name || typeof name !== "string") return -1;
          const chineseMatch = name.match(/^([一二三四五六七八九十]+)/);
          if (chineseMatch && chineseMatch[1]) {
            return order.indexOf(chineseMatch[1]);
          }
          const arabicMatch = name.match(/^(\d+)/);
          if (arabicMatch && arabicMatch[1]) {
            const num = parseInt(arabicMatch[1], 10);
            if (num >= 1 && num <= 45) {
              return num - 1;
            }
          }
          return -1;
        };
        const indexA = getIndex(a.leavehospitaldistrictname);
        const indexB = getIndex(b.leavehospitaldistrictname);
        if (indexA === -1 && indexB === -1) {
          return (a.leavehospitaldistrictname || "").localeCompare(
            b.leavehospitaldistrictname || ""
          );
        }
        if (indexA === -1) return 1;
        if (indexB === -1) return -1;
        return indexA - indexB;
      });
      return data.sort((a, b) =>
        this.compareWardName(
          a.leavehospitaldistrictname,
          b.leavehospitaldistrictname
        )
      );
    },
    sortChineseNumber(aRow, bRow) {
      const a = aRow.leavehospitaldistrictname;
      const b = bRow.leavehospitaldistrictname;
      const chineseNumMap = {
        一: 1,
        二: 2,
        三: 3,
        四: 4,
        五: 5,
        六: 6,
        七: 7,
        八: 8,
        九: 9,
        十: 10,
        十一: 11,
        十二: 12,
        十三: 13,
        十四: 14,
        十五: 15,
        十六: 16,
        十七: 17,
        十八: 18,
        十九: 19,
        二十: 20,
        二十一: 21,
        二十二: 22,
        二十三: 23,
        二十四: 24,
        二十五: 25,
        二十六: 26,
        二十七: 27,
        二十八: 28,
        二十九: 29,
        三十: 30,
        三十一: 31,
        三十二: 32,
        三十三: 33,
        三十四: 34,
        三十五: 35,
        三十六: 36,
        三十七: 37,
        三十八: 38,
        三十九: 39,
        四十: 40,
        四十一: 41,
        四十二: 42,
        四十三: 43,
        四十四: 44,
        四十五: 45,
      };
      const getNumberFromText = (text) => {
        if (!text || typeof text !== "string") return -1;
        const match = text.match(/^([一二三四五六七八九十]+)/);
        if (match && match[1]) {
          const chineseNum = match[1];
          return chineseNumMap[chineseNum] !== undefined
            ? chineseNumMap[chineseNum]
            : -1;
        }
        const arabicMatch = text.match(/^(\d+)/);
        if (arabicMatch && arabicMatch[1]) {
          const num = parseInt(arabicMatch[1], 10);
          return num >= 1 && num <= 45 ? num : -1;
        }
        return -1;
      };
      const numA = getNumberFromText(a);
      const numB = getNumberFromText(b);
      if (numA === -1 && numB === -1) {
        return (a || "").localeCompare(b || "");
      }
      if (numA === -1) return 1;
      if (numB === -1) return -1;
      return numA - numB;
      return this.compareWardName(
        aRow.leavehospitaldistrictname,
        bRow.leavehospitaldistrictname
      );
    },
    getRowKey(row) {
      return row.statisticaltype === 1
      return this.queryParams.statisticaltype === 1
        ? row.leavehospitaldistrictcode
        : row.deptcode;
    },
@@ -655,6 +1186,8 @@
      if (!row.doctorStats) {
        this.loading = true;
        params.rateDay = this.orgname == "龙泉市人民医院" ? 21 : 7;
        getSfStatistics(params).then((res) => {
          this.$set(row, "doctorStats", res.data);
          this.expands = [this.getRowKey(row)];
@@ -664,7 +1197,43 @@
        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 = this.isTargetHospital ? need : need - pending;
      if (denominator <= 0) {
        return "0.00%";
      }
      const rate = (success / denominator) * 100;
      return rate.toFixed(2) + "%";
    },
    // 计算及时率(目标医院):(需随访 - 人工规定时间内没打过电话) / 需随访
    calculateTimelyRate(needFollowUp, manualCallTimeout) {
      const need = Number(needFollowUp) || 0;
      const timeout = Number(manualCallTimeout) || 0;
      if (need <= 0) {
        return "0.00%";
      }
      const rate = ((need - timeout) / need) * 100;
      return (rate < 0 ? 0 : rate).toFixed(2) + "%";
    },
    // 及时率展示文案:目标医院前端计算,其他用后端 rate 字段
    getTimelyRateText(row) {
      if (this.isTargetHospital) {
        return this.calculateTimelyRate(
          row.needFollowUp,
          row.manualCallTimeout
        );
      }
      return (Number(row.rate) * 100).toFixed(2) + "%";
    },
    // 在统计汇总方法中处理成功率
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
@@ -674,12 +1243,70 @@
          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 = this.isTargetHospital
            ? totalNeed
            : totalNeed - totalPending;
          if (denominator > 0) {
            sums[index] = ((totalSuccess / denominator) * 100).toFixed(2) + "%";
          } else {
            sums[index] = "0.00%";
          }
        } else if (column.property === "rate") {
          if (this.isTargetHospital) {
            const totalNeed = data.reduce(
              (sum, item) => sum + (Number(item.needFollowUp) || 0),
              0
            );
            const totalTimeout = data.reduce(
              (sum, item) => sum + (Number(item.manualCallTimeout) || 0),
              0
            );
            sums[index] = this.calculateTimelyRate(totalNeed, totalTimeout);
          } else {
            const percentageValues = data
              .map((item) => {
                const value = item[column.property];
                if (!value || value === "-" || value === "0%") return null;
                if (typeof value === "string" && value.includes("%")) {
                  const numValue = parseFloat(value.replace("%", "")) / 100;
                  return isNaN(numValue) ? null : numValue;
                } else {
                  const numValue = parseFloat(value);
                  return isNaN(numValue) ? null : numValue;
                }
              })
              .filter((value) => value !== null && value !== 0);
            if (percentageValues.length > 0) {
              const average =
                percentageValues.reduce((sum, value) => sum + value, 0) /
                percentageValues.length;
              sums[index] = (average * 100).toFixed(2) + "%";
            } else {
              sums[index] = "0.00%";
            }
          }
        } else if (column.property === "followUpRate") {
          const percentageValues = data
            .map((item) => {
              const value = item[column.property];
@@ -720,7 +1347,75 @@
      return sums;
    },
    Tooltipcgl(h, { column }) {
      return h(
        "el-tooltip",
        {
          props: {
            content: this.isTargetHospital
              ? "随访成功/需随访"
              : "随访成功/(需随访-待随访)",
            placement: "top",
            effect: "dark",
          },
        },
        [h("span", column.label)]
      );
    },
    Tooltipjsl(h, { column }) {
      return h(
        "el-tooltip",
        {
          props: {
            content: this.isTargetHospital
              ? "及时率=(需随访-人工规定时间内没打过电话)/需随访"
              : "(出院时间+任务周期)小于完成时间即为超时;(需随访-超时)/需随访",
            placement: "top",
            effect: "dark",
          },
        },
        [h("span", column.label)]
      );
    },
    Tooltipsfl(h, { column }) {
      return h(
        "el-tooltip",
        {
          props: {
            content: "(随访成功+首次随访失败)/首次应随访",
            placement: "top",
            effect: "dark",
          },
        },
        [h("span", column.label)]
      );
    },
    Tooltipfswc(h, { column }) {
      return h(
        "el-tooltip",
        {
          props: {
            content: "首次发送患者即填报成功的数量",
            placement: "top",
            effect: "dark",
          },
        },
        [h("span", column.label)]
      );
    },
    Tooltipzzwc(h, { column }) {
      return h(
        "el-tooltip",
        {
          props: {
            content: "首次未完成二次或三次补偿推送本方式的完成次数",
            placement: "top",
            effect: "dark",
          },
        },
        [h("span", column.label)]
      );
    },
    getInnerSummaries(param) {
      const { columns, data } = param;
      const sums = [];
@@ -736,7 +1431,65 @@
          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 = this.isTargetHospital
            ? totalNeed
            : totalNeed - totalPending;
          if (denominator > 0) {
            sums[index] = ((totalSuccess / denominator) * 100).toFixed(2) + "%";
          } else {
            sums[index] = "0.00%";
          }
        } else if (column.property === "rate") {
          if (this.isTargetHospital) {
            const totalNeed = data.reduce(
              (sum, item) => sum + (Number(item.needFollowUp) || 0),
              0
            );
            const totalTimeout = data.reduce(
              (sum, item) => sum + (Number(item.manualCallTimeout) || 0),
              0
            );
            sums[index] = this.calculateTimelyRate(totalNeed, totalTimeout);
          } else {
            const percentageValues = data
              .map((item) => {
                const value = item[column.property];
                if (!value || value === "-" || value === "0%") return null;
                if (typeof value === "string" && value.includes("%")) {
                  const numValue = parseFloat(value.replace("%", "")) / 100;
                  return isNaN(numValue) ? null : numValue;
                } else {
                  const numValue = parseFloat(value);
                  return isNaN(numValue) ? null : numValue;
                }
              })
              .filter((value) => value !== null && value !== 0);
            if (percentageValues.length > 0) {
              const average =
                percentageValues.reduce((sum, value) => sum + value, 0) /
                percentageValues.length;
              sums[index] = (average * 100).toFixed(2) + "%";
            } else {
              sums[index] = "0.00%";
            }
          }
        } else if (column.property === "followUpRate") {
          const percentageValues = data
            .map((item) => {
              const value = item[column.property];
@@ -783,25 +1536,99 @@
      return Number.isInteger(num) ? num.toString() : num.toFixed(0);
    },
    // ===== 病区名排序(支持 1-B10 / 2-A2 等 数字-字母数字 格式) =====
    // 解析病区名,返回排序键 { group, letter, number }
    parseWardKey(name) {
      if (!name || typeof name !== "string") return null;
      const trimmed = name.trim();
      // 格式1:数字-字母数字,如 1-B10、2-A2、1-A11
      const dashMatch = trimmed.match(/^(\d+)-([A-Za-z]+)(\d+)/);
      if (dashMatch) {
        return {
          group: parseInt(dashMatch[1], 10),
          letter: dashMatch[2].toUpperCase(),
          number: parseInt(dashMatch[3], 10),
        };
      }
      // 格式2:中文数字开头,如 一病区、十一病区、二十一病区
      const cnMatch = trimmed.match(/^([一二三四五六七八九十]+)/);
      if (cnMatch && cnMatch[1]) {
        const num = this.chineseToNumber(cnMatch[1]);
        if (num > 0) return { group: num, letter: "", number: 0 };
      }
      // 格式3:阿拉伯数字开头,如 1病区、12病区
      const numMatch = trimmed.match(/^(\d+)/);
      if (numMatch && numMatch[1]) {
        return { group: parseInt(numMatch[1], 10), letter: "", number: 0 };
      }
      return null;
    },
    // 中文数字转阿拉伯数字(支持 一 ~ 九十九)
    chineseToNumber(str) {
      const digits = {
        一: 1,
        二: 2,
        三: 3,
        四: 4,
        五: 5,
        六: 6,
        七: 7,
        八: 8,
        九: 9,
      };
      if (!str) return -1;
      if (str === "十") return 10;
      if (str.startsWith("十")) return 10 + (digits[str[1]] || 0);
      if (str.includes("十")) {
        const parts = str.split("十");
        const tens = digits[parts[0]] || 0;
        const ones = digits[parts[1]] || 0;
        return tens * 10 + ones;
      }
      return digits[str] !== undefined ? digits[str] : -1;
    },
    // 病区名比较器:数字段 → 字母段 → 数字段
    compareWardName(nameA, nameB) {
      const ka = this.parseWardKey(nameA);
      const kb = this.parseWardKey(nameB);
      if (!ka && !kb) return (nameA || "").localeCompare(nameB || "", "zh-CN");
      if (!ka) return 1;
      if (!kb) return -1;
      if (ka.group !== kb.group) return ka.group - kb.group;
      if (ka.letter !== kb.letter) return ka.letter.localeCompare(kb.letter);
      return ka.number - kb.number;
    },
    handleSelectionChange(selection) {
      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 = "";
        // 判断是否是丽水市中医院
        const isLishuiHospital = this.orgname == "丽水市中医院";
        if (
          this.queryParams.dateRange &&
@@ -809,25 +1636,99 @@
        ) {
          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}`;
          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 worksheetName = `首次随访统计_${sheetNameSuffix}`;
        // 根据 serviceType 生成随访类型名称(兼容单选/多选)
        const serviceTypes = Array.isArray(this.queryParams.serviceType)
          ? this.queryParams.serviceType
          : this.queryParams.serviceType
          ? [this.queryParams.serviceType]
          : [];
        let serviceTypeName = "首次出院随访"; // 文件名使用的名称
        let sheetTypeName = "首次随访"; // 工作表使用的名称(简化版)
        if (serviceTypes.length > 0) {
          // 使用 props 中的 options(即 tasktypes)
          if (this.options && Array.isArray(this.options)) {
            const matchedTypes = this.options.filter((task) =>
              serviceTypes.includes(task.value)
            );
            console.log(matchedTypes, "matchedTypes");
            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("/")}`;
              // 工作表名简化(取第一个+“等”)
              sheetTypeName = `首次${typeNames[0]}等`;
            } else {
              // 无匹配时使用原始值
              const typeStr = serviceTypes.join("/");
              serviceTypeName = `首次${typeStr}`;
              sheetTypeName = "首次随访";
            }
          } else {
            const typeStr = serviceTypes.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("暂无首次随访数据可导出");
          this.$message.warning(`暂无${serviceTypeName}数据可导出`);
          return false;
        }
@@ -835,7 +1736,7 @@
        const worksheet = workbook.addWorksheet(worksheetName);
        // 构建表格
        this.buildExportSheet(worksheet, sheetNameSuffix);
        this.buildExportSheet(worksheet, sheetNameSuffix, serviceTypeName);
        const buffer = await workbook.xlsx.writeBuffer();
        const blob = new Blob([buffer], {
@@ -851,8 +1752,283 @@
        return false;
      }
    },
    // 子表导出
    /** 导出医生子表 */
    async exportDoctorTable(row) {
      try {
        const areaName =
          row.leavehospitaldistrictname || row.deptname || "未知病区";
    buildExportSheet(worksheet, sheetNameSuffix) {
        let dateRangeString = "";
        if (
          this.queryParams.dateRange &&
          this.queryParams.dateRange.length === 2
        ) {
          const start = this.queryParams.dateRange[0].split(" ")[0];
          const end = this.queryParams.dateRange[1].split(" ")[0];
          dateRangeString = `${start}至${end}`;
        } else {
          dateRangeString = `${new Date().getMonth() + 1}月`;
        }
        const fileName = `${areaName}医生随访列表_${dateRangeString}.xlsx`;
        const sheetName = `${areaName}医生随访`;
        if (!row.doctorStats || row.doctorStats.length === 0) {
          this.$message.warning("当前病区暂无医生随访数据");
          return;
        }
        const workbook = new ExcelJS.Workbook();
        const worksheet = workbook.addWorksheet(sheetName);
        console.log(111);
        this.buildDoctorExportSheet(worksheet, row.doctorStats, areaName);
        console.log(222);
        const buffer = await workbook.xlsx.writeBuffer();
        saveAs(
          new Blob([buffer], {
            type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
          }),
          fileName
        );
        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" },
        },
      };
      const graded = this.isTargetHospital;
      // 成功率:景宁畲族自治县人民医院不展示;及时率:丽水市中医院不展示
      const showSuccessRate = this.orgname != "景宁畲族自治县人民医院";
      const showTimelyRate = this.orgname != "丽水市中医院";
      // 列定义(与展开的医生子表保持一致)
      const headers = [
        "医生姓名",
        "科室",
        "出院人次",
        "无需随访",
        "应随访",
        "需随访",
        ...(graded ? ["待发送", "已发送"] : ["待随访"]),
        "随访成功",
        ...(graded ? [] : ["随访失败"]),
        ...(showSuccessRate ? ["成功率"] : []),
        "随访率",
        ...(showTimelyRate ? ["及时率"] : []),
        "人工",
        "语音",
        "短信",
        "微信",
      ];
      const totalCols = headers.length;
      // 标题
      worksheet.mergeCells(1, 1, 1, totalCols);
      worksheet.getCell(1, 1).value = `${areaName}医生随访列表`;
      worksheet.getCell(1, 1).style = titleStyle;
      worksheet.getRow(1).height = 30;
      // 表头
      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,
          ...(graded
            ? [item.pendingFollowUpWaitSend || 0, item.pendingFollowUpSent || 0]
            : [item.pendingFollowUp || 0]),
          item.followUpSuccess,
          ...(graded ? [] : [item.followUpFail || 0]),
          ...(showSuccessRate
            ? [
                this.calculateSuccessRate(
                  item.followUpSuccess,
                  item.needFollowUp,
                  item.pendingFollowUp
                ),
              ]
            : []),
          item.followUpRate,
          ...(showTimelyRate ? [this.getTimelyRateText(item)] : []),
          item.manual || 0,
          item.voice || 0,
          item.sms || 0,
          item.weChat || 0,
        ]);
        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" },
        };
      });
      // 列宽(前两列姓名/科室较宽,其余统一)
      const widths = [15, 15];
      headers.slice(2).forEach(() => widths.push(12));
      worksheet.columns = widths.map((width) => ({ width }));
    },
    getDoctorExportSummary(data) {
      const graded = this.isTargetHospital;
      const showSuccessRate = this.orgname != "景宁畲族自治县人民医院";
      const showTimelyRate = this.orgname != "丽水市中医院";
      const sums = ["小计", "-"];
      // 数值列求和
      const keys = graded
        ? [
            "dischargeCount",
            "nonFollowUp",
            "followUpNeeded",
            "needFollowUp",
            "pendingFollowUpWaitSend",
            "pendingFollowUpSent",
            "followUpSuccess",
          ]
        : [
            "dischargeCount",
            "nonFollowUp",
            "followUpNeeded",
            "needFollowUp",
            "pendingFollowUp",
            "followUpSuccess",
            "followUpFail",
          ];
      keys.forEach((key) => {
        sums.push(data.reduce((t, r) => t + (Number(r[key]) || 0), 0));
      });
      // 成功率(平均值)
      if (showSuccessRate) {
        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 = graded ? need : 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%"
      );
      // 及时率(目标医院计算,其他取 rate 平均)
      if (showTimelyRate) {
        if (graded) {
          const totalNeed = data.reduce(
            (s, r) => s + (Number(r.needFollowUp) || 0),
            0
          );
          const totalTimeout = data.reduce(
            (s, r) => s + (Number(r.manualCallTimeout) || 0),
            0
          );
          sums.push(this.calculateTimelyRate(totalNeed, totalTimeout));
        } else {
          const rateValues = data
            .map((i) => this.extractPercentageValue(i.rate))
            .filter(Boolean);
          sums.push(
            rateValues.length
              ? (
                  (rateValues.reduce((a, b) => a + b, 0) / rateValues.length) *
                  100
                ).toFixed(2) + "%"
              : "0.00%"
          );
        }
      }
      // 人工/语音/短信/微信
      ["manual", "voice", "sms", "weChat"].forEach((key) => {
        sums.push(data.reduce((t, r) => t + (Number(r[key]) || 0), 0));
      });
      return sums;
    },
    buildExportSheet(worksheet, sheetNameSuffix, serviceTypeName) {
      const titleStyle = {
        font: {
          name: "微软雅黑",
@@ -926,83 +2102,193 @@
          right: { style: "thin", color: { argb: "FFD0D0D0" } },
        },
      };
      // 是否为目标医院(人工/语音/短信/微信 按 发送数/成功数 分级展示)
      const graded = this.isTargetHospital;
      // 添加标题行
      worksheet.mergeCells(1, 1, 1, 16);
      const titleCell = worksheet.getCell(1, 1);
      titleCell.value = `首次出院随访统计表_${sheetNameSuffix}`;
      titleCell.style = titleStyle;
      worksheet.getRow(1).height = 35;
      // 表头
      const secondRowHeaders = [
      const baseHeaders = [
        "",
        "出院病区",
        "科室",
        "出院人次",
        "无需随访人次",
        "应随访人次",
        "需随访",
        "待随访",
        "随访成功",
        "随访失败",
        "随访率",
        "及时率",
        "人工",
        "短信",
        "微信",
      ];
      const coreHeaders = this.isTargetHospital
        ? [
            "需随访",
            "待发送",
            "已发送",
            "随访成功",
            "成功率",
            "随访率",
            "及时率",
          ]
        : [
            "需随访",
            "待随访",
            "随访成功",
            "随访失败",
            "成功率",
            "随访率",
            "及时率",
          ];
      const methodGroups = this.getMethodColumns();
      secondRowHeaders.forEach((header, index) => {
        const cell = worksheet.getCell(3, index + 1);
        cell.value = header;
        cell.style = headerStyle;
      });
      const baseCount = baseHeaders.length; // 6
      const coreCount = coreHeaders.length; // 7
      const methodLeafCount = methodGroups.reduce(
        (sum, g) => sum + g.fields.length,
        0
      ); // 8 或 4
      const totalCols = baseCount + coreCount + methodLeafCount; // 21 或 17
      const coreStartCol = baseCount + 1; // 7
      const methodStartCol = baseCount + coreCount + 1; // 14
      // 合并单元格
      for (let i = 1; i <= 6; i++) {
        worksheet.mergeCells(2, i, 3, i);
        const cell = worksheet.getCell(2, i);
        cell.style = headerStyle;
      const titleText = `${serviceTypeName}统计表_${sheetNameSuffix}`;
      // 添加标题行
      worksheet.mergeCells(1, 1, 1, totalCols);
      const titleCell = worksheet.getCell(1, 1);
      titleCell.value = titleText;
      titleCell.style = titleStyle;
      worksheet.getRow(1).height = 35;
      if (graded) {
        // 表头占 3 行(第2/3/4行),数据从第5行开始
        const headerEndRow = 4;
        // 第2行:基础列纵向合并 + 随访分组横向合并
        for (let i = 1; i <= baseCount; i++) {
          worksheet.mergeCells(2, i, headerEndRow, i);
          const cell = worksheet.getCell(2, i);
          cell.value = baseHeaders[i - 1];
          cell.style = headerStyle;
        }
        worksheet.mergeCells(2, coreStartCol, 2, totalCols);
        worksheet.getCell(2, coreStartCol).value = serviceTypeName;
        worksheet.getCell(2, coreStartCol).style = headerStyle;
        // 第3行:随访核心列(目标医院“待随访”下嵌套“待发送/已发送”)
        worksheet.mergeCells(3, coreStartCol, headerEndRow, coreStartCol);
        worksheet.getCell(3, coreStartCol).value = "需随访";
        worksheet.getCell(3, coreStartCol).style = headerStyle;
        worksheet.mergeCells(3, coreStartCol + 1, 3, coreStartCol + 2);
        worksheet.getCell(3, coreStartCol + 1).value = "待随访";
        worksheet.getCell(3, coreStartCol + 1).style = headerStyle;
        worksheet.mergeCells(
          3,
          coreStartCol + 3,
          headerEndRow,
          coreStartCol + 3
        );
        worksheet.getCell(3, coreStartCol + 3).value = "随访成功";
        worksheet.getCell(3, coreStartCol + 3).style = headerStyle;
        ["成功率", "随访率", "及时率"].forEach((label, i) => {
          const col = coreStartCol + 4 + i;
          worksheet.mergeCells(3, col, headerEndRow, col);
          worksheet.getCell(3, col).value = label;
          worksheet.getCell(3, col).style = headerStyle;
        });
        // 第4行:待发送/已发送 子列
        worksheet.getCell(4, coreStartCol + 1).value = "待发送";
        worksheet.getCell(4, coreStartCol + 1).style = headerStyle;
        worksheet.getCell(4, coreStartCol + 2).value = "已发送";
        worksheet.getCell(4, coreStartCol + 2).style = headerStyle;
        let mc = methodStartCol;
        methodGroups.forEach((g) => {
          if (g.fields.length > 1) {
            worksheet.mergeCells(3, mc, 3, mc + g.fields.length - 1);
          }
          const cell = worksheet.getCell(3, mc);
          cell.value = g.label;
          cell.style = headerStyle;
          mc += g.fields.length;
        });
        // 第4行:随访方式子列(发送数/成功数)
        mc = methodStartCol;
        methodGroups.forEach((g) => {
          g.fields.forEach((field, idx) => {
            const cell = worksheet.getCell(4, mc + idx);
            cell.value = g.sub[idx];
            cell.style = headerStyle;
          });
          mc += g.fields.length;
        });
        worksheet.getRow(2).height = 28;
        worksheet.getRow(3).height = 24;
        worksheet.getRow(4).height = 24;
      } else {
        // 表头占 2 行(第2/3行),数据从第4行开始
        const headerEndRow = 3;
        for (let i = 1; i <= baseCount; i++) {
          worksheet.mergeCells(2, i, headerEndRow, i);
          const cell = worksheet.getCell(2, i);
          cell.value = baseHeaders[i - 1];
          cell.style = headerStyle;
        }
        worksheet.mergeCells(2, coreStartCol, 2, totalCols);
        worksheet.getCell(2, coreStartCol).value = serviceTypeName;
        worksheet.getCell(2, coreStartCol).style = headerStyle;
        // 第3行:随访核心列 + 随访方式列
        for (let k = 0; k < coreCount; k++) {
          const cell = worksheet.getCell(3, coreStartCol + k);
          cell.value = coreHeaders[k];
          cell.style = headerStyle;
        }
        let mc = methodStartCol;
        methodGroups.forEach((g) => {
          const cell = worksheet.getCell(3, mc);
          cell.value = g.label;
          cell.style = headerStyle;
          mc += 1;
        });
        worksheet.getRow(2).height = 28;
        worksheet.getRow(3).height = 25;
      }
      worksheet.getCell(2, 1).value = "";
      worksheet.getCell(2, 2).value = "出院病区";
      worksheet.getCell(2, 3).value = "科室";
      worksheet.getCell(2, 4).value = "出院人次";
      worksheet.getCell(2, 5).value = "无需随访人次";
      worksheet.getCell(2, 6).value = "应随访人次";
      worksheet.mergeCells(2, 7, 2, 15);
      worksheet.getCell(2, 7).value = "首次出院随访";
      worksheet.getCell(2, 7).style = headerStyle;
      worksheet.getRow(2).height = 28;
      worksheet.getRow(3).height = 25;
      // 数据行
      const dataStartRow = graded ? 5 : 4;
      this.tableData.forEach((item, rowIndex) => {
        const dataRow = worksheet.addRow(
          [
            "",
            item.leavehospitaldistrictname || "",
            item.deptname || "",
            item.dischargeCount || 0,
            item.nonFollowUp || 0,
            item.followUpNeeded || 0,
            item.needFollowUp || 0,
            item.pendingFollowUp || 0,
            item.followUpSuccess || 0,
            item.followUpFail || 0,
            item.followUpRate || "0%",
            item.rate ? (Number(item.rate) * 100).toFixed(2) + "%" : "0%",
            item.manual || 0,
            item.sms || 0,
            item.weChat || 0,
          ],
          rowIndex + 4
        );
        const rowValues = [
          "",
          item.leavehospitaldistrictname || "",
          item.deptname || "",
          item.dischargeCount || 0,
          item.nonFollowUp || 0,
          item.followUpNeeded || 0,
          item.needFollowUp || 0,
          // 待随访:目标医院拆为待发送/已发送,其他用待随访
          ...(this.isTargetHospital
            ? [item.pendingFollowUpWaitSend || 0, item.pendingFollowUpSent || 0]
            : [item.pendingFollowUp || 0]),
          item.followUpSuccess || 0,
          // 随访失败:目标医院不显示
          ...(this.isTargetHospital ? [] : [item.followUpFail || 0]),
          // 成功率 - 需要动态计算
          this.calculateSuccessRate(
            item.followUpSuccess,
            item.needFollowUp,
            item.pendingFollowUp
          ),
          item.followUpRate || "0%", // 随访率
          this.getTimelyRateText(item), // 及时率
        ];
        methodGroups.forEach((g) => {
          g.fields.forEach((field) => {
            rowValues.push(item[field] || 0);
          });
        });
        const dataRow = worksheet.addRow(rowValues, rowIndex + dataStartRow);
        dataRow.eachCell((cell) => {
          cell.style = cellStyle;
        });
@@ -1021,22 +2307,43 @@
      summaryRow.height = 28;
      // 列宽
      worksheet.columns = [
        { width: 8 },
        { width: 20 },
        { width: 15 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 10 },
        { width: 10 },
        { width: 10 },
        { width: 10 },
        { width: 12 },
        { width: 12 },
        { width: 8 },
        { width: 8 },
        { width: 8 },
      const widths = [8, 20, 15, 12, 12, 12, 10, 10, 10, 10, 12, 12, 12];
      methodGroups.forEach((g) => {
        g.fields.forEach(() => widths.push(8));
      });
      worksheet.columns = widths.map((width) => ({ width }));
    },
    getMethodColumns() {
      // 随访方式列配置:目标医院按“发送数/成功数”分级展示
      if (this.isTargetHospital) {
        return [
          {
            label: "人工",
            fields: ["manual", "manualSuccess"],
            sub: ["发送数", "成功数"],
          },
          {
            label: "语音",
            fields: ["voice", "voiceSuccess"],
            sub: ["发送数", "成功数"],
          },
          {
            label: "短信",
            fields: ["sms", "smsSuccess"],
            sub: ["发送数", "成功数"],
          },
          {
            label: "微信",
            fields: ["weChat", "weChatSuccess"],
            sub: ["发送数", "成功数"],
          },
        ];
      }
      return [
        { label: "人工", fields: ["manual"], sub: ["人工"] },
        { label: "语音", fields: ["voice"], sub: ["语音"] },
        { label: "短信", fields: ["sms"], sub: ["短信"] },
        { label: "微信", fields: ["weChat"], sub: ["微信"] },
      ];
    },
@@ -1045,64 +2352,96 @@
        "合计",
        "/",
        "/",
        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: 待发送/待随访
        0, // 8: 已发送/随访成功
        0, // 9: 随访成功/随访失败
        "0%", // 10: 成功率
        "0%", // 11: 随访率
        "0%", // 12: 及时率
      ];
      const methodFields = this.getMethodColumns().reduce(
        (arr, g) => arr.concat(g.fields),
        []
      );
      const methodStartIndex = 13;
      methodFields.forEach(() => summaries.push(0));
      this.tableData.forEach((item) => {
        summaries[3] += Number(item.dischargeCount) || 0;
        summaries[4] += Number(item.nonFollowUp) || 0;
        summaries[5] += Number(item.followUpNeeded) || 0;
        summaries[6] += Number(item.needFollowUp) || 0;
        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;
        if (this.isTargetHospital) {
          summaries[7] += Number(item.pendingFollowUpWaitSend) || 0;
          summaries[8] += Number(item.pendingFollowUpSent) || 0;
          summaries[9] += Number(item.followUpSuccess) || 0;
        } else {
          summaries[7] += Number(item.pendingFollowUp) || 0;
          summaries[8] += Number(item.followUpSuccess) || 0;
          summaries[9] += Number(item.followUpFail) || 0;
        }
        methodFields.forEach((field, i) => {
          summaries[methodStartIndex + i] += Number(item[field]) || 0;
        });
      });
      // 成功率计算:随访成功 / 需随访(目标医院),否则 随访成功 / (需随访-待随访)
      const totalSuccess = this.isTargetHospital ? summaries[9] : summaries[8];
      const totalNeed = summaries[6]; // needFollowUp的总和
      const totalPending = summaries[7]; // 待发送/待随访的总和
      const denominator = this.isTargetHospital
        ? totalNeed
        : 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) + "%";
      }
      if (rateValues.length > 0) {
        const avgRate =
          rateValues.reduce((sum, val) => sum + val, 0) / rateValues.length;
        summaries[11] = (avgRate * 100).toFixed(2) + "%";
      // 及时率计算:目标医院 (需随访-人工超时)/需随访,其他取后端 rate 平均
      if (this.isTargetHospital) {
        const totalTimeout = this.tableData.reduce(
          (sum, item) => sum + (Number(item.manualCallTimeout) || 0),
          0
        );
        summaries[12] = this.calculateTimelyRate(totalNeed, totalTimeout);
      } else {
        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[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]);
      // 格式化数字
      const numericIndices = [3, 4, 5, 6, 7, 8, 9].concat(
        methodFields.map((_, i) => methodStartIndex + i)
      );
      numericIndices.forEach((index) => {
        summaries[index] = this.formatNumber(summaries[index]);
      });
      return summaries;
    },
@@ -1117,18 +2456,50 @@
      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,
      //   starttime: this.parseTime(dateRange[0]),
      //   endtime: this.parseTime(dateRange[1]),
      //   deptcode: row.deptcode,
      // };
      this.patientqueryParams.starttime = this.parseTime(dateRange[0]);
      this.patientqueryParams.endtime = this.parseTime(dateRange[1]);
      this.patientqueryParams.deptcode = row.deptcode;
      // 应随访时间范围
      if (queryParams.endTime) {
        this.patientqueryParams.starttime = queryParams.startTime;
        this.patientqueryParams.endtime = queryParams.endTime;
      } else {
        this.patientqueryParams.starttime = this.parseTime(
          queryParams.dateRange[0]
        );
        this.patientqueryParams.endtime = this.parseTime(
          queryParams.dateRange[1]
        );
      }
      // 出院时间范围
      if (queryParams.hospitalEndTime) {
        this.patientqueryParams.startOutHospTime =
          queryParams.hospitalStartTime;
        this.patientqueryParams.endOutHospTime = queryParams.hospitalEndTime;
      } else {
        this.patientqueryParams.startOutHospTime = this.parseTime(
          queryParams.dateRangecy[0]
        );
        this.patientqueryParams.endOutHospTime = this.parseTime(
          queryParams.dateRangecy[1]
        );
      }
      // 统计类型:病区统计(1)传病区code,科室统计(2)传科室code
      if (queryParams.statisticaltype == 1) {
        this.patientqueryParams.leavehospitaldistrictcode =
          row.leavehospitaldistrictcode;
        this.patientqueryParams.deptcode = null;
      } else {
        this.patientqueryParams.deptcode = row.deptcode;
        this.patientqueryParams.leavehospitaldistrictcode = null;
      }
      this.patientqueryParams.serviceTypes = queryParams.serviceType
        ? Array.isArray(queryParams.serviceType)
          ? queryParams.serviceType.join(",")
          : String(queryParams.serviceType)
        : null;
      return selectTimelyRate(this.patientqueryParams);
    },
    selectTimelyRates(dateRange) {