From 749bfc89ddd41264ea6d6b8235b6bf4ea636f352 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8F=B6=E9=94=A6=E6=B6=9B?= <26050301730@qq.com>
Date: Fri, 31 Oct 2025 16:06:12 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=89=93=E5=8D=B0?=
=?UTF-8?q?=E5=8D=95=E6=8D=AE=E6=B2=A1=E6=9C=89=E5=93=8D=E5=BA=94=E7=9A=84?=
=?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=96=B0?=
=?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AF=8A=E6=96=AD=E8=AF=8A=E6=96=AD=E7=B1=BB?=
=?UTF-8?q?=E5=88=AB=E8=87=AA=E5=8A=A8=E8=8E=B7=E5=8F=9611=E7=9A=84?=
=?UTF-8?q?=E9=94=99=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../components/diagnosis/diagnosis.vue | 2 +-
.../purchaseDocument/index.vue | 202 ++++++++++++++++--
2 files changed, 186 insertions(+), 18 deletions(-)
diff --git a/openhis-ui-vue3/src/views/doctorstation/components/diagnosis/diagnosis.vue b/openhis-ui-vue3/src/views/doctorstation/components/diagnosis/diagnosis.vue
index 7d9c1246..9837bb94 100644
--- a/openhis-ui-vue3/src/views/doctorstation/components/diagnosis/diagnosis.vue
+++ b/openhis-ui-vue3/src/views/doctorstation/components/diagnosis/diagnosis.vue
@@ -439,7 +439,7 @@ function handleAddDiagnosis() {
showPopover: false,
name: undefined,
verificationStatusEnum: 4,
- medTypeCode: '11',
+ medTypeCode: '初诊诊断',
diagSrtNo: maxSortNo + 1,
iptDiseTypeCode: 2,
diagnosisDesc: '',
diff --git a/openhis-ui-vue3/src/views/medicationmanagement/purchaseDocument/index.vue b/openhis-ui-vue3/src/views/medicationmanagement/purchaseDocument/index.vue
index 76911480..55d98905 100644
--- a/openhis-ui-vue3/src/views/medicationmanagement/purchaseDocument/index.vue
+++ b/openhis-ui-vue3/src/views/medicationmanagement/purchaseDocument/index.vue
@@ -30,7 +30,8 @@
批量保存
- 打印单据
+ 预览单据
+ 打印单据
{
- return item.value == receiptHeaderForm.supplierId;
- })[0].label;
+// 预览单据函数 - 简化实现,避免复杂嵌套数据结构
+function handlePrintPreview() {
+ console.log('开始执行预览功能');
+
+ // 检查是否存在数据
+ if (!form.purchaseinventoryList || form.purchaseinventoryList.length === 0) {
+ ElMessage.warning('没有数据可预览');
+ return;
+ }
+
+ // 检查是否所有必填字段都已填写
+ const hasEmptyFields = form.purchaseinventoryList.some(row => {
+ return !row.name || !row.itemQuantity || !row.price || !row.totalPrice;
+ });
+
+ if (hasEmptyFields) {
+ ElMessage.warning('请确保所有药品信息完整后再预览');
+ return;
+ }
+
+ // 检查templateJson是否已正确导入
+ if (!templateJson) {
+ console.error('错误:templateJson未定义,请检查导入');
+ ElMessage.error('打印模板未加载,请刷新页面重试');
+ return;
+ }
+
+ // 安全获取供应商名称
+ let supplierName = '';
+ if (supplierListOptions.value && receiptHeaderForm.supplierId) {
+ const filteredSuppliers = supplierListOptions.value.filter((item) => {
+ return item.value == receiptHeaderForm.supplierId;
+ });
+ supplierName = filteredSuppliers.length > 0 ? filteredSuppliers[0].label : '';
+ }
+
+ // 计算总金额
const totalAmount = form.purchaseinventoryList.reduce((accumulator, currentRow) => {
return accumulator + (Number(currentRow.totalPrice) || 0);
}, 0);
- result.push({
- supplierName: supplierName,
+
+ // 重新构建包含药品清单的数据结构
+ const simpleData = {
+ supplierName: supplierName || '',
totalAmount: totalAmount.toFixed(2),
- ...receiptHeaderForm,
- purchaseinventoryList: form.purchaseinventoryList,
+ receiptNumber: receiptHeaderForm.receiptNumber || '',
+ receiptDate: receiptHeaderForm.receiptDate || '',
+ organizationName: receiptHeaderForm.organizationName || '',
+ // 重新添加药品清单数组,但确保格式安全
+ purchaseinventoryList: Array.isArray(form.purchaseinventoryList) ? form.purchaseinventoryList.map(item => ({
+ id: item.id || '',
+ name: item.name || '',
+ itemQuantity: item.itemQuantity || 0,
+ price: item.price || 0,
+ totalPrice: item.totalPrice || 0,
+ // 保留其他可能需要的字段
+ ...item
+ })) : []
+ };
+
+ console.log('简化后的预览数据:', simpleData);
+
+ try {
+ // 直接使用templateJson创建打印
+ // 避免复杂的模板创建和数据处理逻辑
+ setTimeout(() => {
+ try {
+ // 最简单的方式使用hiprint - 直接调用print2方法
+ // 只传递必要的数据,不传递复杂嵌套的数组
+ const printOptions = {
+ preview: true,
+ title: '药品采购入库清单',
+ printer: ''
+ };
+
+ // 方法1: 尝试直接使用templateJson
+ console.log('尝试直接使用templateJson');
+ if (typeof hiprint.template !== 'undefined' && typeof hiprint.template.print === 'function') {
+ hiprint.template.print(templateJson, simpleData, printOptions);
+ }
+ // 方法2: 尝试创建简单模板
+ else if (typeof hiprint.PrintTemplate === 'function') {
+ console.log('尝试使用PrintTemplate');
+ const template = new hiprint.PrintTemplate({template: templateJson});
+ template.print(simpleData, printOptions);
+ }
+ // 方法3: 最直接的方式
+ else {
+ console.log('尝试最直接的打印方式');
+ hiprint.print(templateJson, simpleData, printOptions);
+ }
+
+ ElMessage.success('正在生成单据预览,请等待...');
+ } catch (e) {
+ console.error('预览执行失败:', e);
+ ElMessage.error('预览功能执行失败,请稍后重试');
+ }
+ }, 50);
+ } catch (error) {
+ console.error('预览准备失败:', error);
+ ElMessage.error('预览失败,请检查配置');
+ }
+}
+
+// 打印单据函数 - 简化实现,与预览函数保持一致
+function handlePrint() {
+ // 检查是否存在数据
+ if (!form.purchaseinventoryList || form.purchaseinventoryList.length === 0) {
+ ElMessage.warning('没有数据可打印');
+ return;
+ }
+
+ // 检查是否所有必填字段都已填写
+ const hasEmptyFields = form.purchaseinventoryList.some(row => {
+ return !row.name || !row.itemQuantity || !row.price || !row.totalPrice;
});
- console.log(result, '345678987654');
- const printElements = templateJson;
- var hiprintTemplate = new hiprint.PrintTemplate({ template: printElements }); // 定义模板
- hiprintTemplate.print2(result, {
- printer: 'EPSON LQ-80KFII',
- title: '打印标题',
- }); //开始打印
+
+ if (hasEmptyFields) {
+ ElMessage.warning('请确保所有药品信息完整后再打印');
+ return;
+ }
+
+ // 安全获取供应商名称
+ let supplierName = '';
+ if (supplierListOptions.value && receiptHeaderForm.supplierId) {
+ const filteredSuppliers = supplierListOptions.value.filter((item) => {
+ return item.value == receiptHeaderForm.supplierId;
+ });
+ supplierName = filteredSuppliers.length > 0 ? filteredSuppliers[0].label : '';
+ }
+
+ // 计算总金额
+ const totalAmount = form.purchaseinventoryList.reduce((accumulator, currentRow) => {
+ return accumulator + (Number(currentRow.totalPrice) || 0);
+ }, 0);
+
+ // 重新构建包含药品清单的数据结构
+ const simpleData = {
+ supplierName: supplierName || '',
+ totalAmount: totalAmount.toFixed(2),
+ receiptNumber: receiptHeaderForm.receiptNumber || '',
+ receiptDate: receiptHeaderForm.receiptDate || '',
+ organizationName: receiptHeaderForm.organizationName || '',
+ // 重新添加药品清单数组,但确保格式安全
+ purchaseinventoryList: Array.isArray(form.purchaseinventoryList) ? form.purchaseinventoryList.map(item => ({
+ id: item.id || '',
+ name: item.name || '',
+ itemQuantity: item.itemQuantity || 0,
+ price: item.price || 0,
+ totalPrice: item.totalPrice || 0,
+ // 保留其他可能需要的字段
+ ...item
+ })) : []
+ };
+
+ try {
+ // 使用与预览函数相同的简化打印逻辑
+ setTimeout(() => {
+ try {
+ const printOptions = {
+ preview: false, // 直接打印模式
+ title: '药品采购入库清单',
+ printer: ''
+ };
+
+ // 尝试多种可能的API调用方式
+ if (typeof hiprint.template !== 'undefined' && typeof hiprint.template.print === 'function') {
+ hiprint.template.print(templateJson, simpleData, printOptions);
+ }
+ else if (typeof hiprint.PrintTemplate === 'function') {
+ const template = new hiprint.PrintTemplate({template: templateJson});
+ template.print(simpleData, printOptions);
+ }
+ else {
+ hiprint.print(templateJson, simpleData, printOptions);
+ }
+
+ ElMessage.success('打印请求已发送');
+ } catch (e) {
+ console.error('打印执行失败:', e);
+ ElMessage.error('打印执行失败,请稍后重试');
+ }
+ }, 50);
+ } catch (error) {
+ console.error('打印失败:', error);
+ ElMessage.error('打印失败,请检查配置');
+ }
}
function deleteSelectedRows() {