feat(medicalOrderSet): 优化医嘱组套功能实现

- 实现医嘱基础列表的分页功能,添加loading状态和缓存机制
- 添加防抖处理和组织机构ID参数支持,优化性能表现
- 实现医嘱组套的完整编辑功能,包括增删改查操作界面
- 添加医嘱组套预览、应用和管理功能模块
- 实现西医组套筛选功能,确保tcmFlag参数正确传递
- 优化医嘱组套数据结构,完善明细项信息处理逻辑
- 添加表单验证和错误处理,提升用户体验和系统稳定性
- 重构代码结构,采用响应式设计提高可维护性
This commit is contained in:
2026-03-17 09:57:21 +08:00
parent 03939fb232
commit 8a7d2abb4a
30 changed files with 2066 additions and 543 deletions

View File

@@ -1,33 +1,14 @@
<template>
<div @keyup="handleKeyDown" tabindex="0" ref="tableWrapper">
<!-- 医保等级测试区域已隐藏 -->
<!--
<div style="margin-bottom: 20px; padding: 10px; border: 1px solid #ccc; background: #f5f5f5;">
<h3>医保等级测试</h3>
<div>
<div>1 -> {{ getMedicalInsuranceLevel({chrgitmLv: '1'}) }}</div>
<div>2 -> {{ getMedicalInsuranceLevel({chrgitmLv: '2'}) }}</div>
<div>3 -> {{ getMedicalInsuranceLevel({chrgitmLv: '3'}) }}</div>
<div> -> {{ getMedicalInsuranceLevel({chrgitmLv: '甲'}) }}</div>
<div> -> {{ getMedicalInsuranceLevel({chrgitmLv: '乙'}) }}</div>
<div> -> {{ getMedicalInsuranceLevel({chrgitmLv: '自'}) }}</div>
<div>甲类 -> {{ getMedicalInsuranceLevel({chrgitmLv: '甲类'}) }}</div>
<div>乙类 -> {{ getMedicalInsuranceLevel({chrgitmLv: '乙类'}) }}</div>
<div>自费 -> {{ getMedicalInsuranceLevel({chrgitmLv: '自费'}) }}</div>
</div>
</div>
-->
<!-- 使用Element Plus的虚拟滚动表格 -->
<el-table
ref="adviceBaseRef"
v-loading="loading"
height="400"
:data="filteredAdviceBaseList"
:data="adviceBaseList"
highlight-current-row
@current-change="handleCurrentChange"
row-key="adviceDefinitionId"
@cell-click="clickRow"
v-loading="loading"
>
<el-table-column label="名称" align="center" prop="adviceName" width="200" show-overflow-tooltip />
<el-table-column label="包装单位" align="center" prop="unitCode_dictText" width="100" />
@@ -85,50 +66,9 @@
</template>
<script setup>
import { getCurrentInstance, nextTick, onMounted, ref, computed, watch } from 'vue';
import { nextTick, ref, watch, computed } from 'vue';
import { getAdviceBaseInfo, getDeviceList, getConsultationActivities } from './api';
import { throttle, debounce } from 'lodash-es';
const { proxy } = getCurrentInstance();
// 使用系统统一的数据字典
const { med_category_code, chrgitm_lv } = proxy.useDict('med_category_code', 'chrgitm_lv');
// 医保等级映射(作为后备使用)
const medicalInsuranceLevelMap = {
'1': '甲类',
'2': '乙类',
'3': '自费'
};
// 获取药品分类名称 - 使用系统统一的数据字典
function getCategoryName(row) {
if (!row) return '-';
if (row.adviceType === 1) { // 药品类型
// 优先使用系统统一的药品分类数据字典
if (med_category_code.value && med_category_code.value.length > 0) {
const found = med_category_code.value.find(item => String(item.value) === String(row.categoryCode));
if (found) {
return found.label;
}
}
// 兼容处理:对于中草药可能的多种编码形式
const herbCodes = ['3', '03', '4', 3, 4];
if (herbCodes.includes(row.categoryCode)) {
return '中草药';
}
return '-';
} else if (row.adviceType === 2 || row.adviceType === 4) { // 🔧 Bug Fix: 耗材类型2 或 4
return '耗材';
} else if (row.adviceType === 3) { // 诊疗类型
// 对于诊疗类型activityType 就是 category_code 的整数值,使用 activityType_dictText 显示
return row.activityType_dictText || row.categoryCode_dictText || row.categoryCode || '诊疗';
}
// 其他情况使用 categoryCode_dictText
return row.categoryCode_dictText || '-';
}
import { throttle } from 'lodash-es';
// 获取医保等级 - 简单直接的实现
function getMedicalInsuranceLevel(record) {
@@ -162,148 +102,121 @@ const props = defineProps({
type: Object,
required: true,
},
// 预加载的数据
preloadedData: {
type: Array,
default: () => []
},
// 预加载是否完成
preloadedLoaded: {
type: Boolean,
default: false
},
});
const emit = defineEmits(['selectAdviceBase']);
// 使用缓存机制
const searchCache = new Map();
const allAdviceData = ref([]); // 预加载数据
const isDataLoaded = ref(false); // 数据是否已加载
const adviceBaseList = ref([]);
const loading = ref(false);
const currentSelectRow = ref({});
const currentIndex = ref(0);
const tableWrapper = ref();
const loading = ref(false);
const isRequestInProgress = ref(false); // 请求进行中的标志
const adviceBaseRef = ref();
// 计算属性:根据搜索条件过滤数据
const filteredAdviceBaseList = computed(() => {
let result = [];
if (!props.adviceQueryParams.searchKey) {
result = adviceBaseList.value.slice(0, 50); // 返回前50个常用项目
} else {
const searchKey = props.adviceQueryParams.searchKey.toLowerCase();
result = adviceBaseList.value.filter(item =>
item.adviceName.toLowerCase().includes(searchKey) ||
item.py_str?.toLowerCase().includes(searchKey) ||
item.wb_str?.toLowerCase().includes(searchKey)
).slice(0, 100); // 限制返回数量
}
// 过滤无库存的药品(只针对药品类型 adviceType === 1
// Bug #129 修复确保库存为0的药品不被检索出来
result = result.filter(item => {
if (item.adviceType === 1) {
// 检查是否有库存
if (item.inventoryList && item.inventoryList.length > 0) {
// 计算总库存数量,确保转换为数字进行正确计算
const totalQuantity = item.inventoryList.reduce((sum, inv) => {
const qty = inv.quantity !== undefined && inv.quantity !== null
? (typeof inv.quantity === 'number' ? inv.quantity : Number(inv.quantity) || 0)
: 0;
return sum + qty;
}, 0);
return totalQuantity > 0;
}
return false; // 无库存列表或库存为空,视为无库存
}
return true; // 非药品类型不过滤
});
return result;
// 查询参数 - 与后端API参数名一致
const queryParams = ref({
pageSize: 100,
pageNo: 1,
adviceTypes: '1,2,3',
});
// 预加载数据
async function preloadData() {
if (isDataLoaded.value) return;
try {
const queryParams = {
pageSize: 10000, // 加载更多数据用于本地搜索
pageNum: 1,
adviceTypes: '1,2,3',
organizationId: props.patientInfo.orgId
};
const res = await getAdviceBaseInfo(queryParams);
allAdviceData.value = res.data?.records || [];
isDataLoaded.value = true;
} catch (error) {
console.error('预加载数据失败:', error);
}
}
// 节流函数 - 增强防抖机制
// 节流函数 - 与V1.3一致300ms首次立即响应
const throttledGetList = throttle(
async () => {
// 只有在没有进行中的请求时才执行
if (!isRequestInProgress.value) {
await getList();
}
() => {
getList();
},
500, // 增加到500ms减少频繁请求
{ leading: false, trailing: true }
300,
{ leading: true, trailing: true }
);
// 监听参数变化 - 使用防抖优化
// 监听参数变化 - 优化:优先使用预加载数据
watch(
() => props.adviceQueryParams,
(newValue) => {
// 只有在搜索关键词长度达到一定要求时才触发搜索
if (newValue.searchKey && newValue.searchKey.length < 2) {
adviceBaseList.value = [];
return;
queryParams.value.searchKey = newValue.searchKey;
if (newValue.adviceType) {
queryParams.value.adviceTypes = [newValue.adviceType].join(',');
} else {
queryParams.value.adviceTypes = '1,2,3';
}
throttledGetList();
},
{ deep: true }
);
// 获取数据
async function getList() {
// 防止重复请求
if (isRequestInProgress.value) {
return; // 如果请求正在进行中,直接返回
}
// 设置请求进行中的标志
isRequestInProgress.value = true;
loading.value = true; // 显示加载状态
try {
// 生成缓存键
const cacheKey = `${props.adviceQueryParams.searchKey}_${props.adviceQueryParams.adviceTypes}_${props.adviceQueryParams.categoryCode}_${props.patientInfo.orgId}`;
// 检查缓存
if (searchCache.has(cacheKey)) {
const cachedData = searchCache.get(cacheKey);
if (Date.now() - cachedData.timestamp < 300000) { // 5分钟有效期
adviceBaseList.value = cachedData.data;
return;
}
// 获取数据 - 优化:优先使用预加载数据
function getList() {
const searchKey = queryParams.value.searchKey || '';
const adviceTypes = queryParams.value.adviceTypes || '1,2,3';
// 判断是否可以使用预加载数据
// 条件:预加载数据已就绪,且是普通药品/诊疗类型(adviceTypes包含1,2,3),且没有搜索关键词或搜索关键词很短
const canUsePreloaded = props.preloadedLoaded &&
props.preloadedData &&
props.preloadedData.length > 0 &&
(adviceTypes === '1,2,3' || adviceTypes === '1' || adviceTypes === '2' || adviceTypes === '3');
if (canUsePreloaded) {
// 使用预加载数据
console.log('[adviceBaseList] 使用预加载数据,共', props.preloadedData.length, '条');
let filteredData = [...props.preloadedData]; // 创建副本避免修改原数据
// 根据 adviceTypes 过滤
if (adviceTypes !== '1,2,3') {
const types = adviceTypes.split(',').map(t => parseInt(t));
filteredData = filteredData.filter(item => types.includes(item.adviceType));
}
// 根据搜索关键词过滤
if (searchKey && searchKey.length >= 1) {
const lowerSearchKey = searchKey.toLowerCase();
filteredData = filteredData.filter(item =>
(item.adviceName && item.adviceName.toLowerCase().includes(lowerSearchKey)) ||
(item.adviceDefinitionId && item.adviceDefinitionId.toString().includes(searchKey))
);
}
adviceBaseList.value = filteredData;
nextTick(() => {
currentIndex.value = 0;
});
// 如果有搜索关键词,还需要后台请求更精确的结果
if (searchKey && searchKey.length >= 2) {
fetchFromApi(searchKey);
}
return;
}
// 不能使用预加载数据直接请求API
fetchFromApi(searchKey);
}
const queryParams = {
pageSize: 1000, // 增加页面大小以适应虚拟滚动
pageNum: 1,
adviceTypes: props.adviceQueryParams.adviceTypes || '1,2,3',
searchKey: props.adviceQueryParams.searchKey || '',
categoryCode: props.adviceQueryParams.categoryCode || '',
organizationId: props.patientInfo.orgId
};
// 从API获取数据
function fetchFromApi(searchKey) {
loading.value = true;
queryParams.value.organizationId = props.patientInfo.orgId;
const isConsumables = queryParams.value.adviceTypes === '2';
const isConsultation = queryParams.value.adviceTypes === '5';
const isConsumables = queryParams.adviceTypes === '2' || queryParams.adviceTypes === 2;
const isConsultation = queryParams.adviceTypes === '5' || queryParams.adviceTypes === 5;
if (isConsultation) {
// 会诊类型:调用会诊项目接口
const res = await getConsultationActivities();
if (isConsultation) {
// 会诊类型
getConsultationActivities().then((res) => {
if (res.data && Array.isArray(res.data)) {
const result = res.data.map((item) => ({
adviceBaseList.value = res.data.map((item) => ({
adviceName: item.name || item.activityName,
adviceType: 5, // 会诊类型
unitCode: '111', // 次
adviceType: 5,
unitCode: '111',
unitCode_dictText: '次',
minUnitCode: '111',
minUnitCode_dictText: '次',
@@ -322,34 +235,32 @@ async function getList() {
injectFlag_enumText: '否',
skinTestFlag: 0,
skinTestFlag_enumText: '否',
categoryCode: 31, // 会诊的category_enum
categoryCode: 31,
unitPrice: item.price || 0,
...item,
}));
// 缓存结果
searchCache.set(cacheKey, {
data: result,
timestamp: Date.now()
nextTick(() => {
currentIndex.value = 0;
});
adviceBaseList.value = result;
} else {
adviceBaseList.value = [];
}
} else if (isConsumables) {
const deviceQueryParams = {
pageNo: queryParams.pageNum || 1,
pageSize: queryParams.pageSize || 1000,
searchKey: queryParams.searchKey || '',
statusEnum: 2,
};
}).finally(() => {
loading.value = false;
});
return;
}
const res = await getDeviceList(deviceQueryParams);
if (isConsumables) {
// 耗材类型
getDeviceList({
pageNo: 1,
pageSize: 100,
searchKey: searchKey || '',
statusEnum: 2,
}).then((res) => {
if (res.data && res.data.records) {
const result = res.data.records.map((item) => ({
adviceBaseList.value = res.data.records.map((item) => ({
adviceName: item.name || item.busNo,
adviceType: 4, // 🔧 Bug #147 修复前端耗材类型值为4保存时会转换为后端类型值2
adviceType: 4,
unitCode: item.unitCode || '',
unitCode_dictText: item.unitCode_dictText || '',
minUnitCode: item.minUnitCode || item.unitCode || '',
@@ -359,7 +270,7 @@ async function getList() {
priceList: item.price ? [{ price: item.price }] : (item.retailPrice ? [{ price: item.retailPrice }] : []),
inventoryList: [],
adviceDefinitionId: item.id,
adviceTableName: 'adm_device_definition', // 🔧 Bug #177 修复:添加耗材表名,用于后端库存匹配
adviceTableName: 'adm_device_definition',
chargeItemDefinitionId: item.id,
positionId: item.locationId,
positionName: item.locationId_dictText || '',
@@ -375,66 +286,41 @@ async function getList() {
deviceName: item.name,
...item,
}));
// 缓存结果
searchCache.set(cacheKey, {
data: result,
timestamp: Date.now()
nextTick(() => {
currentIndex.value = 0;
});
adviceBaseList.value = result;
} else {
adviceBaseList.value = [];
}
} else {
const res = await getAdviceBaseInfo(queryParams);
let result = res.data?.records || [];
}).finally(() => {
loading.value = false;
});
return;
}
// 缓存结果
searchCache.set(cacheKey, {
data: result,
timestamp: Date.now()
// 普通药品/诊疗 - 与V1.3一致的处理方式
getAdviceBaseInfo(queryParams.value).then((res) => {
if (res.data && res.data.records && res.data.records.length > 0) {
// 与V1.3一致:在获取数据后直接过滤无库存的药品
adviceBaseList.value = res.data.records.filter((item) => {
if (item.adviceType == 1 || item.adviceType == 2) {
return handleQuantity(item) != 0;
} else {
return true;
}
});
nextTick(() => {
currentIndex.value = 0;
});
adviceBaseList.value = result;
}
} catch (error) {
console.error('获取数据失败:', error);
adviceBaseList.value = [];
} finally {
// 无论成功或失败,都要清除请求标志和加载状态
isRequestInProgress.value = false;
}).finally(() => {
loading.value = false;
}
});
}
// 格式化剂量显示
function formatDose(item) {
if (!item.dose || isNaN(parseFloat(item.dose))) {
return '-';
}
const num = parseFloat(item.dose);
if (num.toFixed(2) === '0.00') {
return '-';
}
return num.toFixed(2) + (item.doseUnitCode_dictText || '');
}
// 从priceList列表中获取价格
// 从priceList列表中获取价格 - 与V1.3一致
function getPriceFromInventory(row) {
if (row.priceList && row.priceList.length > 0) {
const price = row.priceList[0].price;
// 检查价格是否为有效数字
if (price !== undefined && price !== null && !isNaN(price) && isFinite(price)) {
return Number(price).toFixed(2) + ' 元';
}
// 如果价格无效,尝试从其他可能的字段获取价格
if (row.totalPrice !== undefined && row.totalPrice !== null && !isNaN(row.totalPrice) && isFinite(row.totalPrice)) {
return Number(row.totalPrice).toFixed(2) + ' 元';
}
if (row.price !== undefined && row.price !== null && !isNaN(row.price) && isFinite(row.price)) {
return Number(row.price).toFixed(2) + ' 元';
}
const price = row.priceList[0].price || 0;
return Number(price).toFixed(2) + ' 元';
}
return '-';
}
@@ -442,31 +328,29 @@ function getPriceFromInventory(row) {
function handleQuantity(row) {
if (row.inventoryList && row.inventoryList.length > 0) {
const totalQuantity = row.inventoryList.reduce((sum, item) => sum + (item.quantity || 0), 0);
return totalQuantity.toString() + (row.minUnitCode_dictText || '');
return totalQuantity.toString() + row.minUnitCode_dictText;
}
return '0';
return 0;
}
// 处理键盘事件
// 处理键盘事件 - 与V1.3一致
const handleKeyDown = (event) => {
const key = event.key;
const data = filteredAdviceBaseList.value;
if (data.length === 0) return;
const data = adviceBaseList.value;
switch (key) {
case 'ArrowUp': // 上箭头
event.preventDefault();
if (currentIndex.value > 0) {
currentIndex.value--;
currentSelectRow.value = data[currentIndex.value];
setCurrentRow(data[currentIndex.value]);
}
break;
case 'ArrowDown': // 下箭头
event.preventDefault();
if (currentIndex.value < data.length - 1) {
currentIndex.value++;
currentSelectRow.value = data[currentIndex.value];
setCurrentRow(data[currentIndex.value]);
}
break;
case 'Enter': // 回车键
@@ -478,9 +362,19 @@ const handleKeyDown = (event) => {
}
};
// 当前行变化时更新索引
// 设置选中行(带滚动)- 与V1.3一致
const setCurrentRow = (row) => {
adviceBaseRef.value.setCurrentRow(row);
const tableBody = adviceBaseRef.value.$el.querySelector('.el-table__body-wrapper');
const currentRowEl = adviceBaseRef.value.$el.querySelector('.current-row');
if (tableBody && currentRowEl) {
currentRowEl.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
};
// 当前行变化时更新索引 - 与V1.3一致
const handleCurrentChange = (currentRow) => {
currentIndex.value = filteredAdviceBaseList.value.findIndex((item) => item.adviceDefinitionId === currentRow.adviceDefinitionId);
currentIndex.value = adviceBaseList.value.findIndex((item) => item === currentRow);
currentSelectRow.value = currentRow;
};
@@ -489,12 +383,6 @@ function clickRow(row) {
emit('selectAdviceBase', row);
}
// 初始化
onMounted(() => {
// preloadData(); // 预加载数据
getList(); // 获取初始数据
});
defineExpose({
handleKeyDown,
});
@@ -502,4 +390,4 @@ defineExpose({
<style scoped>
/* 保留原有的表格样式 */
</style>
</style>