From 74fbc27a3dd58c1de0e50d2ef9406f47c9f911eb Mon Sep 17 00:00:00 2001
From: Euni4U <958079825@qq.com>
Date: Tue, 22 Apr 2025 11:49:05 +0800
Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0=E5=B7=A5=E4=BD=9C=E9=87=8F?=
=?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=A0=B7=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/views/sta/index.vue | 106 ++++++++++++++
src/views/sta/printHelper.js | 143 +++++++++++++++++++
src/views/sta/workload.js | 265 +++++++++++++++++++++++++++++++++++
3 files changed, 514 insertions(+)
create mode 100644 src/views/sta/printHelper.js
create mode 100644 src/views/sta/workload.js
diff --git a/src/views/sta/index.vue b/src/views/sta/index.vue
index c98035e..50433f7 100644
--- a/src/views/sta/index.vue
+++ b/src/views/sta/index.vue
@@ -20,6 +20,9 @@
/>
查询
+
+
+ 打印
@@ -51,6 +54,9 @@ import {StatisticsApi} from "@/api/inspect/statistics";
import dayjs from "dayjs";
import {PatientApi} from "@/api/inspect/inspectpatient";
import {formatDate} from "@/utils/formatTime";
+import workload from './workload';
+import { hiprint } from "vue-plugin-hiprint";
+import { newHiprintPrintTemplate, preparePrintData } from './printHelper';
const time = ref() // 日期
const data = ref([
@@ -206,6 +212,106 @@ const dataProcessing = (data) => {
return value;
}
+/**
+ * 打印数据
+ */
+const printData = () => {
+ try {
+ // 创建打印模板
+ const hiprintTemplate = newHiprintPrintTemplate("workload", {
+ template: workload,
+ settingContainer: "#workloadPrintElementOptionSetting",
+ });
+
+ // 准备打印数据
+ const printData = preparePrintData(data1.value, time.value);
+ console.log('打印数据:', printData); // 添加调试信息
+
+ // 打印参数配置
+ const options = {
+ leftOffset: 0,
+ topOffset: 0,
+ paperType: 'A4',
+ enableColumnsMerge: true,
+ enableRowsMerge: true,
+ firstPageTitle: true,
+ onlyFirstTitle: true,
+ notAllowRepeat: ['title'],
+ firstPanelPageOnly: true,
+ pageMode: 'single',
+ displayMode: {
+ title: 'firstPage'
+ },
+ printPanelIndex: 0,
+ noRepeatPrint: false,
+ disableHeaderRepeat: false
+ };
+
+ // 样式设置
+ const ext = {
+ callback: () => {
+ console.log("打印窗口已打开");
+ // 添加表头样式
+ setTimeout(() => {
+ const table = document.querySelector('.hiprint-printPanel table');
+ if (table) {
+ const ths = table.querySelectorAll('th');
+ ths.forEach((th, index) => {
+ });
+ }
+ }, 100);
+ },
+ styleHandler: () => {
+ return ``;
+ },
+ };
+
+ // 调用打印
+ hiprintTemplate.print(printData, options, ext);
+
+ console.log('打印成功');
+ } catch (error) {
+ console.error('打印失败:', error);
+ }
+}
onMounted(()=>{
changeRadio(3)
// getList()
diff --git a/src/views/sta/printHelper.js b/src/views/sta/printHelper.js
new file mode 100644
index 0000000..5fc70d1
--- /dev/null
+++ b/src/views/sta/printHelper.js
@@ -0,0 +1,143 @@
+import { hiprint } from "vue-plugin-hiprint";
+
+const templateMap = {};
+
+/**
+ * 创建打印模板
+ * @param {string} key - 模板唯一标识
+ * @param {object} options - 模板配置
+ * @returns {object} 打印模板对象
+ */
+export function newHiprintPrintTemplate(key, options) {
+ let template = new hiprint.PrintTemplate(options);
+ // 添加表头样式
+ template.on('beforePrint', (data) => {
+ const table = document.querySelector('.hiprint-printPanel table');
+ if (table) {
+ const ths = table.querySelectorAll('th');
+ ths.forEach(th => {
+ th.style.fontWeight = 'bold';
+ th.style.fontSize = '12px';
+ });
+ }
+ });
+ templateMap[key] = template;
+ return template;
+}
+
+/**
+ * 获取打印模板
+ * @param {string} key - 模板唯一标识
+ * @returns {object} 打印模板对象
+ */
+export function getHiprintPrintTemplate(key) {
+ return templateMap[key];
+}
+
+/**
+ * 准备打印数据
+ * @param {Array} data - 原始数据
+ * @param {Array} timeRange - 时间范围
+ * @returns {object} 格式化后的打印数据
+ */
+export function preparePrintData(data, timeRange) {
+ // 防错处理
+ if (!data || !Array.isArray(data)) {
+ console.error('打印数据格式错误:', data);
+ return {
+ table: [],
+ dateRange: timeRange ? `${timeRange[0]} 至 ${timeRange[1]}` : '',
+ printDate: formatDate(new Date(), 'YYYY-MM-DD'),
+ printUser: '管理员',
+ title: '体检工作量统计表'
+ };
+ }
+
+ try {
+ // 将树形结构展平为表格结构
+ const flattenedData = [];
+
+ // 处理每个卫生院及其下属的行政村
+ data.forEach(org => {
+ if (!org || typeof org !== 'object') return; // 跳过无效数据
+
+ // 确保orgname存在
+ const orgname = org.orgname || '未知卫生院';
+
+ // 计算该卫生院下的行政村数量
+ const villageCount = org.children ? org.children.length : 0;
+
+ // 添加卫生院汇总行
+ flattenedData.push({
+ orgname: orgname,
+ districtname: '汇总',
+ oldmanflag: org.oldmanflag || 0,
+ htnflag: org.htnflag || 0,
+ diaflag: org.diaflag || 0,
+ smiflag: org.smiflag || 0,
+ pulflag: org.pulflag || 0,
+ sum: org.sum || 0,
+ rowspan: villageCount + 1, // 包括汇总行
+ isFirstRow: true
+ });
+
+ // 添加该卫生院下的所有行政村
+ if (org.children && Array.isArray(org.children) && org.children.length > 0) {
+ // 先对子项进行排序,保持数据一致性
+ const sortedChildren = [...org.children]
+ .filter(village => village && typeof village === 'object') // 过滤无效数据
+ .sort((a, b) => (b.sum || 0) - (a.sum || 0));
+
+ sortedChildren.forEach((village, index) => {
+ flattenedData.push({
+ orgname: '', // 空字符串,不显示卫生院名称
+ districtname: village.districtname || '未知行政村',
+ oldmanflag: village.oldmanflag || 0,
+ htnflag: village.htnflag || 0,
+ diaflag: village.diaflag || 0,
+ smiflag: village.smiflag || 0,
+ pulflag: village.pulflag || 0,
+ sum: village.sum || 0,
+ isChild: true
+ });
+ });
+ }
+ });
+
+ console.log('处理后的打印数据:', flattenedData);
+
+ return {
+ table: flattenedData,
+ dateRange: timeRange ? `${timeRange[0]} 至 ${timeRange[1]}` : '',
+ printDate: formatDate(new Date(), 'YYYY-MM-DD'),
+ printUser: '管理员',
+ title: '体检工作量统计表'
+ };
+ } catch (error) {
+ console.error('准备打印数据出错:', error);
+ return {
+ table: [],
+ dateRange: timeRange ? `${timeRange[0]} 至 ${timeRange[1]}` : '',
+ printDate: formatDate(new Date(), 'YYYY-MM-DD'),
+ printUser: '管理员',
+ title: '体检工作量统计表'
+ };
+ }
+}
+
+/**
+ * 格式化日期
+ * @param {Date} date - 日期对象
+ * @param {string} format - 格式
+ * @returns {string} 格式化后的日期字符串
+ */
+function formatDate(date, format) {
+ const year = date.getFullYear();
+ const month = String(date.getMonth() + 1).padStart(2, '0');
+ const day = String(date.getDate()).padStart(2, '0');
+
+ return format
+ .replace('YYYY', year)
+ .replace('MM', month)
+ .replace('DD', day);
+}
\ No newline at end of file
diff --git a/src/views/sta/workload.js b/src/views/sta/workload.js
new file mode 100644
index 0000000..ac55ffe
--- /dev/null
+++ b/src/views/sta/workload.js
@@ -0,0 +1,265 @@
+export default {
+ panels: [
+ {
+ index: 0,
+ name: 1,
+ paperType: "A4",
+ height: 297,
+ width: 210,
+ paperHeader: 24,
+ paperFooter: 805.5,
+ paperNumberLeft: 565.5,
+ paperNumberTop: 814.5,
+ paperNumberDisabled: true,
+ paperNumberContinue: true,
+ watermarkOptions: {},
+ panelLayoutOptions: {
+ firstPanelTitle: true,
+ onlyShowFirstPageTitle: true,
+ tableHeaderOnlyOnFirst: true,
+ disablePageRepeat: true,
+ disableHeaderRepeat: true
+ },
+ printElements: [
+ {
+ options: {
+ left: 174,
+ top: 15,
+ height: 27,
+ width: 204,
+ title: "体检工作量统计表",
+ fontSize: 19,
+ fontWeight: "600",
+ textAlign: "center",
+ lineHeight: 26,
+ showInPage: "first",
+ pageIndex: 0,
+ fixed: true,
+ onlyShowInFirstPage: true,
+ panelPaperRule: "first"
+ },
+ printElementType: {
+ title: "自定义文本",
+ type: "text"
+ }
+ },
+ {
+ options: {
+ left: 20,
+ top: 40,
+ height: 20,
+ width: 180,
+ title: "统计时间",
+ field: "dateRange",
+ testData: "2023-01-01 至 2023-12-31",
+ fontFamily: "微软雅黑",
+ fontSize: 9,
+ fontWeight: "600",
+ textAlign: "left",
+ repeat: "first"
+ },
+ printElementType: { title: "文本", type: "text" }
+ },
+ {
+ options: {
+ left: 15,
+ top: 70,
+ height: 64.5,
+ width: 555,
+ field: "table",
+ coordinateSync: false,
+ widthHeightSync: false,
+ right: 565,
+ bottom: 96,
+ vCenter: 290,
+ hCenter: 69,
+ tableHeaderRowHeight: 30,
+ tableBodyRowHeight: 30,
+ tableHeaderRepeat: "first",
+ noRepeat: false,
+ tableHeaderStyle: { fontWeight: "bold", fontSize: "12px" },
+ tableStyle: { border: "1px solid #000" },
+ rowsColumnsMerge: null,
+ rowsColumnsMergeClean: true,
+ columns: [
+ [
+ {
+ width: 70,
+ title: "卫生院",
+ field: "orgname",
+ checked: true,
+ columnId: "orgname",
+ fixed: false,
+ align: "center",
+ tableColumnHeight: "30",
+ tableTextType: "text",
+ tableBarcodeMode: "CODE128A",
+ tableQRCodeLevel: 0,
+ tableSummaryTitle: true,
+ tableSummary: "",
+ tableHeaderStyle: { fontSize: "10px" },
+ tableBodyStyle: { fontSize: "10px" }
+ },
+ {
+ width: 70,
+ title: "行政村",
+ field: "districtname",
+ checked: true,
+ columnId: "districtname",
+ fixed: false,
+ align: "center",
+ tableColumnHeight: "30",
+ tableTextType: "text",
+ tableBarcodeMode: "CODE128A",
+ tableQRCodeLevel: 0,
+ tableSummaryTitle: true,
+ tableSummary: "",
+ tableHeaderStyle: { fontSize: "10px" },
+ tableBodyStyle: { fontSize: "10px" }
+ },
+ {
+ width: 40,
+ title: "老年人",
+ field: "oldmanflag",
+ checked: true,
+ columnId: "oldmanflag",
+ fixed: false,
+ align: "center",
+ tableColumnHeight: "30",
+ tableTextType: "text",
+ tableBarcodeMode: "CODE128A",
+ tableQRCodeLevel: 0,
+ tableSummaryTitle: true,
+ tableSummary: "",
+ tableHeaderStyle: { fontSize: "10px" },
+ tableBodyStyle: { fontSize: "10px" }
+ },
+ {
+ width: 40,
+ title: "高血压",
+ field: "htnflag",
+ checked: true,
+ columnId: "htnflag",
+ fixed: false,
+ align: "center",
+ tableColumnHeight: "30",
+ tableTextType: "text",
+ tableBarcodeMode: "CODE128A",
+ tableQRCodeLevel: 0,
+ tableSummaryTitle: true,
+ tableSummary: "",
+ tableHeaderStyle: { fontSize: "10px" },
+ tableBodyStyle: { fontSize: "10px" }
+ },
+ {
+ width: 40,
+ title: "糖尿病",
+ field: "diaflag",
+ checked: true,
+ columnId: "diaflag",
+ fixed: false,
+ align: "center",
+ tableColumnHeight: "30",
+ tableTextType: "text",
+ tableBarcodeMode: "CODE128A",
+ tableQRCodeLevel: 0,
+ tableSummaryTitle: true,
+ tableSummary: "",
+ tableHeaderStyle: { fontSize: "10px" },
+ tableBodyStyle: { fontSize: "10px" }
+ },
+ {
+ width: 40,
+ title: "精神病",
+ field: "smiflag",
+ checked: true,
+ columnId: "smiflag",
+ fixed: false,
+ align: "center",
+ tableColumnHeight: "30",
+ tableTextType: "text",
+ tableBarcodeMode: "CODE128A",
+ tableQRCodeLevel: 0,
+ tableSummaryTitle: true,
+ tableSummary: "",
+ tableHeaderStyle: { fontSize: "10px" },
+ tableBodyStyle: { fontSize: "10px" }
+ },
+ {
+ width: 40,
+ title: "肺结核",
+ field: "pulflag",
+ checked: true,
+ columnId: "pulflag",
+ fixed: false,
+ align: "center",
+ tableColumnHeight: "30",
+ tableTextType: "text",
+ tableBarcodeMode: "CODE128A",
+ tableQRCodeLevel: 0,
+ tableSummaryTitle: true,
+ tableSummary: "",
+ tableHeaderStyle: { fontSize: "10px" },
+ tableBodyStyle: { fontSize: "10px" }
+ },
+ {
+ width: 40,
+ title: "总数",
+ field: "sum",
+ checked: true,
+ columnId: "sum",
+ fixed: false,
+ align: "center",
+ tableColumnHeight: "30",
+ tableTextType: "text",
+ tableBarcodeMode: "CODE128A",
+ tableQRCodeLevel: 0,
+ tableSummaryTitle: true,
+ tableSummary: "",
+ tableHeaderStyle: { fontSize: "10px" },
+ tableBodyStyle: { fontSize: "10px" }
+ }
+ ]
+ ]
+ },
+ printElementType: {
+ title: "表格",
+ type: "table",
+ editable: true,
+ columnDisplayEditable: true,
+ columnDisplayIndexEditable: true,
+ columnTitleEditable: true,
+ columnResizable: true,
+ columnAlignEditable: true,
+ isEnableEditField: true,
+ isEnableContextMenu: true,
+ isEnableInsertRow: true,
+ isEnableDeleteRow: true,
+ isEnableInsertColumn: true,
+ isEnableDeleteColumn: true,
+ isEnableMergeCell: true
+ }
+ },
+ {
+ options: {
+ left: 455,
+ top: 150,
+ height: 20,
+ width: 150,
+ title: "签字确认:",
+ fontSize: 12,
+ fontWeight: "600",
+ textAlign: "left",
+ showInPage: "last",
+ pageIndex: 0,
+ fixed: false
+ },
+ printElementType: {
+ title: "自定义文本",
+ type: "text"
+ }
+ }
+ ]
+ }
+ ]
+};
\ No newline at end of file