调整打印

This commit is contained in:
kmd 2025-10-13 16:06:29 +08:00
parent 0f97c99a52
commit 84a727e98c
3 changed files with 41 additions and 71 deletions

View File

@ -1,4 +1,5 @@
<template>
<div id="workloadPrintElementOptionSetting" style="display: none"></div>
<ContentWrap>
<el-row>
<el-form-item label="统计时间">
@ -26,14 +27,14 @@
<el-button type="primary" @click="printData" style="margin-left: 20px">
<Icon icon="ep:printer" class="mr-5px" /> 打印
</el-button>
<el-button
<!-- <el-button
type="primary"
@click="exportExcel"
style="margin-left: 20px"
:loading="exportLoading"
>
<Icon icon="ep:download" class="mr-5px" /> 导出excel
</el-button>
</el-button> -->
</el-form-item>
</el-row>
</ContentWrap>
@ -247,6 +248,12 @@ const exportExcel = async () => {
*/
const printData = () => {
try {
//
if (!data1.value || data1.value.length === 0) {
message.warning('暂无数据可打印,请先查询数据')
return
}
//
const hiprintTemplate = newHiprintPrintTemplate('workload', {
template: workload,
@ -277,7 +284,6 @@ const printData = () => {
//
const ext = {
callback: () => {
console.log('打印窗口已打开')
//
setTimeout(() => {
const table = document.querySelector('.hiprint-printPanel table')
@ -332,8 +338,6 @@ const printData = () => {
//
hiprintTemplate.print(printData, options, ext)
console.log('打印成功')
} catch (error) {
console.error('打印失败:', error)
}

View File

@ -54,8 +54,8 @@ export function preparePrintData(data, timeRange) {
}
try {
// 将树形结构展平为表格结构
const flattenedData = [];
// 处理平铺的数据结构
const processedData = [];
// 用于计算合计的变量
let totalOldmanflag = 0;
@ -65,48 +65,32 @@ export function preparePrintData(data, timeRange) {
let totalPulflag = 0;
let totalSum = 0;
// 处理每个卫生院及其下属的行政村
data.forEach(org => {
if (!org || typeof org !== 'object') return; // 跳过无效数据
// 直接处理平铺的数据
data.forEach(item => {
if (!item || typeof item !== 'object') return; // 跳过无效数据
// 确保orgname存在
const orgname = org.orgname || '未知卫生院';
// 累加各项数据
totalOldmanflag += item.oldmanflag || 0;
totalHtnflag += item.htnflag || 0;
totalDiaflag += item.diaflag || 0;
totalSmiflag += item.smiflag || 0;
totalPulflag += item.pulflag || 0;
totalSum += item.sum || 0;
// 添加该卫生院下的所有行政村
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) => {
// 累加各项数据
totalOldmanflag += village.oldmanflag || 0;
totalHtnflag += village.htnflag || 0;
totalDiaflag += village.diaflag || 0;
totalSmiflag += village.smiflag || 0;
totalPulflag += village.pulflag || 0;
totalSum += village.sum || 0;
flattenedData.push({
orgname: index === 0 ? 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
});
});
}
processedData.push({
orgname: item.orgname || '未知',
oldmanflag: item.oldmanflag || 0,
htnflag: item.htnflag || 0,
diaflag: item.diaflag || 0,
smiflag: item.smiflag || 0,
pulflag: item.pulflag || 0,
sum: item.sum || 0
});
});
// 添加合计行
flattenedData.push({
processedData.push({
orgname: '合计',
districtname: '',
oldmanflag: totalOldmanflag,
htnflag: totalHtnflag,
diaflag: totalDiaflag,
@ -115,10 +99,9 @@ export function preparePrintData(data, timeRange) {
sum: totalSum,
isTotal: true
});
return {
table: flattenedData,
table: processedData,
dateRange: timeRange ? `${timeRange[0]}${timeRange[1]}` : '',
printDate: formatDate(new Date(), 'YYYY-MM-DD'),
printUser: '管理员',
@ -151,4 +134,4 @@ function formatDate(date, format) {
.replace('YYYY', year)
.replace('MM', month)
.replace('DD', day);
}
}

View File

@ -84,7 +84,7 @@ export default {
columns: [
[
{
width: 70,
width: 140,
title: "<b>卫生院</b>",
field: "orgname",
checked: true,
@ -101,24 +101,7 @@ export default {
tableBodyStyle: { fontSize: "10px" }
},
{
width: 70,
title: "<b>行政村</b>",
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,
width: 50,
title: "<b>老年人</b>",
field: "oldmanflag",
checked: true,
@ -135,7 +118,7 @@ export default {
tableBodyStyle: { fontSize: "10px" }
},
{
width: 40,
width: 50,
title: "<b>高血压</b>",
field: "htnflag",
checked: true,
@ -152,7 +135,7 @@ export default {
tableBodyStyle: { fontSize: "10px" }
},
{
width: 40,
width: 50,
title: "<b>糖尿病</b>",
field: "diaflag",
checked: true,
@ -169,7 +152,7 @@ export default {
tableBodyStyle: { fontSize: "10px" }
},
{
width: 40,
width: 50,
title: "<b>精神病</b>",
field: "smiflag",
checked: true,
@ -186,7 +169,7 @@ export default {
tableBodyStyle: { fontSize: "10px" }
},
{
width: 40,
width: 50,
title: "<b>肺结核</b>",
field: "pulflag",
checked: true,
@ -203,7 +186,7 @@ export default {
tableBodyStyle: { fontSize: "10px" }
},
{
width: 40,
width: 55,
title: "<b>总人数</b>",
field: "sum",
checked: true,