打印条形码功能

This commit is contained in:
Euni4U 2025-04-11 13:37:55 +08:00
parent 2aa41fec67
commit a3426eaaa0
3 changed files with 178 additions and 25 deletions

View File

@ -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 })
} }
} }

View File

@ -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) {

View File

@ -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,