From ffa22cc18c75c0a73a3fd987e2b62fbf55316db2 Mon Sep 17 00:00:00 2001
From: WXL (wul) <wl_5969728@163.com>
Date: 星期四, 25 六月 2026 15:22:46 +0800
Subject: [PATCH] 测试完成
---
src/views/Satisfaction/sfstatistics/components/components/TopicDialog.vue | 321 +++++++++++++++++++++++++++++++----------------------
1 files changed, 188 insertions(+), 133 deletions(-)
diff --git a/src/views/Satisfaction/sfstatistics/components/components/TopicDialog.vue b/src/views/Satisfaction/sfstatistics/components/components/TopicDialog.vue
index 7b6fa0a..3095477 100644
--- a/src/views/Satisfaction/sfstatistics/components/components/TopicDialog.vue
+++ b/src/views/Satisfaction/sfstatistics/components/components/TopicDialog.vue
@@ -89,6 +89,7 @@
<script>
import ExcelJS from "exceljs";
import { saveAs } from "file-saver";
+
export default {
name: "TopicDialog",
props: {
@@ -100,6 +101,9 @@
type: Object,
default: () => ({}),
},
+ topType: {
+ type: String,
+ },
topicList: {
type: [Array, Object],
default: () => ({}),
@@ -107,211 +111,260 @@
},
data() {
return {
- processedTopicList: [], // 澶勭悊鍚庣殑鏁版嵁
+ processedTopicList: [],
+ orgname: "", // 鏂板锛氬尰闄㈠悕绉�
};
},
computed: {
configTitle() {
- // 浠庣埗绾� queryParams 涓鍙�
const key = this.queryParams?.configKey;
return key === "returnVisitCount" ? "澶嶈瘖閫氱煡" : "婊℃剰搴�";
},
},
+ created() {
+ // 鑾峰彇鍖婚櫌鍚嶇О
+ this.orgname = localStorage.getItem("orgname") || "";
+ },
watch: {
- // 鐩戝惉鐖剁粍浠朵紶閫掔殑鏁版嵁鍙樺寲
topicList: {
immediate: true,
handler(newVal) {
- console.log("TopicDialog鎺ユ敹鍒扮埗缁勪欢鏁版嵁:", newVal);
this.processTopicList(newVal);
},
},
},
- mounted() {
- console.log("TopicDialog mounted, props:", this.$props);
- },
methods: {
- // 澶勭悊topicList鏁版嵁
processTopicList(data) {
- console.log("寮�濮嬪鐞嗘暟鎹�:", data);
-
if (!data || typeof data !== "object") {
this.processedTopicList = [];
return;
}
- // 灏嗗璞¤浆鎹负鏁扮粍
const result = [];
-
Object.keys(data).forEach((key) => {
const item = data[key];
if (item && item.scriptContent) {
- // 娣辨嫹璐漣tem锛岄伩鍏嶄慨鏀瑰師鏁版嵁
const processedItem = JSON.parse(JSON.stringify(item));
- // 杩囨护details锛屽彧淇濈暀鏈夐�夐」鏂囨湰鐨�
if (processedItem.details && Array.isArray(processedItem.details)) {
processedItem.details = processedItem.details.filter(
(detail) => detail && detail.optionText
);
}
-
result.push(processedItem);
}
});
- console.log("澶勭悊鍚庣殑鏁版嵁:", result);
this.processedTopicList = result;
},
- /** 瀵煎嚭棰樼洰鏄庣粏 */
+
+ // 鏍煎紡鍖栨棩鏈熻寖鍥村瓧绗︿覆锛堜笌涓婚〉闈竴鑷达級
+ formatDateRangeForExport() {
+ let dateRangeString = "";
+ let sheetNameSuffix = "";
+ const isLishuiHospital = this.orgname == "涓芥按甯備腑鍖婚櫌";
+
+ if (
+ this.queryParams.dateRange &&
+ this.queryParams.dateRange.length === 2
+ ) {
+ const startDateStr = this.queryParams.dateRange[0];
+ const endDateStr = this.queryParams.dateRange[1];
+
+ if (isLishuiHospital) {
+ // 涓芥按甯備腑鍖婚櫌锛氬彧鏄剧ず骞存湀
+ const formatMonthOnly = (dateStr) => {
+ const date = new Date(dateStr);
+ 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 = (dateStr) => {
+ return dateStr.split(" ")[0]; // 濡傛灉鍖呭惈鏃堕棿閮ㄥ垎锛屽彧鍙栨棩鏈�
+ };
+ const startDateFormatted = formatDateForDisplay(startDateStr);
+ const endDateFormatted = formatDateForDisplay(endDateStr);
+ dateRangeString = `${startDateFormatted}鑷�${endDateFormatted}`;
+ sheetNameSuffix = `${startDateFormatted}鑷�${endDateFormatted}`;
+ }
+ } else {
+ const now = new Date();
+ const currentMonth = now.getMonth() + 1;
+ const currentYear = now.getFullYear();
+
+ if (isLishuiHospital) {
+ // 涓芥按甯備腑鍖婚櫌锛氭樉绀哄勾鏈�
+ dateRangeString = `${currentYear}骞�${currentMonth}鏈坄;
+ sheetNameSuffix = `${currentYear}骞�${currentMonth}鏈坄;
+ } else {
+ // 鍏朵粬鍖婚櫌锛氭樉绀烘湀浠�
+ dateRangeString = `${currentMonth}鏈坄;
+ sheetNameSuffix = `${currentMonth}鏈坄;
+ }
+ }
+
+ return { dateRangeString, sheetNameSuffix };
+ },
+
+ // 瀵煎嚭棰樼洰鏄庣粏
async exportTopicDetail() {
if (!this.processedTopicList.length) {
this.$message.warning("鏆傛棤鏁版嵁鍙鍑�");
return;
}
- const workbook = new ExcelJS.Workbook();
- const sheetName = `${
- this.rowData.leavehospitaldistrictname || this.rowData.deptname
- }${this.configTitle}鏄庣粏`;
- const worksheet = workbook.addWorksheet(sheetName);
+ try {
+ // 鑾峰彇鏍煎紡鍖栧悗鐨勬棩鏈熻寖鍥�
+ const { dateRangeString, sheetNameSuffix } =
+ this.formatDateRangeForExport();
- /* ---------- 鏍峰紡 ---------- */
- const titleStyle = {
- font: { name: "寰蒋闆呴粦", size: 14, bold: true },
- alignment: { horizontal: "center", vertical: "middle" },
- fill: {
- type: "pattern",
- pattern: "solid",
- fgColor: { argb: "FFF5F7FA" },
- },
- };
+ const workbook = new ExcelJS.Workbook();
+ const sheetName = `${
+ this.rowData.leavehospitaldistrictname || this.rowData.deptname
+ }${this.configTitle}鏄庣粏_${sheetNameSuffix}`;
+ const worksheet = workbook.addWorksheet(sheetName);
- const subtitleStyle = {
- font: { name: "寰蒋闆呴粦", size: 12, bold: true },
- alignment: { horizontal: "left", vertical: "middle" },
- };
+ // 鏍峰紡瀹氫箟锛堜繚鎸佷笉鍙橈級
+ const titleStyle = {
+ font: { name: "寰蒋闆呴粦", size: 14, bold: true },
+ alignment: { horizontal: "center", vertical: "middle" },
+ fill: {
+ type: "pattern",
+ pattern: "solid",
+ fgColor: { argb: "FFF5F7FA" },
+ },
+ };
- const headerStyle = {
- font: { name: "寰蒋闆呴粦", size: 11, bold: true },
- fill: {
- type: "pattern",
- pattern: "solid",
- fgColor: { argb: "FFEBEEF5" },
- },
- alignment: { horizontal: "center", vertical: "middle" },
- border: {
- top: { style: "thin" },
- left: { style: "thin" },
- bottom: { style: "thin" },
- right: { style: "thin" },
- },
- };
+ const subtitleStyle = {
+ font: { name: "寰蒋闆呴粦", size: 12, bold: true },
+ alignment: { horizontal: "left", vertical: "middle" },
+ };
- 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 headerStyle = {
+ font: { name: "寰蒋闆呴粦", size: 11, bold: true },
+ fill: {
+ type: "pattern",
+ pattern: "solid",
+ fgColor: { argb: "FFEBEEF5" },
+ },
+ alignment: { horizontal: "center", vertical: "middle" },
+ border: {
+ top: { style: "thin" },
+ left: { style: "thin" },
+ bottom: { style: "thin" },
+ right: { style: "thin" },
+ },
+ };
- /* ---------- 鏍囬鍖� ---------- */
- worksheet.mergeCells(1, 1, 1, 4);
- worksheet.getCell(1, 1).value = `${this.configTitle}棰樼洰鏄庣粏`;
- worksheet.getCell(1, 1).style = titleStyle;
+ const cellStyle = {
+ font: { name: "瀹嬩綋", size: 10 },
+ alignment: { horizontal: "center", vertical: "middle" },
+ border: {
+ top: { style: "thin" },
+ left: { style: "thin" },
+ bottom: { style: "thin" },
+ right: { style: "thin" },
+ },
+ };
- worksheet.mergeCells(2, 1, 2, 4);
- worksheet.getCell(2, 1).value = `缁熻瀵硅薄锛�${
- this.rowData.leavehospitaldistrictname || this.rowData.deptname
- }`;
- worksheet.getCell(2, 1).style = subtitleStyle;
+ // 鏍囬鍖�
+ worksheet.mergeCells(1, 1, 1, 4);
+ worksheet.getCell(
+ 1,
+ 1
+ ).value = `${this.configTitle}棰樼洰鏄庣粏锛�${dateRangeString}锛塦;
+ worksheet.getCell(1, 1).style = titleStyle;
- worksheet.mergeCells(3, 1, 3, 4);
- worksheet.getCell(3, 1).value = `缁熻鏃堕棿锛�${
- this.queryParams.dateRange?.[0] || "-"
- } 鑷� ${this.queryParams.dateRange?.[1] || "-"}`;
- worksheet.getCell(3, 1).style = subtitleStyle;
+ worksheet.mergeCells(2, 1, 2, 4);
+ worksheet.getCell(2, 1).value = `缁熻瀵硅薄锛�${
+ this.rowData.leavehospitaldistrictname || this.rowData.deptname
+ }`;
+ worksheet.getCell(2, 1).style = subtitleStyle;
- let currentRow = 5;
+ let currentRow = 4;
- /* ---------- 閫愰鍐欏叆 ---------- */
- this.processedTopicList.forEach((item, index) => {
- worksheet.mergeCells(currentRow, 1, currentRow, 4);
- worksheet.getCell(currentRow, 1).value = `绗�${index + 1}棰橈細${
- item.scriptContent
- } [${item.scriptType == 1 ? "鍗曢�夐" : "澶氶�夐"}]`;
- worksheet.getCell(currentRow, 1).style = subtitleStyle;
- currentRow++;
+ // 閫愰鍐欏叆
+ this.processedTopicList.forEach((item, index) => {
+ worksheet.mergeCells(currentRow, 1, currentRow, 4);
+ worksheet.getCell(currentRow, 1).value = `绗�${index + 1}棰橈細${
+ item.scriptContent
+ } [${item.scriptType == 1 ? "鍗曢�夐" : "澶氶�夐"}]`;
+ worksheet.getCell(currentRow, 1).style = subtitleStyle;
+ currentRow++;
- const headerRow = worksheet.addRow([
- "闂閫夐」",
- "閫夋嫨浜烘暟",
- "鍗犳瘮",
- "",
- ]);
- headerRow.eachCell((cell) => {
- cell.style = headerStyle;
- });
- currentRow++;
-
- item.details.forEach((detail) => {
- const percent =
- detail.chosenPercentage != null
- ? (Number(detail.chosenPercentage) * 100).toFixed(2) + "%"
- : "-";
-
- const row = worksheet.addRow([
- detail.optionText,
- detail.chosenQuantity || 0,
- percent,
+ const headerRow = worksheet.addRow([
+ "闂閫夐」",
+ "閫夋嫨浜烘暟",
+ "鍗犳瘮",
"",
]);
- row.eachCell((cell) => {
- cell.style = cellStyle;
+ headerRow.eachCell((cell) => {
+ cell.style = headerStyle;
});
+ currentRow++;
+
+ item.details.forEach((detail) => {
+ const percent =
+ detail.chosenPercentage != null
+ ? (Number(detail.chosenPercentage) * 100).toFixed(2) + "%"
+ : "-";
+
+ const row = worksheet.addRow([
+ detail.optionText,
+ detail.chosenQuantity || 0,
+ percent,
+ "",
+ ]);
+ row.eachCell((cell) => {
+ cell.style = cellStyle;
+ });
+ currentRow++;
+ });
+
currentRow++;
});
- currentRow++;
- });
+ // 璁剧疆鍒楀
+ worksheet.columns = [
+ { width: 40 },
+ { width: 12 },
+ { width: 12 },
+ { width: 10 },
+ ];
- /* ---------- 鍒楀 ---------- */
- worksheet.columns = [
- { width: 40 },
- { width: 12 },
- { width: 12 },
- { width: 10 },
- ];
+ // 鐢熸垚鏂囦欢鍚嶏紙涓庝富椤甸潰淇濇寔涓�鑷达級
+ const fileName = `${
+ this.rowData.leavehospitaldistrictname || this.rowData.deptname
+ }${this.configTitle}鏄庣粏_${dateRangeString}.xlsx`;
- /* ---------- 瀵煎嚭 ---------- */
- const buffer = await workbook.xlsx.writeBuffer();
- const fileName =
- `${this.rowData.leavehospitaldistrictname || this.rowData.deptname}` +
- `${this.configTitle}鏄庣粏_` +
- `${this.queryParams.dateRange?.[0]}鑷�${this.queryParams.dateRange?.[1]}.xlsx`;
+ const buffer = await workbook.xlsx.writeBuffer();
+ saveAs(
+ new Blob([buffer], {
+ type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ }),
+ fileName
+ );
- saveAs(
- new Blob([buffer], {
- type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
- }),
- fileName
- );
-
- this.$message.success("瀵煎嚭鎴愬姛");
+ this.$message.success("瀵煎嚭鎴愬姛");
+ } catch (error) {
+ console.error("瀵煎嚭澶辫触:", error);
+ this.$message.error(`瀵煎嚭澶辫触: ${error.message}`);
+ }
},
- // 鏍煎紡鍖栫櫨鍒嗘瘮
+
formatPercent(value) {
if (value === null || value === undefined) return "-";
const num = parseFloat(value);
if (isNaN(num)) return "-";
- return `${num.toFixed(2)}%`; // 娉ㄦ剰锛氫綘鐨勬暟鎹腑鐧惧垎姣斿凡缁忔槸0-100鐨勫舰寮�
+ return `${num.toFixed(2)}%`;
},
- // 鍏抽棴瀵硅瘽妗�
handleClose() {
this.$emit("close");
},
@@ -354,6 +407,7 @@
overflow: hidden;
font-size: 14px;
}
+
.dialog-header {
display: flex;
justify-content: space-between;
@@ -368,6 +422,7 @@
color: #303133;
}
}
+
::v-deep .el-table th {
background-color: #f1f5f9;
color: #333;
--
Gitblit v1.9.3