1594 lines
55 KiB
Vue
1594 lines
55 KiB
Vue
<template>
|
||
<div class="app-container">
|
||
<div class="left">
|
||
<div class="form">
|
||
<el-form
|
||
:model="queryParams"
|
||
ref="queryRef"
|
||
:inline="true"
|
||
v-show="showSearch"
|
||
label-position="right"
|
||
style="min-width: 500px"
|
||
>
|
||
<el-form-item label="患者信息" prop="condition">
|
||
<el-input
|
||
v-model="queryParams.condition"
|
||
placeholder="请输入姓名/证件号"
|
||
clearable
|
||
style="width: 160px"
|
||
@keyup.enter="handleQuery"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="发药状态" prop="departmentId" style="margin-left: 10px">
|
||
<el-select
|
||
v-model="queryParams.statusEnum"
|
||
placeholder="请选择发药状态"
|
||
clearable
|
||
style="width: 160px"
|
||
@change="handleQuery"
|
||
>
|
||
<el-option
|
||
v-for="item in dispenseStatusOptions"
|
||
:key="item.value"
|
||
:label="item.label"
|
||
:value="item.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="就诊日期">
|
||
<el-date-picker
|
||
v-model="dateRange"
|
||
type="daterange"
|
||
start-placeholder="开始日期"
|
||
end-placeholder="结束日期"
|
||
style="width: 250px"
|
||
value-format="YYYY-MM-DD"
|
||
@change="handleQuery"
|
||
/>
|
||
</el-form-item>
|
||
<!-- <el-form-item label="科室" prop="departmentId">
|
||
<el-select
|
||
v-model="queryParams.departmentId"
|
||
placeholder="请选择科室"
|
||
clearable
|
||
style="width: 160px"
|
||
@change="handleQuery"
|
||
>
|
||
<el-option
|
||
v-for="item in departmentList"
|
||
:key="item.value"
|
||
:label="item.label"
|
||
:value="item.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item> -->
|
||
<el-form-item style="margin-left: 15px">
|
||
<el-button type="primary" @click="handleQuery">搜索</el-button>
|
||
<el-button @click="resetQuery">重置</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
</div>
|
||
|
||
<el-table
|
||
:data="patientList"
|
||
border
|
||
style="width: 100%; height: 60vh"
|
||
highlight-current-row
|
||
@row-click="handleCurrentChange"
|
||
>
|
||
<el-table-column prop="patientName" label="姓名" width="130" align="center" />
|
||
<el-table-column prop="genderEnum_enumText" label="性别" width="80" align="center" />
|
||
<el-table-column prop="age" label="年龄" width="80" align="center" />
|
||
<el-table-column prop="receptionTime" label="就诊日期" align="center">
|
||
<template #default="scope">
|
||
{{ scope.row.receptionTime ? formatDate(scope.row.receptionTime) : '-' }}
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<pagination
|
||
v-show="total > 0"
|
||
:total="total"
|
||
v-model:page="queryParams.pageNo"
|
||
v-model:limit="queryParams.pageSize"
|
||
@pagination="getList"
|
||
/>
|
||
</div>
|
||
|
||
<div class="right">
|
||
<!-- <div class="select_wrapper_div">
|
||
<p style="margin-right: 60px; font-size: 19px">患者基本信息</p> -->
|
||
|
||
<!-- <el-button type="success" plain @click="print" icon="Printer" style="margin-left: 30px;">打印</el-button> -->
|
||
<!-- </div> -->
|
||
<div class="top">
|
||
<!-- <el-descriptions :column="4" title="患者基本信息">
|
||
<el-descriptions-item label="姓名:">{{ personInfo.patientName }}</el-descriptions-item>
|
||
<el-descriptions-item label="性别:">
|
||
{{ personInfo.genderEnum_enumText }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="年龄:">{{ personInfo.age }}</el-descriptions-item>
|
||
<el-descriptions-item label="合同类型:">
|
||
{{ personInfo.categoryEnum_enumText }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="就诊科室:">
|
||
{{ personInfo.organizationName }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="就诊日期:">
|
||
{{ personInfo.encounterDate }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="证件号:">{{ personInfo.idCard }}</el-descriptions-item>
|
||
<el-descriptions-item label="总金额:">
|
||
{{ personInfo.totalPrice ? personInfo.totalPrice.toFixed(2) : '0.00' }}元
|
||
</el-descriptions-item>
|
||
</el-descriptions> -->
|
||
<!-- <el-row>
|
||
<el-col :span="4">姓名:{{ personInfo.patientName }}</el-col>
|
||
<el-col :span="3">性别:{{ personInfo.genderEnum_enumText }}</el-col>
|
||
<el-col :span="3">年龄:{{ personInfo.age }}</el-col>
|
||
<el-col :span="5">合同类型:{{ personInfo.categoryEnum_enumText }}</el-col> </el-row
|
||
><br />
|
||
<el-row>
|
||
<el-col :span="5">就诊科室:{{ personInfo.organizationName }}</el-col>
|
||
<el-col :span="5">就诊日期:{{ personInfo.encounterDate }}</el-col>
|
||
<el-col :span="7">证件号:{{ personInfo.idCard }}</el-col>
|
||
|
||
</el-row
|
||
><br />
|
||
<el-row>
|
||
<el-col :span="4"
|
||
>总金额:{{
|
||
personInfo.totalPrice ? personInfo.totalPrice.toFixed(2) : '0.00'
|
||
}}元</el-col
|
||
>
|
||
</el-row> -->
|
||
<span style="color: #606266; font-size: 14px; font-weight: 700; margin-right: 15px">
|
||
调配药师
|
||
</span>
|
||
<el-select v-model="preparerDoctor" placeholder="调配药师" style="width: 160px">
|
||
<el-option
|
||
v-for="item in preparerDoctorOptions"
|
||
:key="item.value"
|
||
:label="item.label"
|
||
:value="item.value"
|
||
/>
|
||
</el-select>
|
||
<span style="color: #606266; font-size: 14px; font-weight: 700; margin-right: 15px">
|
||
药品分类
|
||
</span>
|
||
<el-select
|
||
v-model="tcmFlag"
|
||
placeholder="药品分类"
|
||
style="width: 160px"
|
||
@change="
|
||
() => {
|
||
if (currentRow.encounterId) {
|
||
getMedicineList(currentRow.encounterId);
|
||
}
|
||
}
|
||
"
|
||
>
|
||
<el-option
|
||
v-for="item in medCategoryCode"
|
||
:key="item.value"
|
||
:label="item.label"
|
||
:value="item.value"
|
||
/>
|
||
</el-select>
|
||
<span style="color: #606266; font-size: 14px; font-weight: 700; margin-right: 15px">
|
||
项目
|
||
</span>
|
||
<el-select
|
||
v-model="projectTypeCode"
|
||
placeholder="项目"
|
||
style="width: 160px"
|
||
@change="getMedicineList(currentRow.encounterId)"
|
||
>
|
||
<el-option label="全部" value="1" />
|
||
<el-option label="药品" value="2" />
|
||
<el-option label="耗材" value="3" />
|
||
</el-select>
|
||
<el-button
|
||
:disabled="medicineInfoList && medicineInfoList.length == 0"
|
||
type="primary"
|
||
@click="handleBatch()"
|
||
style="margin-left: 30px"
|
||
>
|
||
批量发药
|
||
</el-button>
|
||
<el-button type="primary" @click="handleScan()" style="margin-left: 30px"> 扫码 </el-button>
|
||
<el-button type="primary" @click="previewAndPrint()" style="margin-left: 30px">
|
||
处方打印
|
||
</el-button>
|
||
<div style="position: absolute; top: 30px; right: 25px">
|
||
总金额:{{ medicineTotalPrice ? medicineTotalPrice.toFixed(2) : '0.00' }}元
|
||
</div>
|
||
</div>
|
||
<el-table
|
||
:data="medicineInfoList"
|
||
border
|
||
style="width: 100%; height: 65vh; margin-top: 10px"
|
||
:row-style="rowStyle"
|
||
:span-method="spanMethod"
|
||
@select="handleSelectionChange"
|
||
ref="tableRef"
|
||
>
|
||
<el-table-column type="selection" width="55" align="center" fixed="left" />
|
||
<el-table-column prop="prescriptionNo" label="处方号" width="120" align="center" />
|
||
<el-table-column prop="itemName" label="项目名称" width="160" align="center" />
|
||
<el-table-column prop="statusEnum_enumText" label="发药状态" width="100" align="center">
|
||
<template #default="scope">
|
||
<el-tag :type="tagType(scope.row.statusEnum)">
|
||
{{ scope.row.statusEnum_enumText }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="quantity" label="发药数量" width="100" align="center">
|
||
<template #default="scope">
|
||
{{ scope.row.quantity }}{{ scope.row.unitCode_dictText }}
|
||
</template>
|
||
</el-table-column>
|
||
<!-- <el-table-column prop="flag" label="组合" width="60" align="center" /> -->
|
||
<!-- <el-table-column prop="quantity" label="发药数量" width="100" align="center" /> -->
|
||
<el-table-column prop="totalVolume" label="规格" width="100" align="center" />
|
||
<!-- <el-table-column prop="unitCode_dictText" label="单位" width="100" align="center" /> -->
|
||
<!-- <el-table-column
|
||
prop="doseUnitCode_dictText"
|
||
label="单次剂量"
|
||
width="80"
|
||
align="center"
|
||
v-if="tcmFlag == '0'"
|
||
>
|
||
<template #default="scope">
|
||
{{ scope.row.dose }}{{ scope.row.doseUnitCode_dictText }}
|
||
</template>
|
||
</el-table-column> -->
|
||
<el-table-column
|
||
prop="traceNo"
|
||
label="追溯码"
|
||
width="180"
|
||
align="center"
|
||
v-if="tcmFlag == '0'"
|
||
>
|
||
<template #default="scope">
|
||
<el-tooltip
|
||
:content="formatContent(scope.row.traceNo)"
|
||
placement="top"
|
||
popper-class="custom-tooltip"
|
||
>
|
||
<el-input
|
||
:ref="'traceNoRef' + scope.$index"
|
||
@input="handleTraceNoInput(scope.row, scope.$index)"
|
||
v-model="scope.row.traceNo"
|
||
placeholder="请输入追溯码"
|
||
/>
|
||
</el-tooltip>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="lotNumber" label="批次号" width="120" align="center" />
|
||
<el-table-column
|
||
prop="totalPrice"
|
||
label="金额"
|
||
width="100"
|
||
:formatter="formatPrice"
|
||
align="right"
|
||
header-align="center"
|
||
/>
|
||
<el-table-column prop="locationName" label="发药药房" width="90" align="center" />
|
||
<el-table-column prop="manufacturerText" label="生产厂家" width="200" align="center" />
|
||
<el-table-column prop="doctorName" label="开单医生" width="100" align="center" />
|
||
<el-table-column prop="conditionName" label="诊断" width="120" align="center" />
|
||
<!-- <el-table-column prop="dose" label="剂量" width="100" align="center" /> -->
|
||
<el-table-column prop="rateCode" label="频次" width="100" align="center" />
|
||
<el-table-column prop="methodCode_dictText" label="用法" width="100" align="center" />
|
||
<el-table-column prop="dispensePerDuration" label="天数" width="80" align="center" />
|
||
<el-table-column
|
||
label="操作"
|
||
align="center"
|
||
width="160"
|
||
fixed="right"
|
||
class-name="small-padding fixed-width"
|
||
>
|
||
<template #default="scope">
|
||
<el-button
|
||
link
|
||
type="primary"
|
||
:disabled="scope.row.statusEnum != 2"
|
||
icon="SuccessFilled"
|
||
@click="handleBatch(scope.row)"
|
||
>
|
||
发药
|
||
</el-button>
|
||
<el-button
|
||
link
|
||
type="primary"
|
||
:disabled="scope.row.statusEnum != 2"
|
||
@click="backMedicine(scope.row)"
|
||
icon="CircleClose"
|
||
>
|
||
作废
|
||
</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
<!-- <el-table-column prop="performOrg_dictText" label="是否拆零" width="120">
|
||
<template #default="scope">
|
||
<el-select v-model="scope.row.performOrg_dictText" placeholder="请选择"
|
||
@change="handleSelectChange(scope.row)">
|
||
<el-option v-for="option in options" :key="option.value" :label="option.label"
|
||
:value="option.value"></el-option>
|
||
</el-select>
|
||
</template>
|
||
</el-table-column> -->
|
||
<!-- <el-table-column prop="medicationStatusEnum_enumText" label="追溯码" width="100" /> -->
|
||
<!-- <el-table-column
|
||
prop="unitPrice"
|
||
label="单价"
|
||
width="100"
|
||
:formatter="formatPrice"
|
||
align="right"
|
||
header-align="center"
|
||
/> -->
|
||
</el-table>
|
||
</div>
|
||
<el-dialog title="选择作废原因" v-model="showDialog" width="30%">
|
||
<!-- 下拉选择框 -->
|
||
<el-select v-model="notPerformedReasonEnum" placeholder="请选择作废原因">
|
||
<el-option
|
||
v-for="item in backReason"
|
||
:key="item.value"
|
||
:label="item.label"
|
||
:value="item.value"
|
||
/>
|
||
</el-select>
|
||
|
||
<!-- 弹窗底部按钮 -->
|
||
<template #footer>
|
||
<span class="dialog-footer">
|
||
<el-button type="primary" @click="handleConfirm">确 定</el-button>
|
||
<el-button @click="handleCancel">取 消</el-button>
|
||
</span>
|
||
</template>
|
||
</el-dialog>
|
||
<TraceNoDialog
|
||
:ypName="ypName"
|
||
:openDialog="openTraceNoDialog"
|
||
@submit="submit"
|
||
@cancel="openTraceNoDialog = false"
|
||
/>
|
||
</div>
|
||
|
||
<el-dialog title="选择打印机" v-model="showPrinterDialog" width="400px" append-to-body>
|
||
<el-form>
|
||
<el-form-item label="请选择打印机:">
|
||
<el-select v-model="selectedPrinter" placeholder="请选择打印机" style="width: 100%">
|
||
<el-option
|
||
v-for="printer in printerList"
|
||
:key="printer.name"
|
||
:label="printer.name"
|
||
:value="printer.name"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-form>
|
||
|
||
<template #footer>
|
||
<span class="dialog-footer">
|
||
<el-button @click="cancelPrinter">取 消</el-button>
|
||
<el-button type="primary" @click="confirmPrinter">确 定</el-button>
|
||
</span>
|
||
</template>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<script setup name="westernmedicine">
|
||
import { ref, computed, onMounted, onBeforeMount } from 'vue';
|
||
import { ElMessage } from 'element-plus';
|
||
import {
|
||
listWesternmedicine,
|
||
listPatient,
|
||
updateMedicion,
|
||
listInit,
|
||
backMedicion,
|
||
prepareMedicion,
|
||
itemTraceNo,
|
||
getReportRegisterInit,
|
||
deviceDispense,
|
||
deviceInvalid,
|
||
} from './components/api';
|
||
import { advicePrint } from '@/api/public';
|
||
import { formatDate, formatDateStr } from '@/utils/index';
|
||
import { debounce } from 'lodash-es';
|
||
import TraceNoDialog from '@/components/OpenHis/TraceNoDialog/index.vue';
|
||
// 使用window.hiprint,不再从vue-plugin-hiprint导入
|
||
import templateJson from './components/templateJson.json';
|
||
// import disposalTemplate from './components/disposalTemplate.json';
|
||
import {
|
||
getPrinterList,
|
||
getCachedPrinter,
|
||
savePrinterToCache,
|
||
selectPrinterAndPrint,
|
||
executePrint,
|
||
} from '@/utils/his';
|
||
|
||
const showSearch = ref(true);
|
||
const total = ref(0);
|
||
const markers = ref([]);
|
||
const patientList = ref([]);
|
||
const medicineInfoList = ref([]);
|
||
const departmentList = ref([]);
|
||
const dateRange = ref([]);
|
||
const personInfo = ref([]);
|
||
const dispenseStatusOptions = ref([]);
|
||
const preparerDoctorOptions = ref([]);
|
||
const diagnoses = ref('');
|
||
const preparerDoctor = ref();
|
||
const backReason = ref([]);
|
||
const selectedPrescriptionNo = ref('');
|
||
const showDialog = ref(false);
|
||
const notPerformedReasonEnum = ref();
|
||
const currentRow = ref(null);
|
||
const tableRef = ref(null);
|
||
const selectedGroupIds = ref(new Set());
|
||
const selectedItems = ref(new Set());
|
||
const traceNoList = ref([]);
|
||
const traceNo = ref('');
|
||
const traceNoTemp = ref('');
|
||
const tcmFlag = ref('0');
|
||
const openTraceNo = ref(false);
|
||
const isManualSelection = ref(false);
|
||
const groups = ref({});
|
||
const openTraceNoDialog = ref(false);
|
||
const ypName = ref('');
|
||
const medicineTotalPrice = ref(0);
|
||
const projectTypeCode = ref('2');
|
||
const selectedRow = ref(null);
|
||
|
||
const { proxy } = getCurrentInstance();
|
||
const medCategoryCode = ref([
|
||
{
|
||
label: '西药中成药',
|
||
value: '0',
|
||
},
|
||
{
|
||
label: '中药',
|
||
value: '1',
|
||
},
|
||
]);
|
||
|
||
const data = reactive({
|
||
form: {},
|
||
queryParams: {
|
||
pageNo: 1,
|
||
pageSize: 10,
|
||
condition: null,
|
||
departmentId: null,
|
||
statusEnum: 3,
|
||
classEnum: 2,
|
||
},
|
||
});
|
||
const { queryParams } = toRefs(data);
|
||
|
||
// 在组件挂载后调用 getList
|
||
onMounted(() => {
|
||
setDefaultDateRange();
|
||
getList();
|
||
});
|
||
function handleScan() {
|
||
openTraceNoDialog.value = true;
|
||
}
|
||
function submit(value) {
|
||
let list = [];
|
||
if (value) {
|
||
list = value.split(',');
|
||
}
|
||
itemTraceNo(list).then((res) => {
|
||
if (res.code === 200) {
|
||
if (!res.data) {
|
||
proxy.$modal.msgWarning('未在库存中匹配到追溯码,请在发药列表中单独扫描');
|
||
openTraceNoDialog.value = false;
|
||
proxy.$refs['traceNoRef0'].focus();
|
||
return;
|
||
}
|
||
medicineInfoList.value.forEach((item, index) => {
|
||
if (res.data[item.medicineId] && res.data[item.medicineId].split(',') > item.quantity) {
|
||
proxy.$modal.msgWarning('操作失败');
|
||
return;
|
||
}
|
||
medicineInfoList.value[index].traceNo = res.data[item.medicineId];
|
||
});
|
||
openTraceNoDialog.value = false;
|
||
}
|
||
});
|
||
}
|
||
// 设置默认日期范围为当天
|
||
function setDefaultDateRange() {
|
||
const today = new Date();
|
||
const year = today.getFullYear();
|
||
const month = String(today.getMonth() + 1).padStart(2, '0');
|
||
const day = String(today.getDate()).padStart(2, '0');
|
||
const formattedDate = `${year}-${month}-${day}`;
|
||
dateRange.value = [formattedDate, formattedDate];
|
||
console.log('222', dateRange.value);
|
||
}
|
||
|
||
function getList() {
|
||
console.log('224555552', dateRange.value);
|
||
queryParams.value.receptionTimeSTime = dateRange.value[0] + ' 00:00:00';
|
||
queryParams.value.receptionTimeETime = dateRange.value[1] + ' 23:59:59';
|
||
|
||
console.log('222', queryParams.value);
|
||
listPatient(queryParams.value).then((response) => {
|
||
console.log('Full response1:', response);
|
||
patientList.value = response.data.records;
|
||
total.value = response.data.total;
|
||
});
|
||
listInit().then((response) => {
|
||
console.log('Full response2:', response);
|
||
departmentList.value = [{ value: null, label: '全部' }, ...response.data.departmentOptions];
|
||
backReason.value = response.data.notPerformedReasonOptions;
|
||
dispenseStatusOptions.value = response.data.dispenseStatusOptions;
|
||
preparerDoctorOptions.value = response.data.preparerDoctorOptions;
|
||
preparerDoctor.value = preparerDoctorOptions.value[0].value;
|
||
});
|
||
}
|
||
//打印中西药处方
|
||
// async function printPrescription() {
|
||
// const selectedRows = tableRef.value.getSelectionRows();
|
||
// if (selectedRows.length === 0) {
|
||
// proxy.$modal.msgWarning('未选择要打印的项目,请重新选择,打印失败');
|
||
// return;
|
||
// }
|
||
// let requestIds = selectedRows.map((item) => item.requestId).join(',');
|
||
// const result = [];
|
||
// advicePrint({ requestIds: requestIds, isPrescription: '1' }).then((res) => {
|
||
// const groupedRows = {};
|
||
// res.data.adviceItemList.forEach((row) => {
|
||
// const prescriptionNo = row.prescriptionNo;
|
||
// if (!groupedRows[prescriptionNo]) {
|
||
// groupedRows[prescriptionNo] = [];
|
||
// }
|
||
// row.contractName = res.data.contractName;
|
||
// groupedRows[prescriptionNo].push(row);
|
||
// });
|
||
|
||
// console.log('按处方号分组的结果:', groupedRows);
|
||
|
||
// // 如果您需要将分组后的数据转换为数组形式
|
||
// const groupedArray = Object.values(groupedRows);
|
||
// console.log('分组后的数组形式:', groupedArray);
|
||
|
||
// groupedArray.forEach((item, index) => {
|
||
// const total = item.reduce((sum, item) => {
|
||
// return sum + (item.totalPrice || 0);
|
||
// }, 0);
|
||
// result.push({
|
||
// ...res.data,
|
||
// medTotalAmount: total,
|
||
// prescriptionList: item,
|
||
// });
|
||
// });
|
||
// console.log(result, 'result');
|
||
// const printElements = templateJson;
|
||
// var hiprintTemplate = new hiprint.PrintTemplate({ template: printElements }); // 定义模板
|
||
// hiprintTemplate.print2(result, {
|
||
// title: '打印标题',
|
||
// height: 210,
|
||
// width: 148,
|
||
// }); //开始打印
|
||
// // 直接打印回调
|
||
// // 发送任务到打印机成功
|
||
// hiprintTemplate.on('printSuccess', function (e) {
|
||
// console.log('打印成功');
|
||
// });
|
||
// // 发送任务到打印机失败
|
||
// hiprintTemplate.on('printError', function (e) {
|
||
// console.log('打印失败');
|
||
// });
|
||
// });
|
||
// // 计算总价
|
||
// // const result = {
|
||
// // data: selectedRows.map((item) => ({
|
||
// // ...item,
|
||
// // patientName: personInfo.value.patientName,
|
||
// // genderEnum_enumText: personInfo.value.genderEnum_enumText,
|
||
// // age: personInfo.value.age,
|
||
// // phone: personInfo.value.phone,
|
||
// // hospitalName: personInfo.value.hospitalName,
|
||
// // patientBusNo: personInfo.value.patientBusNo,
|
||
// // quantity: item.quantity,
|
||
// // unitCode_dictText: item.unitCode_dictText,
|
||
// // organizationName: personInfo.value.organizationName,
|
||
// // })),
|
||
// // };
|
||
// // 按 prescriptionNo 分组
|
||
// // const groupedRows = {};
|
||
// // selectedRows.forEach(row => {
|
||
// // const prescriptionNo = row.prescriptionNo;
|
||
// // if (!groupedRows[prescriptionNo]) {
|
||
// // groupedRows[prescriptionNo] = [];
|
||
// // }
|
||
// // row.contractName = personInfo.value.contractName;
|
||
// // groupedRows[prescriptionNo].push(row);
|
||
// // });
|
||
|
||
// // console.log('按处方号分组的结果:', groupedRows);
|
||
|
||
// // // 如果您需要将分组后的数据转换为数组形式
|
||
// // const groupedArray = Object.values(groupedRows);
|
||
// // console.log('分组后的数组形式:', groupedArray);
|
||
|
||
// // const result = [];
|
||
// // groupedArray.forEach((item, index) => {
|
||
// // const total = item.reduce((sum, item) => {
|
||
// // return sum + (item.totalPrice || 0);
|
||
// // }, 0);
|
||
// // result.push({
|
||
// // ...personInfo.value,
|
||
// // medTotalAmount: total,
|
||
// // doctor: item[0].doctorName,
|
||
// // prescriptionNo: item[0].prescriptionNo,
|
||
// // reqAuthoredTime: item[0].reqAuthoredTime,
|
||
// // prescriptionList: item,
|
||
// // })
|
||
// // })
|
||
|
||
// // 将对象转换为 JSON 字符串
|
||
// // let jsonString = JSON.stringify(result, null, 2);
|
||
|
||
// // 模板对象获取
|
||
|
||
// // await CefSharp.BindObjectAsync('boundAsync');
|
||
// // await boundAsync
|
||
// // .printReport('西药(中成药)处方笺.grf', jsonString)
|
||
// // .then((response) => {
|
||
// // //返回结果是jsonString,可判断其调用是否成功
|
||
// // console.log(response, 'response');
|
||
// // var res = JSON.parse(response);
|
||
// // if (!res.IsSuccess) {
|
||
// // proxy.$modal.msgError('调用打印插件失败:' + res.ErrorMessage);
|
||
// // }
|
||
// // })
|
||
// // .catch((error) => {
|
||
// // proxy.$modal.msgError('调用打印插件失败:' + error);
|
||
// // });
|
||
// }
|
||
// 新增打印机相关变量
|
||
const printerList = ref([]); // 打印机列表
|
||
const selectedPrinter = ref(''); // 选中的打印机
|
||
const showPrinterDialog = ref(false); // 显示打印机选择对话框
|
||
const previewData = ref(null); // 预览数据
|
||
|
||
// 抽取获取打印数据的公共函数
|
||
async function getPrintData() {
|
||
const selectedRows = tableRef.value.getSelectionRows();
|
||
if (selectedRows.length === 0) {
|
||
proxy.$modal.msgWarning('未选择要打印的项目,请重新选择');
|
||
return null;
|
||
}
|
||
|
||
try {
|
||
// 获取打印数据
|
||
let requestIds = selectedRows.map((item) => item.requestId).join(',');
|
||
console.log('打印请求ID:', requestIds);
|
||
|
||
const res = await advicePrint({ requestIds: requestIds, isPrescription: '1' });
|
||
console.log('打印数据获取结果:', res);
|
||
|
||
if (!res || !res.data || !res.data.adviceItemList) {
|
||
proxy.$modal.msgError('获取打印数据失败:数据格式不正确');
|
||
return null;
|
||
}
|
||
|
||
const groupedRows = {};
|
||
res.data.adviceItemList.forEach((row) => {
|
||
const prescriptionNo = row.prescriptionNo;
|
||
if (!groupedRows[prescriptionNo]) {
|
||
groupedRows[prescriptionNo] = [];
|
||
}
|
||
row.contractName = res.data.contractName;
|
||
groupedRows[prescriptionNo].push(row);
|
||
});
|
||
|
||
const groupedArray = Object.values(groupedRows);
|
||
const result = [];
|
||
|
||
groupedArray.forEach((item) => {
|
||
if (item && item.length > 0) {
|
||
// 从处方列表的第一个条目提取处方信息
|
||
const firstItem = item[0];
|
||
const total = item.reduce((sum, item) => {
|
||
return sum + (item.totalPrice || 0);
|
||
}, 0);
|
||
|
||
// 转换药品列表字段,确保与打印模板匹配
|
||
const transformedPrescriptionList = item.map(medItem => ({
|
||
...medItem,
|
||
// 添加模板需要的字段映射
|
||
medicineName: medItem.itemName, // 用于模板中的medicineName字段
|
||
totalVolume: medItem.totalVolume || medItem.spec || '', // 后端返回的规格字段是totalVolume
|
||
unitPrice: medItem.unitPrice || medItem.price || 0, // 使用后端返回的unitPrice
|
||
unitCode_dictText: medItem.unitCode_dictText || medItem.unit || '', // 使用后端返回的unitCode_dictText
|
||
// 添加其他可能需要的字段
|
||
dose: medItem.dose || '',
|
||
doseUnitCode_dictText: medItem.doseUnitCode_dictText || '',
|
||
methodCode_dictText: medItem.methodCode_dictText || medItem.usage || '',
|
||
rateCode_dictText: medItem.rateCode_dictText || medItem.rateCode || ''
|
||
}));
|
||
|
||
result.push({
|
||
...res.data,
|
||
// 确保处方号、患者信息等关键数据正确提取,并添加模板需要的字段映射
|
||
prescriptionNo: firstItem.prescriptionNo,
|
||
patientName: res.data.patientName || firstItem.patientName,
|
||
gender: res.data.genderEnum || firstItem.gender,
|
||
genderEnum_enumText: res.data.genderEnum_enumText || firstItem.gender || '', // 使用后端返回的性别文本
|
||
age: res.data.age || firstItem.age,
|
||
adviceDate: res.data.reqTime || firstItem.adviceDate || firstItem.createTime || new Date().toLocaleDateString(),
|
||
reqTime: res.data.reqTime || firstItem.adviceDate || firstItem.createTime || new Date().toLocaleDateString(), // 开具日期字段映射
|
||
doctorName: res.data.doctorName || firstItem.doctorName,
|
||
medTotalAmount: total,
|
||
// 添加模板需要的其他字段
|
||
encounterNo: res.data.encounterNo || firstItem.encounterNo || '', // 门诊号
|
||
departmentName: res.data.departmentName || firstItem.departmentName || '', // 科室
|
||
conditionName: res.data.conditionName || firstItem.conditionName || '', // 临床诊断
|
||
phone: res.data.phone || firstItem.phone || '', // 电话
|
||
contractName: res.data.contractName || firstItem.contractName || '', // 医疗机构
|
||
prescriptionList: transformedPrescriptionList, // 使用转换后的药品列表
|
||
});
|
||
}
|
||
});
|
||
|
||
console.log('打印数据准备完成:', result);
|
||
return result;
|
||
} catch (error) {
|
||
console.error('获取打印数据失败:', error);
|
||
proxy.$modal.msgError('获取打印数据失败: ' + error.message);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
// 合并预览和打印功能的主函数
|
||
async function previewAndPrint() {
|
||
try {
|
||
const result = await getPrintData();
|
||
if (!result) return;
|
||
|
||
// 保存预览数据
|
||
previewData.value = result;
|
||
|
||
console.log('直接执行处方打印预览');
|
||
|
||
// 构建预览HTML(保持原有格式)
|
||
let previewHtml = '';
|
||
|
||
// 为每个处方生成预览内容
|
||
result.forEach((prescription, index) => {
|
||
// 确保处方数据存在
|
||
if (!prescription) return;
|
||
|
||
// 从处方获取药品列表,确保是数组
|
||
const prescriptionList = Array.isArray(prescription.prescriptionList) ? prescription.prescriptionList : [];
|
||
|
||
previewHtml += '<div class="prescription-container">';
|
||
previewHtml += '<h3>处方 ' + (index + 1) + '</h3>';
|
||
previewHtml += '<div class="prescription-info">';
|
||
previewHtml += '<p><strong>处方号:</strong> ' + (prescription.prescriptionNo || 'N/A') + '</p>';
|
||
previewHtml += '<p><strong>患者姓名:</strong> ' + (prescription.patientName || 'N/A') + '</p>';
|
||
previewHtml += '<p><strong>性别:</strong> ' + (prescription.genderEnum_enumText || prescription.gender || 'N/A') + '</p>';
|
||
previewHtml += '<p><strong>年龄:</strong> ' + (prescription.age || 'N/A') + '</p>';
|
||
previewHtml += '<p><strong>开具日期:</strong> ' + (prescription.reqTime || prescription.adviceDate || prescription.createTime || new Date().toLocaleDateString()) + '</p>';
|
||
previewHtml += '<p><strong>医生:</strong> ' + (prescription.doctorName || 'N/A') + '</p>';
|
||
// 添加额外的处方信息
|
||
if (prescription.encounterNo) previewHtml += '<p><strong>门诊号:</strong> ' + prescription.encounterNo + '</p>';
|
||
if (prescription.departmentName) previewHtml += '<p><strong>科室:</strong> ' + prescription.departmentName + '</p>';
|
||
if (prescription.conditionName) previewHtml += '<p><strong>临床诊断:</strong> ' + prescription.conditionName + '</p>';
|
||
if (prescription.phone) previewHtml += '<p><strong>电话:</strong> ' + prescription.phone + '</p>';
|
||
previewHtml += '</div>';
|
||
|
||
previewHtml += '<table class="prescription-table">';
|
||
previewHtml += '<thead>';
|
||
previewHtml += '<tr>';
|
||
previewHtml += '<th>药品名称</th>';
|
||
previewHtml += '<th>规格</th>';
|
||
previewHtml += '<th>单价</th>';
|
||
previewHtml += '<th>数量</th>';
|
||
previewHtml += '<th>金额</th>';
|
||
previewHtml += '<th>费用等级</th>';
|
||
previewHtml += '<th>用法用量</th>';
|
||
previewHtml += '</tr>';
|
||
previewHtml += '</thead>';
|
||
previewHtml += '<tbody>';
|
||
|
||
// 添加药品列表
|
||
if (prescriptionList.length > 0) {
|
||
prescriptionList.forEach((item) => {
|
||
previewHtml += '<tr>';
|
||
// 使用映射后的字段名,确保与打印模板一致
|
||
previewHtml += '<td>' + (item.medicineName || item.itemName || 'N/A') + '</td>';
|
||
previewHtml += '<td>' + (item.totalVolume || item.spec || '') + '</td>';
|
||
previewHtml += '<td>' + (item.unitPrice || item.price || '0.00') + '</td>';
|
||
previewHtml += '<td>' + (item.quantity || 'N/A') + ' ' + (item.unitCode_dictText || item.unit || '') + '</td>';
|
||
previewHtml += '<td>' + (item.totalPrice || '0.00') + '</td>';
|
||
previewHtml += '<td>' + (item.contractName || 'N/A') + '</td>';
|
||
// 组合用法用量信息
|
||
const usageInfo = [];
|
||
if (item.dose && item.doseUnitCode_dictText) usageInfo.push(item.dose + item.doseUnitCode_dictText);
|
||
if (item.methodCode_dictText || item.usage) usageInfo.push(item.methodCode_dictText || item.usage);
|
||
if (item.frequency) usageInfo.push(item.frequency);
|
||
previewHtml += '<td>' + usageInfo.join('<br/>') + '</td>';
|
||
previewHtml += '</tr>';
|
||
});
|
||
} else {
|
||
previewHtml += '<tr><td colspan="7" style="text-align: center;">暂无药品信息</td></tr>';
|
||
}
|
||
|
||
previewHtml += '</tbody>';
|
||
previewHtml += '<tfoot>';
|
||
previewHtml += '<tr>';
|
||
previewHtml += '<td colspan="6" style="text-align: right; font-weight: bold;">总计:</td>';
|
||
previewHtml += '<td style="font-weight: bold;">' + (prescription.medTotalAmount || '0.00') + '</td>';
|
||
previewHtml += '</tr>';
|
||
previewHtml += '</tfoot>';
|
||
previewHtml += '</table>';
|
||
|
||
previewHtml += '<div class="prescription-footer">';
|
||
previewHtml += '<p><strong>医疗机构:</strong> ' + (prescription.contractName || 'N/A') + '</p>';
|
||
previewHtml += '</div>';
|
||
previewHtml += '</div>';
|
||
previewHtml += '<hr class="prescription-separator">';
|
||
});
|
||
|
||
// 创建临时打印容器(不可见)
|
||
const printContainer = document.createElement('div');
|
||
printContainer.style.position = 'fixed';
|
||
printContainer.style.left = '-9999px';
|
||
printContainer.style.top = '-9999px';
|
||
printContainer.style.width = '800px';
|
||
|
||
// 添加打印样式,确保只打印药品信息
|
||
const style = document.createElement('style');
|
||
style.textContent = `
|
||
/* 确保打印样式只应用于药品信息 */
|
||
.print-content {
|
||
font-family: Arial, sans-serif;
|
||
font-size: 12px;
|
||
}
|
||
.medicine-table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
}
|
||
.medicine-table th,
|
||
.medicine-table td {
|
||
border: 1px solid #000;
|
||
padding: 8px;
|
||
text-align: left;
|
||
}
|
||
.medicine-table th {
|
||
background: #f2f2f2;
|
||
font-weight: bold;
|
||
}
|
||
.page-break {
|
||
page-break-after: always;
|
||
}
|
||
/* 隐藏不需要打印的元素 */
|
||
@media print {
|
||
body > *:not(#print-container) {
|
||
display: none !important;
|
||
}
|
||
#print-container {
|
||
position: static !important;
|
||
width: 100% !important;
|
||
}
|
||
}
|
||
`;
|
||
document.head.appendChild(style);
|
||
|
||
// 设置容器ID以便CSS选择
|
||
printContainer.id = 'print-container';
|
||
|
||
// 仅构建药品信息表格
|
||
let medicineHtml = '<div class="print-content">';
|
||
|
||
result.forEach((prescription, index) => {
|
||
if (!prescription) return;
|
||
const prescriptionList = Array.isArray(prescription.prescriptionList) ? prescription.prescriptionList : [];
|
||
|
||
// 只保留必要的药品信息
|
||
medicineHtml += '<div class="prescription-medicines">';
|
||
medicineHtml += '<h4>处方 ' + (index + 1) + '</h4>';
|
||
|
||
if (prescriptionList.length > 0) {
|
||
medicineHtml += '<table class="medicine-table">';
|
||
medicineHtml += '<thead>';
|
||
medicineHtml += '<tr>';
|
||
medicineHtml += '<th>药品名称</th>';
|
||
medicineHtml += '<th>规格</th>';
|
||
medicineHtml += '<th>单价</th>';
|
||
medicineHtml += '<th>数量</th>';
|
||
medicineHtml += '<th>金额</th>';
|
||
medicineHtml += '<th>用法用量</th>';
|
||
medicineHtml += '</tr>';
|
||
medicineHtml += '</thead>';
|
||
medicineHtml += '<tbody>';
|
||
|
||
prescriptionList.forEach((item) => {
|
||
medicineHtml += '<tr>';
|
||
medicineHtml += '<td>' + (item.medicineName || item.itemName || 'N/A') + '</td>';
|
||
medicineHtml += '<td>' + (item.totalVolume || item.spec || '') + '</td>';
|
||
medicineHtml += '<td>' + (item.unitPrice || item.price || '0.00') + '</td>';
|
||
medicineHtml += '<td>' + (item.quantity || 'N/A') + ' ' + (item.unitCode_dictText || item.unit || '') + '</td>';
|
||
medicineHtml += '<td>' + (item.totalPrice || '0.00') + '</td>';
|
||
|
||
// 组合用法用量信息
|
||
const usageInfo = [];
|
||
if (item.dose && item.doseUnitCode_dictText) usageInfo.push(item.dose + item.doseUnitCode_dictText);
|
||
if (item.methodCode_dictText || item.usage) usageInfo.push(item.methodCode_dictText || item.usage);
|
||
if (item.frequency) usageInfo.push(item.frequency);
|
||
medicineHtml += '<td>' + usageInfo.join('<br/>') + '</td>';
|
||
medicineHtml += '</tr>';
|
||
});
|
||
|
||
medicineHtml += '</tbody>';
|
||
medicineHtml += '<tfoot>';
|
||
medicineHtml += '<tr>';
|
||
medicineHtml += '<td colspan="4" style="text-align: right; font-weight: bold;">总计:</td>';
|
||
medicineHtml += '<td colspan="2" style="font-weight: bold;">' + (prescription.medTotalAmount || '0.00') + '</td>';
|
||
medicineHtml += '</tr>';
|
||
medicineHtml += '</tfoot>';
|
||
medicineHtml += '</table>';
|
||
} else {
|
||
medicineHtml += '<p>暂无药品信息</p>';
|
||
}
|
||
|
||
// 分页符(最后一个处方除外)
|
||
if (index < result.length - 1) {
|
||
medicineHtml += '<div class="page-break"></div>';
|
||
}
|
||
|
||
medicineHtml += '</div>';
|
||
});
|
||
|
||
medicineHtml += '</div>';
|
||
printContainer.innerHTML = medicineHtml;
|
||
|
||
// 添加到文档
|
||
document.body.appendChild(printContainer);
|
||
|
||
// 触发打印预览
|
||
window.print();
|
||
|
||
// 打印完成后移除临时容器和样式
|
||
const cleanup = () => {
|
||
// 移除临时容器
|
||
if (printContainer && document.body.contains(printContainer)) {
|
||
document.body.removeChild(printContainer);
|
||
}
|
||
// 移除临时样式
|
||
if (style && document.head.contains(style)) {
|
||
document.head.removeChild(style);
|
||
}
|
||
// 移除事件监听器
|
||
window.removeEventListener('afterprint', cleanup);
|
||
};
|
||
|
||
// 监听打印完成事件
|
||
window.addEventListener('afterprint', cleanup);
|
||
|
||
// 添加超时清理,防止打印预览取消时资源未释放
|
||
setTimeout(() => {
|
||
cleanup();
|
||
}, 30000); // 30秒后自动清理
|
||
|
||
proxy.$modal.msgSuccess('打印预览已启动');
|
||
|
||
// 同时处理后台打印逻辑
|
||
setTimeout(() => {
|
||
handleBackgroundPrint(result);
|
||
}, 500);
|
||
} catch (error) {
|
||
console.error('预览和打印过程出错:', error);
|
||
proxy.$modal.msgError('操作失败: ' + error.message);
|
||
}
|
||
}
|
||
|
||
// 后台打印逻辑,复用原有的打印功能
|
||
function handleBackgroundPrint(result) {
|
||
try {
|
||
// 获取打印机列表
|
||
const printers = getPrinterList();
|
||
console.log('获取到的打印机列表:', printers);
|
||
|
||
if (printers.length === 0) {
|
||
console.log('未检测到可用打印机,仅提供预览功能');
|
||
return;
|
||
}
|
||
|
||
// 设置打印机列表
|
||
printerList.value = printers;
|
||
|
||
// 检查是否有缓存的打印机
|
||
const cachedPrinter = getCachedPrinter();
|
||
console.log('缓存的打印机:', cachedPrinter);
|
||
|
||
if (cachedPrinter && printers.some(printer => printer.name === cachedPrinter)) {
|
||
// 如果有缓存的打印机,直接使用
|
||
selectedPrinter.value = cachedPrinter;
|
||
confirmPrinter(result);
|
||
} else {
|
||
// 否则不自动显示打印机选择对话框,让用户在预览页面手动选择打印
|
||
console.log('无缓存打印机,用户可在预览页面手动打印');
|
||
}
|
||
} catch (error) {
|
||
console.error('后台打印过程出错:', error);
|
||
// 不显示错误提示,以免干扰用户在预览页面的操作
|
||
}
|
||
}
|
||
|
||
// 使用保存的打印数据执行打印
|
||
function confirmPrinter(printData) {
|
||
console.log('开始打印,传入数据:', printData);
|
||
console.log('window临时数据:', window.currentPrintData);
|
||
|
||
// 如果没有传入数据,尝试从window临时变量获取
|
||
let data = printData || window.currentPrintData;
|
||
|
||
if (!selectedPrinter.value) {
|
||
proxy.$modal.msgWarning('请选择打印机');
|
||
return;
|
||
}
|
||
|
||
if (!data || !Array.isArray(data) || data.length === 0) {
|
||
proxy.$modal.msgError('没有找到有效的打印数据');
|
||
showPrinterDialog.value = false;
|
||
return;
|
||
}
|
||
|
||
if (!templateJson) {
|
||
proxy.$modal.msgError('打印模板加载失败');
|
||
showPrinterDialog.value = false;
|
||
return;
|
||
}
|
||
|
||
// 确保数据字段映射正确,特别是规格字段
|
||
data = data.map(prescription => {
|
||
const mappedPrescription = { ...prescription };
|
||
// 确保药品列表字段映射正确
|
||
if (Array.isArray(prescription.prescriptionList)) {
|
||
mappedPrescription.prescriptionList = prescription.prescriptionList.map(med => ({
|
||
...med,
|
||
// 确保规格字段正确映射,优先使用totalVolume
|
||
totalVolume: med.totalVolume || med.spec || '',
|
||
// 确保其他关键字段存在
|
||
medicineName: med.medicineName || med.itemName || '',
|
||
unitPrice: med.unitPrice || med.price || 0,
|
||
unitCode_dictText: med.unitCode_dictText || med.unit || '',
|
||
methodCode_dictText: med.methodCode_dictText || med.usage || ''
|
||
}));
|
||
}
|
||
return mappedPrescription;
|
||
});
|
||
console.log('处理后的打印数据:', data);
|
||
|
||
console.log('准备执行打印,打印机:', selectedPrinter.value);
|
||
|
||
// 使用his.js中的savePrinterToCache保存选择
|
||
savePrinterToCache(selectedPrinter.value);
|
||
|
||
try {
|
||
// 检查hiprint是否可用
|
||
if (!window.hiprint) {
|
||
throw new Error('打印插件未正确加载');
|
||
}
|
||
|
||
// 直接使用hiprint执行打印,确保功能正常
|
||
const hiprintTemplate = new window.hiprint.PrintTemplate({ template: templateJson });
|
||
const printOptions = {
|
||
title: '处方打印',
|
||
height: 210,
|
||
width: 148,
|
||
printer: selectedPrinter.value
|
||
};
|
||
|
||
// 打印成功回调
|
||
hiprintTemplate.on('printSuccess', function (e) {
|
||
console.log('打印成功:', e);
|
||
proxy.$modal.msgSuccess('打印成功');
|
||
showPrinterDialog.value = false;
|
||
// 清除临时数据
|
||
window.currentPrintData = null;
|
||
});
|
||
|
||
// 打印失败回调
|
||
hiprintTemplate.on('printError', function (e) {
|
||
console.error('打印失败:', e);
|
||
proxy.$modal.msgError('打印失败,请检查打印机连接');
|
||
showPrinterDialog.value = false;
|
||
window.currentPrintData = null;
|
||
});
|
||
|
||
// 执行打印
|
||
console.log('调用hiprint.print2方法');
|
||
hiprintTemplate.print2(data, printOptions);
|
||
} catch (error) {
|
||
console.error('打印执行出错:', error);
|
||
proxy.$modal.msgError('打印执行失败: ' + error.message);
|
||
showPrinterDialog.value = false;
|
||
window.currentPrintData = null;
|
||
}
|
||
}
|
||
|
||
// 取消打印机选择
|
||
function cancelPrinter() {
|
||
showPrinterDialog.value = false;
|
||
window.currentPrintData = null;
|
||
}
|
||
/** 重置按钮操作 */
|
||
function resetQuery() {
|
||
setDefaultDateRange();
|
||
medicineInfoList.value = [];
|
||
personInfo.value = [];
|
||
proxy.resetForm('queryRef');
|
||
getList();
|
||
}
|
||
/** 搜索按钮操作 */
|
||
function handleQuery() {
|
||
if (dateRange.value) {
|
||
queryParams.value.receptionTimeSTime = dateRange.value[0] + ' 00:00:00';
|
||
queryParams.value.receptionTimeETime = dateRange.value[1] + ' 23:59:59';
|
||
} else {
|
||
queryParams.value.receptionTimeSTime = null;
|
||
queryParams.value.receptionTimeETime = null;
|
||
}
|
||
queryParams.value.pageNo = 1;
|
||
console.log('************', queryParams.value);
|
||
listPatient(queryParams.value).then((response) => {
|
||
patientList.value = response.data.records;
|
||
total.value = response.data.total;
|
||
});
|
||
}
|
||
|
||
function countGroupRows(data) {
|
||
const groupCounts = new Map();
|
||
data.forEach((item, index) => {
|
||
if (!groupCounts.has(item.prescriptionNo)) {
|
||
groupCounts.set(item.prescriptionNo, { count: 0, indices: [] });
|
||
}
|
||
const groupInfo = groupCounts.get(item.prescriptionNo);
|
||
groupInfo.count++;
|
||
groupInfo.indices.push(index);
|
||
});
|
||
return groupCounts;
|
||
}
|
||
function getRowMarkers(groupCounts, data) {
|
||
const markers = new Array(data.length).fill('');
|
||
|
||
groupCounts.forEach((groupInfo, prescriptionNo) => {
|
||
const { count, indices } = groupInfo;
|
||
if (count === 1) {
|
||
// 如果只有一行,不显示标记
|
||
return;
|
||
} else if (count === 2) {
|
||
// 如果有两行,分别显示左右括号
|
||
markers[indices[0]] = '┏';
|
||
markers[indices[1]] = '┗ ';
|
||
} else {
|
||
// 如果有两行以上,第一条显示左括号,中间用竖线,最后一条显示右括号
|
||
markers[indices[0]] = '┏';
|
||
for (let i = 1; i < indices.length - 1; i++) {
|
||
markers[indices[i]] = '┃';
|
||
}
|
||
markers[indices[indices.length - 1]] = '┗ ';
|
||
}
|
||
});
|
||
return markers;
|
||
}
|
||
|
||
function spanMethod({ row, column, rowIndex, columnIndex }) {
|
||
// 定义需要合并的列范围(前6列,包括selection列)
|
||
const columnsToMerge = [1, 16]; // 假设selection列是第0列,其他列依次是1, 2, 3, 4, 5
|
||
console.log(row);
|
||
// 检查当前列是否在需要合并的列范围内
|
||
if (row.prescriptionNo) {
|
||
if (columnsToMerge.includes(columnIndex)) {
|
||
const prescriptionNo = row.prescriptionNo;
|
||
|
||
// 查找当前处方号在列表中第一次出现的索引
|
||
const firstRowIndex = medicineInfoList.value.findIndex(
|
||
(item) => item.prescriptionNo === prescriptionNo
|
||
);
|
||
|
||
// 如果当前行是该处方号的首行,则合并count行
|
||
if (rowIndex === firstRowIndex) {
|
||
// 计算该处方号的总行数
|
||
const count = medicineInfoList.value.filter(
|
||
(item) => item.prescriptionNo === prescriptionNo
|
||
).length;
|
||
return [count, 1]; // 合并count行,1列
|
||
} else {
|
||
return [0, 0]; // 其他行不显示
|
||
}
|
||
}
|
||
}
|
||
|
||
// 其他列不进行合并
|
||
return [1, 1];
|
||
}
|
||
|
||
function handleSelectionChange(selectedRows, currentRow) {
|
||
medicineInfoList.value
|
||
.filter((item) => {
|
||
return item.dispenseId == currentRow.dispenseId;
|
||
})
|
||
.forEach((item, index) => {
|
||
tableRef.value.toggleRowSelection(item, selectedRows.includes(currentRow));
|
||
});
|
||
}
|
||
|
||
function formatPrice(row, column, cellValue) {
|
||
if (cellValue === null || cellValue === undefined) {
|
||
return '0.00 元'; // 如果值为空,返回0.00
|
||
}
|
||
return cellValue.toFixed(2) + ' 元'; // 保留两位小数
|
||
}
|
||
|
||
function tagType(statusEnum) {
|
||
if (statusEnum == 2 || statusEnum == 2) {
|
||
return 'default';
|
||
} else if (statusEnum == 4) {
|
||
return 'success';
|
||
} else if (statusEnum == 5 || statusEnum == 6 || statusEnum == 7) {
|
||
return 'warning';
|
||
} else if (statusEnum == 12) {
|
||
return 'info';
|
||
}
|
||
}
|
||
|
||
function handleCurrentChange(row) {
|
||
currentRow.value = row; // 更新当前选中行的数据
|
||
console.log('当前选中行的数据:', currentRow.value);
|
||
currentRow.value.statusEnum = undefined;
|
||
currentRow.value.dispenseStatus = queryParams.value.statusEnum;
|
||
getMedicineList(row.encounterId);
|
||
}
|
||
|
||
function getMedicineList(encounterId) {
|
||
// 根据projectTypeCode的值决定调用哪些接口
|
||
if (projectTypeCode.value == 1) {
|
||
// 同时调用两个接口并将数据合并显示
|
||
Promise.all([
|
||
listWesternmedicine({
|
||
pageNo: 1,
|
||
pageSize: 100,
|
||
encounterId: encounterId,
|
||
statusEnum: queryParams.value.statusEnum,
|
||
tcmFlag: tcmFlag.value,
|
||
}),
|
||
getReportRegisterInit({
|
||
pageNo: 1,
|
||
pageSize: 100,
|
||
encounterId: encounterId,
|
||
statusEnum: queryParams.value.statusEnum,
|
||
tcmFlag: tcmFlag.value,
|
||
}),
|
||
])
|
||
.then(([westernRes, reportRes]) => {
|
||
// 合并两个接口的数据
|
||
let westernData = Array.isArray(westernRes.data.records)
|
||
? westernRes.data.records
|
||
: [westernRes.data.records];
|
||
|
||
let reportData = Array.isArray(reportRes.data.records)
|
||
? reportRes.data.records
|
||
: [reportRes.data.records];
|
||
|
||
// 合并数据
|
||
medicineInfoList.value = [...westernData, ...reportData];
|
||
|
||
// 处理合并后的数据
|
||
processMedicineListData();
|
||
})
|
||
.catch((error) => {
|
||
console.error('获取数据失败:', error);
|
||
proxy.$modal.msgError('获取数据失败');
|
||
});
|
||
} else if (projectTypeCode.value == 2) {
|
||
// 只调用listWesternmedicine接口
|
||
listWesternmedicine({
|
||
pageNo: 1,
|
||
pageSize: 100,
|
||
encounterId: encounterId,
|
||
statusEnum: queryParams.value.statusEnum,
|
||
tcmFlag: tcmFlag.value,
|
||
}).then((response) => {
|
||
console.log('121212', response);
|
||
// personInfo.value = response.data.prescriptionPatientInfoDto;
|
||
medicineInfoList.value = Array.isArray(response.data.records)
|
||
? response.data.records
|
||
: [response.data.records];
|
||
|
||
// 处理数据
|
||
processMedicineListData();
|
||
});
|
||
} else if (projectTypeCode.value == 3) {
|
||
// 只调用getReportRegisterInit接口
|
||
getReportRegisterInit({
|
||
encounterId: encounterId,
|
||
statusEnum: queryParams.value.statusEnum,
|
||
tcmFlag: tcmFlag.value,
|
||
}).then((response) => {
|
||
medicineInfoList.value = Array.isArray(response.data.records)
|
||
? response.data.records
|
||
: [response.data.records];
|
||
|
||
// 处理数据
|
||
processMedicineListData();
|
||
});
|
||
}
|
||
}
|
||
|
||
// 提取公共的数据处理逻辑
|
||
function processMedicineListData() {
|
||
// 创建分组映射表
|
||
const groupMap = {};
|
||
medicineTotalPrice.value = 0;
|
||
medicineInfoList.value.forEach((item) => {
|
||
const groupId = item.groupId; // 确保属性名一致
|
||
medicineTotalPrice.value = medicineTotalPrice.value + item.totalPrice;
|
||
if (groupId != null) {
|
||
// 过滤掉null/undefined
|
||
groupMap[groupId] = groupMap[groupId] || [];
|
||
groupMap[groupId].push(item);
|
||
}
|
||
});
|
||
|
||
// 处理每个分组
|
||
Object.values(groupMap).forEach((group) => {
|
||
const count = group.length;
|
||
if (count === 2) {
|
||
group[0].flag = '┓';
|
||
group[1].flag = '┛';
|
||
} else if (count > 2) {
|
||
group[0].flag = '┓';
|
||
group.slice(1, -1).forEach((item) => (item.flag = '┃')); // 中间元素
|
||
group[group.length - 1].flag = '┛';
|
||
}
|
||
});
|
||
|
||
// 处理没有分组的项
|
||
medicineInfoList.value.forEach((item) => {
|
||
if (item.groupId == null) {
|
||
// 确保属性名一致
|
||
item.flag = '';
|
||
} else if (!item.flag) {
|
||
// 确保所有项都有flag属性
|
||
item.flag = '';
|
||
}
|
||
});
|
||
|
||
diagnoses.value = medicineInfoList.value.map((item) => item.诊断 || '无').join(', ');
|
||
}
|
||
|
||
function submitMedicine(saveList) {
|
||
console.log(saveList);
|
||
if (projectTypeCode.value == 1) {
|
||
// 根据itemTable分类数据
|
||
const deviceList = saveList.filter((item) => item.itemTable === 'adm_device_definition');
|
||
const medicineList = saveList.filter((item) => item.itemTable === 'med_medication_definition');
|
||
|
||
// 并行处理两种类型的发药
|
||
const promises = [];
|
||
|
||
// 如果有耗材数据,调用deviceDispense接口
|
||
if (deviceList.length > 0) {
|
||
promises.push(
|
||
deviceDispense(deviceList).then((res) => {
|
||
if (res.code != 200) {
|
||
throw new Error('耗材发药失败');
|
||
}
|
||
return res;
|
||
})
|
||
);
|
||
}
|
||
|
||
// 如果有药品数据,调用prepareMedicion接口
|
||
if (medicineList.length > 0) {
|
||
promises.push(
|
||
prepareMedicion(medicineList).then((res) => {
|
||
if (res.code != 200) {
|
||
throw new Error('药品发药失败');
|
||
}
|
||
return res;
|
||
})
|
||
);
|
||
}
|
||
|
||
// 等待所有发药接口完成
|
||
Promise.all(promises)
|
||
.then(() => {
|
||
// 所有发药都成功后,调用更新接口
|
||
if (medicineList.length > 0) {
|
||
return updateMedicion(medicineList);
|
||
}
|
||
})
|
||
.then((response) => {
|
||
proxy.$modal.msgSuccess('发药成功');
|
||
// 重新获取数据
|
||
getMedicineList(currentRow.value.encounterId);
|
||
})
|
||
.catch((error) => {
|
||
console.error('发药失败:', error);
|
||
proxy.$modal.msgError('发药失败: ' + error.message);
|
||
});
|
||
} else if (projectTypeCode.value == 2) {
|
||
prepareMedicion(saveList).then((res) => {
|
||
if (res.code == 200) {
|
||
updateMedicion(saveList).then((response) => {
|
||
proxy.$modal.msgSuccess('发药成功');
|
||
getMedicineList(currentRow.value.encounterId);
|
||
});
|
||
}
|
||
});
|
||
} else {
|
||
deviceDispense(saveList).then((res) => {
|
||
if (res.code == 200) {
|
||
proxy.$modal.msgSuccess('发药成功');
|
||
getMedicineList(currentRow.value.encounterId);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
const throttledGetList = debounce(handelTraceNo, 500);
|
||
const traceNoInput = debounce(handleTraceNoInput, 500);
|
||
|
||
function formatContent(value) {
|
||
let content = '';
|
||
if (value && value.endsWith(',')) {
|
||
value = value.slice(0, -1);
|
||
}
|
||
if (value) {
|
||
value.split(',').forEach((item, index) => {
|
||
content += `[${index + 1}] ${item}\n`;
|
||
});
|
||
return content;
|
||
}
|
||
}
|
||
function handleTraceNoInput(row, index) {
|
||
if (row.traceNo) {
|
||
// 先移除所有逗号
|
||
let cleanStr = row.traceNo.replace(/,/g, '');
|
||
// 每20个字符插入一个逗号
|
||
let formattedStr = cleanStr.replace(/(.{20})/g, '$1,');
|
||
// 如果最后一个字符是逗号则移除
|
||
formattedStr = formattedStr.replace(/,$/, '');
|
||
row.traceNo = formattedStr;
|
||
|
||
// 保持输入焦点
|
||
proxy.$refs['traceNoRef' + index].focus();
|
||
}
|
||
}
|
||
|
||
let inputValue = '';
|
||
function handelTraceNo(value) {
|
||
traceNoList.value.push(value);
|
||
traceNo.value = traceNo.value + '[' + traceNoList.value.length + ']' + ' ' + value + '\n';
|
||
traceNoTemp.value = '';
|
||
// let saveValue = value.substring(inputValue.length + 5, value.length);
|
||
// inputValue = value;
|
||
// console.log(value);
|
||
// console.log(saveValue);
|
||
// traceNoList.value.push(saveValue);
|
||
// traceNo.value = value + '[' + (traceNoList.value.length + 1) + ']' + ' ';
|
||
}
|
||
|
||
function handleBatch(row) {
|
||
let saveList = [];
|
||
if (row) {
|
||
saveList = medicineInfoList.value
|
||
.filter((item) => {
|
||
return item.dispenseId === row.dispenseId;
|
||
})
|
||
.map((item) => {
|
||
return {
|
||
requestId: item.requestId,
|
||
dispenseId: item.dispenseId,
|
||
traceNo: item.traceNo,
|
||
prescriptionNo: item.prescriptionNo,
|
||
preparerId: preparerDoctor.value,
|
||
itemTable: item.itemTable,
|
||
};
|
||
});
|
||
} else {
|
||
if (tableRef.value.getSelectionRows().length > 0) {
|
||
saveList = tableRef.value.getSelectionRows().map((item) => {
|
||
return {
|
||
requestId: item.requestId,
|
||
dispenseId: item.dispenseId,
|
||
traceNo: item.traceNo,
|
||
prescriptionNo: item.prescriptionNo,
|
||
preparerId: preparerDoctor.value,
|
||
itemTable: item.itemTable,
|
||
};
|
||
});
|
||
}
|
||
}
|
||
console.log(saveList);
|
||
|
||
submitMedicine(saveList);
|
||
}
|
||
|
||
function backMedicine(row) {
|
||
showDialog.value = true;
|
||
selectedPrescriptionNo.value = row.dispenseId;
|
||
selectedRow.value = row;
|
||
console.log('作废原因:', selectedPrescriptionNo.value, row.prescriptionNo);
|
||
}
|
||
|
||
function handleConfirm() {
|
||
if (!notPerformedReasonEnum.value) {
|
||
ElMessage.error('请选择作废原因');
|
||
return;
|
||
}
|
||
if (selectedRow.value.itemTable != 'adm_device_definition') {
|
||
backMedicion([
|
||
{
|
||
dispenseId: selectedPrescriptionNo.value,
|
||
notPerformedReasonEnum: notPerformedReasonEnum.value,
|
||
},
|
||
]).then((response) => {
|
||
proxy.$modal.msgSuccess('作废成功');
|
||
});
|
||
} else {
|
||
deviceInvalid([
|
||
{
|
||
dispenseId: selectedPrescriptionNo.value,
|
||
notPerformedReasonEnum: notPerformedReasonEnum.value,
|
||
},
|
||
]).then((response) => {
|
||
proxy.$modal.msgSuccess('作废成功');
|
||
});
|
||
}
|
||
getMedicineList(currentRow.value.encounterId);
|
||
showDialog.value = false;
|
||
notPerformedReasonEnum.value = ''; // 清空选择
|
||
}
|
||
|
||
function handleCancel() {
|
||
showDialog.value = false;
|
||
notPerformedReasonEnum.value = ''; // 清空选择
|
||
}
|
||
|
||
// getList();
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.app-container {
|
||
padding: 20px;
|
||
display: flex;
|
||
}
|
||
|
||
.left {
|
||
width: 25%;
|
||
|
||
.form {
|
||
width: 100%;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
}
|
||
}
|
||
|
||
.right {
|
||
margin-left: 2%;
|
||
width: 74%;
|
||
}
|
||
|
||
:deep(.el-table tbody tr:hover > td) {
|
||
background-color: inherit !important;
|
||
}
|
||
|
||
.el-form--inline .el-form-item {
|
||
margin-right: 0px;
|
||
}
|
||
::v-deep.el-textarea .el-textarea__inner {
|
||
resize: none !important;
|
||
}
|
||
</style>
|