打印条形码功能
This commit is contained in:
parent
2aa41fec67
commit
a3426eaaa0
@ -145,5 +145,9 @@ export const PatientApi = {
|
|||||||
//更新体检日期
|
//更新体检日期
|
||||||
updateMedicalDateTime: async (medicalSn: string, medicalDateTime: Date) => {
|
updateMedicalDateTime: async (medicalSn: string, medicalDateTime: Date) => {
|
||||||
return await request.put({ url: `/inspect/patient/updateMedicalDateTime?medicalSn=${medicalSn}&medicalDateTime=${medicalDateTime.toISOString()}` })
|
return await request.put({ url: `/inspect/patient/updateMedicalDateTime?medicalSn=${medicalSn}&medicalDateTime=${medicalDateTime.toISOString()}` })
|
||||||
|
},
|
||||||
|
//获取体检报告
|
||||||
|
GetbarcodeInfo: async (medicalSn: string) => {
|
||||||
|
return await request.get({ url: `/inspect/patient/GetbarcodeInfo?medicalSn=` + medicalSn })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="PrintElementOptionSetting" style="display:none;"></div>
|
<div id="PrintElementOptionSetting" style="display:none;"></div>
|
||||||
|
<div id="BarcodePrintElementOptionSetting" style="display:none;"></div>
|
||||||
|
|
||||||
<!-- 添加全屏加载遮罩 -->
|
<!-- 添加全屏加载遮罩 -->
|
||||||
<div
|
<div
|
||||||
@ -106,7 +107,7 @@ v-loading.fullscreen.lock="fullscreenLoading"
|
|||||||
<el-table-column label="联系电话" align="center" prop="phoneNum" />
|
<el-table-column label="联系电话" align="center" prop="phoneNum" />
|
||||||
<el-table-column label="住址" align="center" prop="domicileaddress" />
|
<el-table-column label="住址" align="center" prop="domicileaddress" />
|
||||||
<el-table-column label="状态" align="center" prop="isprint" :formatter="statusFormatter" />
|
<el-table-column label="状态" align="center" prop="isprint" :formatter="statusFormatter" />
|
||||||
<el-table-column label="操作" align="center" fixed="right" width="120px">
|
<el-table-column label="操作" align="center" fixed="right" width="240px">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button
|
<el-button
|
||||||
link
|
link
|
||||||
@ -115,6 +116,13 @@ v-loading.fullscreen.lock="fullscreenLoading"
|
|||||||
>
|
>
|
||||||
打印导检单
|
打印导检单
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
@click="handlePrintBarcode(scope.row)"
|
||||||
|
>
|
||||||
|
打印条形码
|
||||||
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@ -150,6 +158,7 @@ v-loading.fullscreen.lock="fullscreenLoading"
|
|||||||
<div style="display: flex; align-items: center;">
|
<div style="display: flex; align-items: center;">
|
||||||
<el-input v-model="addForm.cardId" placeholder="请输入身份证号" @blur="handleCardIdBlur" style="width: 75%;" />
|
<el-input v-model="addForm.cardId" placeholder="请输入身份证号" @blur="handleCardIdBlur" style="width: 75%;" />
|
||||||
<el-button type="primary" @click="handleGwPatientInfo" style="margin-left: 10px;">获取公卫患者信息</el-button>
|
<el-button type="primary" @click="handleGwPatientInfo" style="margin-left: 10px;">获取公卫患者信息</el-button>
|
||||||
|
<el-button type="primary" @click="handleReadIdCard" style="margin-left: 10px;">读取身份证</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="出生日期" prop="birthDate">
|
<el-form-item label="出生日期" prop="birthDate">
|
||||||
@ -185,7 +194,9 @@ import { PatientApi, type PatientVO } from '@/api/inspect/inspectpatient'
|
|||||||
import * as SummaryApi from "@/api/summary";
|
import * as SummaryApi from "@/api/summary";
|
||||||
import { newHiprintPrintTemplate } from "@/views/summary/utils/template-helper";
|
import { newHiprintPrintTemplate } from "@/views/summary/utils/template-helper";
|
||||||
import template from "@/views/summary/print/template";
|
import template from "@/views/summary/print/template";
|
||||||
|
import barcode from "@/views/summary/print/barcode";
|
||||||
import IDCardReader from '@/components/IDCardReader.vue';
|
import IDCardReader from '@/components/IDCardReader.vue';
|
||||||
|
import sdk from '@/components/IDCardReader/sdk';
|
||||||
defineOptions({ name: 'Department' })
|
defineOptions({ name: 'Department' })
|
||||||
|
|
||||||
const message = useMessage() // 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
@ -207,6 +218,7 @@ const queryParams = reactive({
|
|||||||
})
|
})
|
||||||
const queryFormRef = ref() // 搜索的表单
|
const queryFormRef = ref() // 搜索的表单
|
||||||
const fileInputRef = ref<HTMLInputElement | null>(null) // 文件输入引用
|
const fileInputRef = ref<HTMLInputElement | null>(null) // 文件输入引用
|
||||||
|
const idCardReading = ref(false) // 身份证读取状态
|
||||||
|
|
||||||
// 新增对话框相关变量
|
// 新增对话框相关变量
|
||||||
const dialogVisible = ref(false)
|
const dialogVisible = ref(false)
|
||||||
@ -295,25 +307,19 @@ const handlePrint = async (row: PatientVO) => {
|
|||||||
/** 打印导检单 */
|
/** 打印导检单 */
|
||||||
const createPrint = async (medicalSn) => {
|
const createPrint = async (medicalSn) => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// 使用SummaryApi打印导检单
|
// 使用SummaryApi打印导检单
|
||||||
const dataPrint = await SummaryApi.printInfoOfMedicalSn(medicalSn);
|
const dataPrint = await SummaryApi.printInfoOfMedicalSn(medicalSn);
|
||||||
console.log('获取到的打印数据:', dataPrint);
|
|
||||||
|
|
||||||
// 创建打印模板 - 修改这里,使用固定的模板名称而不是动态获取
|
// 创建打印模板 - 修改这里,使用固定的模板名称而不是动态获取
|
||||||
const hiprintTemplate = newHiprintPrintTemplate("InspectionChecklist", {
|
const hiprintTemplate = newHiprintPrintTemplate("InspectionChecklist", {
|
||||||
template: template,
|
template: template,
|
||||||
settingContainer: "#PrintElementOptionSetting",
|
settingContainer: "#PrintElementOptionSetting",
|
||||||
});
|
});
|
||||||
console.log('打印模板创建成功');
|
|
||||||
|
|
||||||
// 打印设置
|
// 打印设置
|
||||||
const options = {leftOffset: -1, topOffset: -1};
|
const options = {leftOffset: -1, topOffset: -1};
|
||||||
|
|
||||||
// 扩展配置
|
// 扩展配置
|
||||||
const ext = {
|
const ext = {
|
||||||
callback: () => {
|
callback: () => {
|
||||||
console.log("浏览器打印窗口已打开");
|
|
||||||
},
|
},
|
||||||
styleHandler: () => {
|
styleHandler: () => {
|
||||||
return "<style>.hiprint-printElement-text{color:black !important;}</style>";
|
return "<style>.hiprint-printElement-text{color:black !important;}</style>";
|
||||||
@ -322,11 +328,96 @@ const createPrint = async (medicalSn) => {
|
|||||||
|
|
||||||
// 调用浏览器打印
|
// 调用浏览器打印
|
||||||
hiprintTemplate.print(dataPrint, options, ext);
|
hiprintTemplate.print(dataPrint, options, ext);
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error('打印导检单失败,详细错误:', error);
|
console.error('打印导检单失败,详细错误:', error);
|
||||||
message.error(`打印导检单失败: ${error.message || '未知错误'}`);
|
message.error(`打印导检单失败: ${error.message || '未知错误'}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/** 打印条形码 */
|
||||||
|
const handlePrintBarcode = async (row: PatientVO) => {
|
||||||
|
try {
|
||||||
|
// 获取条形码数据
|
||||||
|
const databarcodePrint = await PatientApi.GetbarcodeInfo(row.medicalSn)
|
||||||
|
// 基础打印数据 - 患者基本信息
|
||||||
|
const baseData = {
|
||||||
|
patientName: databarcodePrint.name || row.pname,
|
||||||
|
patientGender: databarcodePrint.gender || row.gender,
|
||||||
|
patientAge: databarcodePrint.age || '',
|
||||||
|
checkTypeId: '体检',
|
||||||
|
sampleTypeId: '',
|
||||||
|
sampleSource: '体检',
|
||||||
|
billingTime: databarcodePrint.examinationDate || new Date().toLocaleDateString(),
|
||||||
|
medicalSn: row.medicalSn
|
||||||
|
};
|
||||||
|
|
||||||
|
// 准备批量打印数据数组
|
||||||
|
const batchPrintData: any[] = [];
|
||||||
|
|
||||||
|
// 添加体检编号条码(第1页)
|
||||||
|
batchPrintData.push({
|
||||||
|
...baseData,
|
||||||
|
barCode: row.medicalSn,
|
||||||
|
billingItem: '体检编号',
|
||||||
|
checkTypeId: '体检',
|
||||||
|
count: '1/4' // 页码标记
|
||||||
|
});
|
||||||
|
|
||||||
|
// 添加项目条码
|
||||||
|
if (databarcodePrint.barcodes && databarcodePrint.barcodes.length > 0) {
|
||||||
|
databarcodePrint.barcodes.forEach((item, index) => {
|
||||||
|
// 处理项目名称
|
||||||
|
let itemName = item.name || '检查项目';
|
||||||
|
let checkType = itemName; // 默认检验类别与项目名称相同
|
||||||
|
|
||||||
|
// 特殊情况处理:如果是"生化"
|
||||||
|
if (itemName === '生化') {
|
||||||
|
itemName = '生化全项'; // 项目名称显示为"生化全项"
|
||||||
|
checkType = '生化'; // 但检验类别保持为"生化"
|
||||||
|
}
|
||||||
|
|
||||||
|
batchPrintData.push({
|
||||||
|
...baseData,
|
||||||
|
barCode: item.code,
|
||||||
|
billingItem: itemName,
|
||||||
|
checkTypeId: checkType,
|
||||||
|
count: `${index+2}/4` // 页码标记
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 创建打印模板
|
||||||
|
const hiprintTemplate = newHiprintPrintTemplate("Barcode", {
|
||||||
|
template: barcode,
|
||||||
|
settingContainer: "#BarcodePrintElementOptionSetting",
|
||||||
|
});
|
||||||
|
|
||||||
|
// 打印设置
|
||||||
|
const options = {
|
||||||
|
leftOffset: 0,
|
||||||
|
topOffset: 0,
|
||||||
|
printMode: 'popup'
|
||||||
|
};
|
||||||
|
|
||||||
|
// 增强样式
|
||||||
|
const ext = {
|
||||||
|
callback: () => {
|
||||||
|
},
|
||||||
|
styleHandler: () => {
|
||||||
|
return `<style>
|
||||||
|
.hiprint-printElement-text{color:black !important;}
|
||||||
|
.hiprint-printElement-barcode{display:block !important; visibility:visible !important;}
|
||||||
|
svg {display:block !important; width:100% !important;}
|
||||||
|
.hiprint-printElement{opacity:1 !important; visibility:visible !important;}
|
||||||
|
</style>`;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// 执行批量打印 - 直接传入数组数据
|
||||||
|
hiprintTemplate.print(batchPrintData, options, ext);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('打印条形码失败,详细错误:', error);
|
||||||
|
message.error(`打印条形码失败: ${error.message || '未知错误'}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
/** 状态格式化 */
|
/** 状态格式化 */
|
||||||
const statusFormatter = (row: any) => {
|
const statusFormatter = (row: any) => {
|
||||||
return row.isprint === 1 ? '已打印' : '未打印'
|
return row.isprint === 1 ? '已打印' : '未打印'
|
||||||
@ -419,7 +510,7 @@ const submitForm = async () => {
|
|||||||
}else{
|
}else{
|
||||||
message.error('患者已存在')
|
message.error('患者已存在')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error('添加失败:', error)
|
console.error('添加失败:', error)
|
||||||
message.error('添加失败: ' + (error.message || '未知错误'))
|
message.error('添加失败: ' + (error.message || '未知错误'))
|
||||||
}
|
}
|
||||||
@ -476,8 +567,8 @@ const handleCardIdBlur = () => {
|
|||||||
const day = birthDateStr.substring(6, 8)
|
const day = birthDateStr.substring(6, 8)
|
||||||
|
|
||||||
// 设置出生日期
|
// 设置出生日期
|
||||||
addForm.birthDate = new Date(`${year}-${month}-${day}`)
|
addForm.birthDate = `${year}-${month}-${day}`
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error('解析身份证信息出错:', error)
|
console.error('解析身份证信息出错:', error)
|
||||||
message.error('身份证号格式不正确,无法提取出生日期和性别')
|
message.error('身份证号格式不正确,无法提取出生日期和性别')
|
||||||
}
|
}
|
||||||
@ -507,13 +598,70 @@ const handleGwPatientInfo = async () => {
|
|||||||
} else {
|
} else {
|
||||||
message.warning('未找到该患者的公卫信息')
|
message.warning('未找到该患者的公卫信息')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
message.error('获取公卫患者信息失败: ' + (error.message || '未知错误'))
|
message.error('获取公卫患者信息失败: ' + (error.message || '未知错误'))
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理读取身份证
|
||||||
|
const handleReadIdCard = async () => {
|
||||||
|
if (idCardReading.value) {
|
||||||
|
message.warning('正在读取身份证,请稍候...')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
idCardReading.value = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 初始化SDK
|
||||||
|
sdk.init_sdk()
|
||||||
|
|
||||||
|
// 连接设备
|
||||||
|
await sdk.open_device()
|
||||||
|
message.success('读卡器连接成功')
|
||||||
|
|
||||||
|
// 读取身份证信息
|
||||||
|
const result = await sdk.read_card()
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
|
||||||
|
// 填充表单数据
|
||||||
|
addForm.cardId = result.idNumber || ''
|
||||||
|
addForm.name = result.name || ''
|
||||||
|
addForm.address = result.address || ''
|
||||||
|
|
||||||
|
// 设置性别
|
||||||
|
addForm.gender = result.gender || ''
|
||||||
|
|
||||||
|
// 设置出生日期
|
||||||
|
if (result.birthday) {
|
||||||
|
addForm.birthDate = result.birthday
|
||||||
|
} else {
|
||||||
|
// 如果没有生日信息,尝试从身份证号解析
|
||||||
|
handleCardIdBlur()
|
||||||
|
}
|
||||||
|
|
||||||
|
message.success('读取身份证成功')
|
||||||
|
} else {
|
||||||
|
throw new Error('读取身份证失败')
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('读卡失败:', error)
|
||||||
|
message.error(error instanceof Error ? error.message : '读取身份证失败')
|
||||||
|
} finally {
|
||||||
|
// 无论成功或失败,都断开连接
|
||||||
|
try {
|
||||||
|
await sdk.close_device()
|
||||||
|
} catch (e) {
|
||||||
|
console.error('断开连接失败:', e)
|
||||||
|
}
|
||||||
|
|
||||||
|
idCardReading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 处理日期变化
|
// 处理日期变化
|
||||||
const handleDateChange = (val: [string, string] | null) => {
|
const handleDateChange = (val: [string, string] | null) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export default {
|
export default {
|
||||||
"panels": [
|
panels: [
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
"paperType": "A7",
|
"paperType": "A7",
|
||||||
@ -9,7 +9,7 @@ export default {
|
|||||||
"paperFooter": 85.03937007874016,
|
"paperFooter": 85.03937007874016,
|
||||||
"printElements": [
|
"printElements": [
|
||||||
{
|
{
|
||||||
"tid": "defaultModule.text",
|
"printElementType": { "title": "文本", "type": "text" },
|
||||||
"options": {
|
"options": {
|
||||||
"left": 48,
|
"left": 48,
|
||||||
"top": 3,
|
"top": 3,
|
||||||
@ -21,7 +21,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tid": "defaultModule.vline",
|
"printElementType": { "title": "直线", "type": "vline" },
|
||||||
"options": {
|
"options": {
|
||||||
"left": 43.5,
|
"left": 43.5,
|
||||||
"top": 3,
|
"top": 3,
|
||||||
@ -32,7 +32,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tid": "defaultModule.vline",
|
"printElementType": { "title": "直线", "type": "vline" },
|
||||||
"options": {
|
"options": {
|
||||||
"left": 60,
|
"left": 60,
|
||||||
"top": 3,
|
"top": 3,
|
||||||
@ -42,7 +42,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tid": "defaultModule.vline",
|
"printElementType": { "title": "直线", "type": "vline" },
|
||||||
"options": {
|
"options": {
|
||||||
"left": 79.5,
|
"left": 79.5,
|
||||||
"top": 3,
|
"top": 3,
|
||||||
@ -51,7 +51,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tid": "defaultModule.text",
|
"printElementType": { "title": "文本", "type": "text" },
|
||||||
"options": {
|
"options": {
|
||||||
"left": 82.5,
|
"left": 82.5,
|
||||||
"top": 3,
|
"top": 3,
|
||||||
@ -63,7 +63,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tid": "defaultModule.text",
|
"printElementType": { "title": "文本", "type": "text" },
|
||||||
"options": {
|
"options": {
|
||||||
"left": 64.5,
|
"left": 64.5,
|
||||||
"top": 3,
|
"top": 3,
|
||||||
@ -75,7 +75,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tid": "defaultModule.text",
|
"printElementType": { "title": "文本", "type": "text" },
|
||||||
"options": {
|
"options": {
|
||||||
"left": 115.5,
|
"left": 115.5,
|
||||||
"top": 3,
|
"top": 3,
|
||||||
@ -86,7 +86,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tid": "defaultModule.text",
|
"printElementType": { "title": "文本", "type": "text" },
|
||||||
"options": {
|
"options": {
|
||||||
"left": 4.5,
|
"left": 4.5,
|
||||||
"top": 3,
|
"top": 3,
|
||||||
@ -99,20 +99,21 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tid": "defaultModule.text",
|
"printElementType": { "title": "条形码", "type": "text" },
|
||||||
"options": {
|
"options": {
|
||||||
"left": 16.5,
|
"left": 16.5,
|
||||||
"top": 15,
|
"top": 15,
|
||||||
"height": 34.5,
|
"height": 34.5,
|
||||||
"width": 115.5,
|
"width": 115.5,
|
||||||
"field": "barCode",
|
"field": "barCode",
|
||||||
|
"textContent": "${barCode}",
|
||||||
"testData": "202401270838",
|
"testData": "202401270838",
|
||||||
"textAlign": "center",
|
"textAlign": "center",
|
||||||
"textType": "barcode"
|
"textType": "barcode"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tid": "defaultModule.text",
|
"printElementType": { "title": "文本", "type": "text" },
|
||||||
"options": {
|
"options": {
|
||||||
"left": 6,
|
"left": 6,
|
||||||
"top": 16.5,
|
"top": 16.5,
|
||||||
@ -126,7 +127,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tid": "defaultModule.text",
|
"printElementType": { "title": "文本", "type": "text" },
|
||||||
"options": {
|
"options": {
|
||||||
"left": 9,
|
"left": 9,
|
||||||
"top": 57,
|
"top": 57,
|
||||||
@ -139,7 +140,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tid": "defaultModule.text",
|
"printElementType": { "title": "文本", "type": "text" },
|
||||||
"options": {
|
"options": {
|
||||||
"left": 9,
|
"left": 9,
|
||||||
"top": 67.5,
|
"top": 67.5,
|
||||||
|
Loading…
Reference in New Issue
Block a user