WXL (wul)
5 天以前 ba1ad6cff887cecb836a9fff87d84c146c820ad7
src/views/sfstatistics/percentage/index.vue
@@ -1700,15 +1700,43 @@
    // 替换您原来的 exportTable 方法
    async exportTable() {
      try {
        // 获取当前日期
        // 1. 获取并格式化日期范围
        let dateRangeString = ""; // 用于文件名
        let sheetNameSuffix = ""; // 用于工作表名
        // 检查是否存在选中的日期范围
        if (
          this.queryParams.dateRange &&
          this.queryParams.dateRange.length === 2
        ) {
          const startDateStr = this.queryParams.dateRange[0]; // 开始日期字符串,例如 "2026-01-01 00:00:00"
          const endDateStr = this.queryParams.dateRange[1]; // 结束日期字符串
          // 格式化日期为 YYYY-MM-DD(去掉时间部分)
          const formatDateForDisplay = (dateTimeStr) => {
            return dateTimeStr.split(" ")[0]; // 取空格前的部分,即 "YYYY-MM-DD"
          };
          const startDateFormatted = formatDateForDisplay(startDateStr);
          const endDateFormatted = formatDateForDisplay(endDateStr);
          // 构建日期范围字符串
          dateRangeString = `${startDateFormatted}至${endDateFormatted}`;
          sheetNameSuffix = `${startDateFormatted}至${endDateFormatted}`;
        } else {
          // 如果没有选择日期范围,则使用当前月份作为备选方案
        const now = new Date();
        // 获取当前月份(注意月份从0开始,需要加1)
        const currentMonth = now.getMonth() + 1;
        // 构建文件名
        const excelName = `${currentMonth}月出院随访统计表.xlsx`;
          dateRangeString = `${currentMonth}月`;
          sheetNameSuffix = `${currentMonth}月`;
        }
        // 2. 动态构建文件名和工作表名
        const excelName = `出院随访统计表_${dateRangeString}.xlsx`;
        const worksheetName = `随访统计_${sheetNameSuffix}`; // 工作表名不能超过31个字符[2](@ref)
        // 创建新的工作簿和工作表
        const workbook = new ExcelJS.Workbook();
        const worksheet = workbook.addWorksheet(`${currentMonth}月出院随访统计表`);
        const worksheet = workbook.addWorksheet(worksheetName); // 使用动态工作表名
// 定义样式(新增总标题样式)
    const titleStyle = {
      font: {
@@ -1804,7 +1832,7 @@
// 1. 添加总标题行(第一行)
    worksheet.mergeCells(1, 1, 1, 23); // 合并A1到W1的所有列[1,4](@ref)
    const titleCell = worksheet.getCell(1, 1);
    titleCell.value = `${currentMonth}月出院随访统计表`; // 使用文件名作为总标题
        titleCell.value = `${sheetNameSuffix}出院随访统计表`; // 使用文件名作为总标题
    titleCell.style = titleStyle;
    worksheet.getRow(1).height = 35; // 设置总标题行高
        // 1. 首先,创建并设置第二行(子表头)的所有单元格
@@ -1892,7 +1920,8 @@
    // 6. 添加数据行(注意行索引需要+1,因为上面插入了一行)
    this.userList.forEach((item, rowIndex) => {
      const dataRow = worksheet.addRow([
          const dataRow = worksheet.addRow(
            [
        "", // 展开列
        item.leavehospitaldistrictname || "",
        item.deptname || "",
@@ -1918,7 +1947,9 @@
        item.manualAgain || 0,
        item.smsAgain || 0,
        item.weChatAgain || 0,
      ], rowIndex + 4); // 从第4行开始添加数据(原第3行)
            ],
            rowIndex + 4
          ); // 从第4行开始添加数据(原第3行)
      // 应用数据行样式
      dataRow.eachCell((cell) => {