WXL (wul)
4 天以前 fb34ba28cb908bd328cf6690ab0b19a56428f4e2
src/views/sfstatistics/percentage/components/CombinedFollowUp.vue
@@ -1301,7 +1301,7 @@
      };
      // 标题行
      worksheet.mergeCells(1, 1, 1, 20);
      worksheet.mergeCells(1, 1, 1, 26);
      worksheet.getCell(
        1,
        1
@@ -1356,13 +1356,40 @@
        worksheet.getCell(3, col).style = headerStyle;
      });
      // 新增计算指标
      worksheet.mergeCells(2, 16, 3, 16);
      worksheet.getCell(2, 16).value = "随访率";
      // 随访情况大列(正常语音/拒接或拒访/面访或接诊/微信/电话不正确/其他)
      worksheet.mergeCells(2, 16, 2, 21);
      worksheet.getCell(2, 16).value = "随访情况";
      worksheet.getCell(2, 16).style = headerStyle;
      worksheet.mergeCells(2, 17, 3, 17);
      worksheet.getCell(2, 17).value = "推送率";
      worksheet.getCell(2, 17).style = headerStyle;
      const situationCols = [
        "正常语音",
        "患者拒接或拒访",
        "面访或者接诊",
        "微信随访",
        "随访电话不正确",
        "其他情况不宜随访",
      ];
      situationCols.forEach((label, idx) => {
        const col = 16 + idx;
        worksheet.getCell(3, col).value = label;
        worksheet.getCell(3, col).style = headerStyle;
      });
      // 新增计算指标
      worksheet.mergeCells(2, 22, 3, 22);
      worksheet.getCell(2, 22).value = "随访率";
      worksheet.getCell(2, 22).style = headerStyle;
      worksheet.mergeCells(2, 23, 3, 23);
      worksheet.getCell(2, 23).value = "推送率";
      worksheet.getCell(2, 23).style = headerStyle;
      worksheet.mergeCells(2, 24, 3, 24);
      worksheet.getCell(2, 24).value = "已拨通";
      worksheet.getCell(2, 24).style = headerStyle;
      worksheet.mergeCells(2, 25, 3, 25);
      worksheet.getCell(2, 25).value = "再次随访推送人数";
      worksheet.getCell(2, 25).style = headerStyle;
      worksheet.mergeCells(2, 26, 3, 26);
      worksheet.getCell(2, 26).value = "追踪随访推送率";
      worksheet.getCell(2, 26).style = headerStyle;
      // 数据行
      this.tableData.forEach((item) => {
@@ -1390,8 +1417,17 @@
            item.needFollowUpAgain,
            item.pendingFollowUpAgain
          ),
          item.taskSituation1 || 0,
          item.taskSituation2 || 0,
          item.taskSituation3 || 0,
          item.taskSituation4 || 0,
          item.taskSituation5 || 0,
          item.taskSituation6 || 0,
          this.calculateFollowUpRate(item),
          this.calculatePushRate(item),
          item.manuallyCalled || 0,
          item.againFollowUpPushCount || 0,
          this.calculateAgainFollowUpPushRate(item),
        ];
        const row = worksheet.addRow(rowData);
        row.eachCell((cell) => {
@@ -1426,61 +1462,77 @@
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
        { width: 12 },
      ];
    },
    getExportSummaries() {
      // 提取数据,计算合计行
      // 提取数据,计算合计行(26 列:与主表导出表头一致)
      const data = this.tableData;
      const sums = [
        "合计",
        "/",
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        "0%",
        0,
        0,
        0,
        0,
        "0%",
        "0%",
        "0%",
        "合计", // 0
        "/", // 1
        0, // 2 出院人次
        0, // 3 无需随访
        0, // 4 应随访
        0, // 5 需随访(首次)
        0, // 6 待随访(首次)
        0, // 7 完成(首次)
        0, // 8 失败(首次)
        "0.00%", // 9 成功率(首次)
        0, // 10 需随访(再次)
        0, // 11 待随访(再次)
        0, // 12 完成(再次)
        0, // 13 失败(再次)
        "0.00%", // 14 成功率(再次)
        0, // 15 正常语音
        0, // 16 患者拒接或拒访
        0, // 17 面访或者接诊
        0, // 18 微信随访
        0, // 19 随访电话不正确
        0, // 20 其他情况不宜随访
        "0.00%", // 21 随访率
        "0.00%", // 22 推送率
        0, // 23 已拨通
        0, // 24 再次随访推送人数
        "0.00%", // 25 追踪随访推送率
      ];
      // 数字列索引
      const numIndices = [2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13];
      data.forEach((row) => {
        numIndices.forEach((idx) => {
          const val = Number(row[this.getFieldByIndex(idx)]) || 0;
          sums[idx] += val;
        });
      // 数字列求和(索引 -> 字段名)
      const numFields = [
        [2, "dischargeCount"],
        [3, "nonFollowUp"],
        [4, "followUpNeeded"],
        [5, "needFollowUp"],
        [6, "pendingFollowUp"],
        [7, "followUpSuccess"],
        [8, "followUpFail"],
        [10, "needFollowUpAgain"],
        [11, "pendingFollowUpAgain"],
        [12, "followUpSuccessAgain"],
        [13, "followUpFailAgain"],
        [15, "taskSituation1"],
        [16, "taskSituation2"],
        [17, "taskSituation3"],
        [18, "taskSituation4"],
        [19, "taskSituation5"],
        [20, "taskSituation6"],
        [23, "manuallyCalled"],
        [24, "againFollowUpPushCount"],
      ];
      numFields.forEach(([idx, field]) => {
        sums[idx] = this.formatNumber(
          data.reduce((s, row) => s + (Number(row[field]) || 0), 0)
        );
      });
      // 格式化数字
      numIndices.forEach((idx) => {
        sums[idx] = this.formatNumber(sums[idx]);
      });
      // 计算两个百分比列的平均值
      const followUpRates = data
        .map((row) =>
          parseFloat(this.calculateFollowUpRate(row).replace("%", ""))
        )
        .filter((v) => !isNaN(v));
      const pushRates = data
        .map((row) => parseFloat(this.calculatePushRate(row).replace("%", "")))
        .filter((v) => !isNaN(v));
      sums[15] = followUpRates.length
        ? (
            followUpRates.reduce((a, b) => a + b, 0) / followUpRates.length
          ).toFixed(2) + "%"
        : "0.00%";
      sums[16] = pushRates.length
        ? (pushRates.reduce((a, b) => a + b, 0) / pushRates.length).toFixed(2) +
          "%"
        : "0.00%";
      // 成功率的合计用整体法计算
      const totalSuccess = data.reduce(
        (s, row) => s + (Number(row.followUpSuccess) || 0),
@@ -1514,6 +1566,40 @@
        denomAgain > 0
          ? ((totalSuccessAgain / denomAgain) * 100).toFixed(2) + "%"
          : "0.00%";
      // 随访率 / 推送率:取各行的平均值
      const followUpRates = data
        .map((row) =>
          parseFloat(this.calculateFollowUpRate(row).replace("%", ""))
        )
        .filter((v) => !isNaN(v));
      sums[21] = followUpRates.length
        ? (
            followUpRates.reduce((a, b) => a + b, 0) / followUpRates.length
          ).toFixed(2) + "%"
        : "0.00%";
      const pushRates = data
        .map((row) => parseFloat(this.calculatePushRate(row).replace("%", "")))
        .filter((v) => !isNaN(v));
      sums[22] = pushRates.length
        ? (pushRates.reduce((a, b) => a + b, 0) / pushRates.length).toFixed(2) +
          "%"
        : "0.00%";
      // 追踪随访推送率:整体法 = 再次随访推送人数合计 / 出院人次合计
      const totalPush = data.reduce(
        (s, row) => s + (Number(row.againFollowUpPushCount) || 0),
        0
      );
      const totalDischarge = data.reduce(
        (s, row) => s + (Number(row.dischargeCount) || 0),
        0
      );
      sums[25] =
        totalDischarge > 0
          ? ((totalPush / totalDischarge) * 100).toFixed(2) + "%"
          : "0.00%";
      return sums;
    },