| | |
| | | plain |
| | | icon="el-icon-download" |
| | | size="medium" |
| | | @click="handleExport" |
| | | @click="exportTable" |
| | | >导åº</el-button |
| | | > |
| | | <el-button |
| | |
| | | </el-form> |
| | | <div class="your-table-container"> |
| | | <el-table |
| | | ref="exportTable" |
| | | id="exportTableid" |
| | | v-loading="loading" |
| | | :data="userList" |
| | | :border="true" |
| | |
| | | } from "@/api/system/label"; |
| | | import store from "@/store"; |
| | | import { getSfStatistics, selectTimelyRate } from "@/api/system/user"; |
| | | |
| | | import * as XLSX from "xlsx"; |
| | | import FileSaver from "file-saver"; |
| | | import ExcelJS from "exceljs"; |
| | | import { saveAs } from "file-saver"; |
| | | import Treeselect from "@riophae/vue-treeselect"; |
| | | import "@riophae/vue-treeselect/dist/vue-treeselect.css"; |
| | | const shortcuts = [ |
| | |
| | | sums[index] = "å计"; |
| | | return; |
| | | } |
| | | if (index === 1||index === 2) { |
| | | if (index === 1 || index === 2) { |
| | | sums[index] = "/"; |
| | | return; |
| | | } |
| | |
| | | }) |
| | | .catch(() => {}); |
| | | }, |
| | | /** å¯¼åºæé®æä½ */ |
| | | handleExport() { |
| | | const params = { |
| | | ...this.queryParams, |
| | | // 妿鿩äº"å
¨é¨"ï¼åä¼ ææç
åº/ç§å®¤ä»£ç |
| | | leavehospitaldistrictcodes: |
| | | this.queryParams.leavehospitaldistrictcodes.includes("all") |
| | | ? this.allWardCodes |
| | | : this.queryParams.leavehospitaldistrictcodes, |
| | | deptcodes: this.queryParams.deptcodes.includes("all") |
| | | ? this.allDeptCodes |
| | | : this.queryParams.deptcodes, |
| | | }; |
| | | delete params.leavehospitaldistrictcodes.all; |
| | | delete params.deptcodes.all; |
| | | console.log(params); |
| | | // å¯¼åºæ¹æ³ |
| | | // æ¿æ¢æ¨åæ¥ç exportTable æ¹æ³ |
| | | async exportTable() { |
| | | try { |
| | | // è·åå½åæ¥æ |
| | | const now = new Date(); |
| | | // è·åå½åæä»½ï¼æ³¨ææä»½ä»0å¼å§ï¼éè¦å 1ï¼ |
| | | const currentMonth = now.getMonth() + 1; |
| | | // æå»ºæä»¶å |
| | | const excelName = `${currentMonth}æåºé¢é访ç»è®¡è¡¨.xlsx`; |
| | | // å建æ°çå·¥ä½ç°¿åå·¥ä½è¡¨ |
| | | const workbook = new ExcelJS.Workbook(); |
| | | const worksheet = workbook.addWorksheet("é访ç»è®¡"); |
| | | |
| | | this.download( |
| | | "smartor/serviceSubtask/getSfStatisticsExport", |
| | | { |
| | | ...params, |
| | | }, |
| | | `user_${new Date().getTime()}.xlsx` |
| | | ); |
| | | // å®ä¹æ ·å¼ |
| | | const headerStyle = { |
| | | font: { |
| | | name: "微软é
é»", |
| | | size: 11, |
| | | bold: true, |
| | | color: { argb: "FF000000" }, |
| | | }, |
| | | fill: { |
| | | type: "pattern", |
| | | pattern: "solid", |
| | | fgColor: { argb: "FFF5F7FA" }, |
| | | }, |
| | | alignment: { |
| | | vertical: "middle", |
| | | horizontal: "center", |
| | | wrapText: true, |
| | | }, |
| | | border: { |
| | | top: { style: "thin", color: { argb: "FFD0D0D0" } }, |
| | | left: { style: "thin", color: { argb: "FFD0D0D0" } }, |
| | | bottom: { style: "thin", color: { argb: "FFD0D0D0" } }, |
| | | right: { style: "thin", color: { argb: "FFD0D0D0" } }, |
| | | }, |
| | | }; |
| | | |
| | | const cellStyle = { |
| | | font: { |
| | | name: "å®ä½", |
| | | size: 10, |
| | | color: { argb: "FF000000" }, |
| | | }, |
| | | alignment: { |
| | | vertical: "middle", |
| | | horizontal: "center", |
| | | }, |
| | | border: { |
| | | top: { style: "thin", color: { argb: "FFD0D0D0" } }, |
| | | left: { style: "thin", color: { argb: "FFD0D0D0" } }, |
| | | bottom: { style: "thin", color: { argb: "FFD0D0D0" } }, |
| | | right: { style: "thin", color: { argb: "FFD0D0D0" } }, |
| | | }, |
| | | }; |
| | | |
| | | const summaryStyle = { |
| | | font: { |
| | | name: "å®ä½", |
| | | size: 10, |
| | | bold: true, |
| | | color: { argb: "FF409EFF" }, |
| | | }, |
| | | fill: { |
| | | type: "pattern", |
| | | pattern: "solid", |
| | | fgColor: { argb: "FFF5F7FA" }, |
| | | }, |
| | | alignment: { |
| | | vertical: "middle", |
| | | horizontal: "center", |
| | | }, |
| | | border: { |
| | | top: { style: "thin", color: { argb: "FFD0D0D0" } }, |
| | | left: { style: "thin", color: { argb: "FFD0D0D0" } }, |
| | | bottom: { style: "thin", color: { argb: "FFD0D0D0" } }, |
| | | right: { style: "thin", color: { argb: "FFD0D0D0" } }, |
| | | }, |
| | | }; |
| | | |
| | | // 1. é¦å
ï¼å建并设置第äºè¡ï¼å表头ï¼çææåå
æ ¼ |
| | | const secondRowHeaders = [ |
| | | "", // A2 å±å¼åå ä½ï¼å
¶å¼å°ç±ç¬¬ä¸è¡åå¹¶åç主åå
æ ¼å³å®ï¼ |
| | | "åºé¢ç
åº", |
| | | "ç§å®¤", |
| | | "åºé¢äººæ¬¡", |
| | | "æ éé访人次", |
| | | "åºé访人次", // B2 to F2 |
| | | // 馿¬¡åºé¢é访å表头 |
| | | "éé访", |
| | | "å¾
é访", |
| | | "é访æå", |
| | | "é访失败", |
| | | "é访ç", |
| | | "åæ¶ç", |
| | | "人工", |
| | | "çä¿¡", |
| | | "微信", |
| | | // 忬¡åºé¢é访å表头 |
| | | "éé访", |
| | | "å¾
é访", |
| | | "é访æå", |
| | | "é访失败", |
| | | "é访ç", |
| | | "人工", |
| | | "çä¿¡", |
| | | "微信", |
| | | ]; |
| | | |
| | | // æ·»å 第äºè¡å¹¶è®¾ç½®æ ·å¼ |
| | | secondRowHeaders.forEach((header, index) => { |
| | | // 注æï¼åç´¢å¼ä»1å¼å§ï¼å¯¹åºA忝1ï¼B忝2ï¼ä»¥æ¤ç±»æ¨ã |
| | | const cell = worksheet.getCell(2, index + 1); |
| | | cell.value = header; |
| | | cell.style = headerStyle; |
| | | }); |
| | | |
| | | // 2. ç¶åï¼å建第ä¸è¡ç主æ é¢åå
æ ¼å¹¶è®¾ç½®æ ·å¼ï¼ç´§æ¥çè¿è¡çºµååå¹¶ |
| | | // åå¹¶ A1:A2 å¹¶è®¾ç½®å¼ |
| | | worksheet.mergeCells(1, 1, 2, 1); // åå¹¶ A1 å° A2 |
| | | worksheet.getCell(1, 1).value = ""; // 设置主åå
æ ¼(A1)çå¼ |
| | | worksheet.getCell(1, 1).style = headerStyle; // 设置主åå
æ ¼æ ·å¼ |
| | | |
| | | // åå¹¶ B1:B2 å¹¶è®¾ç½®å¼ |
| | | worksheet.mergeCells(1, 2, 2, 2); // åå¹¶ B1 å° B2 |
| | | worksheet.getCell(1, 2).value = "åºé¢ç
åº"; |
| | | worksheet.getCell(1, 2).style = headerStyle; |
| | | |
| | | // åå¹¶ C1:C2 å¹¶è®¾ç½®å¼ |
| | | worksheet.mergeCells(1, 3, 2, 3); // åå¹¶ C1 å° C2 |
| | | worksheet.getCell(1, 3).value = "ç§å®¤"; |
| | | worksheet.getCell(1, 3).style = headerStyle; |
| | | |
| | | // åå¹¶ D1:D2 å¹¶è®¾ç½®å¼ |
| | | worksheet.mergeCells(1, 4, 2, 4); // åå¹¶ D1 å° D2 |
| | | worksheet.getCell(1, 4).value = "åºé¢äººæ¬¡"; |
| | | worksheet.getCell(1, 4).style = headerStyle; |
| | | |
| | | // åå¹¶ E1:E2 å¹¶è®¾ç½®å¼ |
| | | worksheet.mergeCells(1, 5, 2, 5); // åå¹¶ E1 å° E2 |
| | | worksheet.getCell(1, 5).value = "æ éé访人次"; |
| | | worksheet.getCell(1, 5).style = headerStyle; |
| | | |
| | | // åå¹¶ F1:F2 å¹¶è®¾ç½®å¼ |
| | | worksheet.mergeCells(1, 6, 2, 6); // åå¹¶ F1 å° F2 |
| | | worksheet.getCell(1, 6).value = "åºé访人次"; |
| | | worksheet.getCell(1, 6).style = headerStyle; |
| | | |
| | | // 3. 设置第ä¸è¡ç横ååå¹¶æ é¢ï¼è¿äºä¿æä¸åï¼å ä¸ºåªæ¶å第ä¸è¡ï¼ |
| | | // 馿¬¡åºé¢é访ï¼åå¹¶G1å°O1ï¼ |
| | | worksheet.mergeCells("G1:O1"); |
| | | worksheet.getCell("G1").value = "馿¬¡åºé¢é访"; |
| | | worksheet.getCell("G1").style = headerStyle; |
| | | |
| | | // 忬¡åºé¢é访ï¼åå¹¶P1å°W1ï¼ |
| | | worksheet.mergeCells("P1:W1"); |
| | | worksheet.getCell("P1").value = "忬¡åºé¢é访"; |
| | | worksheet.getCell("P1").style = headerStyle; |
| | | |
| | | // 4. 设置è¡é«ï¼å¯éï¼ä½å»ºè®®è®¾ç½®ï¼ |
| | | worksheet.getRow(1).height = 28; // 第ä¸è¡è¡é« |
| | | worksheet.getRow(2).height = 25; // 第äºè¡è¡é« |
| | | |
| | | // æ·»å æ°æ®è¡ |
| | | this.userList.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, |
| | | // 忬¡åºé¢éè®¿æ°æ® |
| | | item.needFollowUpAgain || 0, |
| | | item.pendingFollowUpAgain || 0, |
| | | item.followUpSuccessAgain || 0, |
| | | item.followUpFailAgain || 0, |
| | | item.followUpRateAgain || "0%", |
| | | item.manualAgain || 0, |
| | | item.smsAgain || 0, |
| | | item.weChatAgain || 0, |
| | | ]); |
| | | |
| | | // åºç¨æ°æ®è¡æ ·å¼ |
| | | dataRow.eachCell((cell) => { |
| | | cell.style = cellStyle; |
| | | }); |
| | | dataRow.height = 24; |
| | | }); |
| | | |
| | | // æ·»å åè®¡è¡ |
| | | const summaries = this.getSummaries({ |
| | | columns: [ |
| | | { property: "" }, |
| | | { property: "leavehospitaldistrictname" }, |
| | | { property: "deptname" }, |
| | | { property: "dischargeCount" }, |
| | | { property: "nonFollowUp" }, |
| | | { property: "followUpNeeded" }, |
| | | { property: "needFollowUp" }, |
| | | { property: "pendingFollowUp" }, |
| | | { property: "followUpSuccess" }, |
| | | { property: "followUpFail" }, |
| | | { property: "followUpRate" }, |
| | | { property: "rate" }, |
| | | { property: "manual" }, |
| | | { property: "sms" }, |
| | | { property: "weChat" }, |
| | | { property: "needFollowUpAgain" }, |
| | | { property: "pendingFollowUpAgain" }, |
| | | { property: "followUpSuccessAgain" }, |
| | | { property: "followUpFailAgain" }, |
| | | { property: "followUpRateAgain" }, |
| | | { property: "manualAgain" }, |
| | | { property: "smsAgain" }, |
| | | { property: "weChatAgain" }, |
| | | ], |
| | | data: this.userList, |
| | | }); |
| | | |
| | | const summaryRow = worksheet.addRow(summaries); |
| | | summaryRow.eachCell((cell, colNumber) => { |
| | | cell.style = summaryStyle; |
| | | // 第ä¸åæ¾ç¤º"å计" |
| | | if (colNumber === 1) { |
| | | cell.value = "å计"; |
| | | } |
| | | }); |
| | | 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 }, |
| | | // 忬¡åºé¢é访å |
| | | { width: 10 }, |
| | | { width: 10 }, |
| | | { width: 10 }, |
| | | { width: 10 }, |
| | | { width: 12 }, |
| | | { width: 8 }, |
| | | { width: 8 }, |
| | | { width: 8 }, |
| | | ]; |
| | | |
| | | // çæå¹¶ä¸è½½æä»¶ |
| | | 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; |
| | | } |
| | | }, |
| | | |
| | | // æ¾ç¤ºå¾è¡¨å¼¹çª |
| | | |
| | | showChartDialog() { |
| | |
| | | } |
| | | |
| | | // ç¾åæ¯åæ®µç¹æ®æ ·å¼ |
| | | .your-table-container ::v-deep .el-table__footer .el-table__cell[data-field="followUpRate"] .cell, |
| | | .your-table-container ::v-deep .el-table__footer .el-table__cell[data-field="rate"] .cell, |
| | | .your-table-container ::v-deep .el-table__footer .el-table__cell[data-field="followUpRateAgain"] .cell { |
| | | .your-table-container |
| | | ::v-deep |
| | | .el-table__footer |
| | | .el-table__cell[data-field="followUpRate"] |
| | | .cell, |
| | | .your-table-container |
| | | ::v-deep |
| | | .el-table__footer |
| | | .el-table__cell[data-field="rate"] |
| | | .cell, |
| | | .your-table-container |
| | | ::v-deep |
| | | .el-table__footer |
| | | .el-table__cell[data-field="followUpRateAgain"] |
| | | .cell { |
| | | color: #e6a23c !important; |
| | | font-weight: 700 !important; |
| | | } |