Fix Bug #463: [目录管理-诊疗目录] 新增/编辑弹窗中"诊疗子项"检索功能失效,无法搜到已维护的项目

根因分析:medicineList.vue 的搜索功能仅做本地过滤,数据受限于初始加载的1000条(pageSize: 1000),
输入搜索关键词时不会向后端发起新的请求,导致不在前1000条内的项目无法被搜到。

修复策略:
1. medicineList.vue:当用户输入搜索关键词时,新增 searchList() 走服务端搜索(调用 API 的 searchKey 参数),
   使用 pageSize: 5000 提高搜索覆盖率;搜索词清空时恢复使用预加载数据
2. 放宽 childrenJson 过滤条件,从严格的 == null 改为兼容空字符串(== null || === '')
3. 修复 diagnosisTreatmentDialog.vue 中 medicineList 的重复 import
This commit is contained in:
关羽
2026-05-13 17:16:32 +08:00
parent 7e902973b8
commit 01f60513ae
2 changed files with 52 additions and 5 deletions

View File

@@ -372,7 +372,6 @@ import {
} from './diagnosistreatment';
import PopoverList from '@/components/OpenHis/popoverList/index.vue';
import medicineList from './medicineList.vue';
import MedicineList from '../components/medicineList.vue';
import {getCurrentInstance, nextTick, watch} from 'vue';
const { proxy } = getCurrentInstance();

View File

@@ -36,6 +36,7 @@ const emit = defineEmits(['selectRow']);
const diagnosisTreatmentList = ref([]); // 原始数据列表
const filteredList = ref([]); // 过滤后的数据列表
const hasLoaded = ref(false); // 标记是否已加载数据
const isLoading = ref(false); // 标记是否正在加载
// 获取诊疗项目列表
function getList() {
@@ -53,7 +54,7 @@ function getList() {
getDiagnosisTreatmentList({ statusEnum: 2, pageSize: 1000, pageNo: 1 })
.then((res) => {
diagnosisTreatmentList.value =
res.data?.records?.filter((item) => item.childrenJson == null) || [];
res.data?.records?.filter((item) => item.childrenJson == null || item.childrenJson === '') || [];
filterList(); // 初始化过滤
hasLoaded.value = true; // 标记为已加载
})
@@ -62,6 +63,47 @@ function getList() {
});
}
// 服务端搜索(当用户输入搜索关键词时)
function searchList(searchKey) {
if (!searchKey || searchKey.trim() === '') return;
isLoading.value = true;
// 使用较大的pageSize确保搜索结果尽可能多
getDiagnosisTreatmentList({ statusEnum: 2, searchKey: searchKey.trim(), pageSize: 5000, pageNo: 1 })
.then((res) => {
diagnosisTreatmentList.value =
res.data?.records?.filter((item) => item.childrenJson == null || item.childrenJson === '') || [];
filterList();
})
.catch((err) => {
console.error('搜索诊疗项目数据失败:', err);
})
.finally(() => {
isLoading.value = false;
});
}
// 获取预加载数据(不带搜索关键词时使用)
function loadPreloadedData() {
if (props.preloadedData && props.preloadedData.length > 0) {
diagnosisTreatmentList.value = props.preloadedData;
filterList();
hasLoaded.value = true;
return;
}
if (hasLoaded.value) return;
getDiagnosisTreatmentList({ statusEnum: 2, pageSize: 1000, pageNo: 1 })
.then((res) => {
diagnosisTreatmentList.value =
res.data?.records?.filter((item) => item.childrenJson == null || item.childrenJson === '') || [];
filterList();
hasLoaded.value = true;
})
.catch((err) => {
console.error('获取诊疗项目数据失败:', err);
});
}
// 监听shouldLoadData属性变化仅在首次为true时加载数据
watch(
() => props.shouldLoadData,
@@ -86,11 +128,17 @@ watch(
{ immediate: true }
);
// 监听搜索关键词变化,实时过滤数据
// 监听搜索关键词变化,有搜索词时走服务端搜索,否则走本地过滤
watch(
() => props.searchKey,
() => {
filterList();
(newVal) => {
if (newVal && newVal.trim() !== '') {
// 有搜索关键词,走服务端搜索
searchList(newVal);
} else {
// 搜索词为空,使用预加载数据
loadPreloadedData();
}
}
);