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

根因:medicineList.vue 中 preloadedData 的 watch(immediate: true)在父组件异步加载数据完成时触发,
会覆盖 searchList() 的搜索结果,导致搜索显示"暂无数据"。

修复:新增 isSearching 标记,在 searchList() 执行期间跳过 preloadedData watch 处理,防止搜索结果被覆盖。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
赵云
2026-05-16 18:24:26 +08:00
parent 48f6b7195b
commit 96a57f1b7e

View File

@@ -38,6 +38,9 @@ const filteredList = ref([]); // 过滤后的数据列表
const hasLoaded = ref(false); // 标记是否已加载数据
const isLoading = ref(false); // 标记是否正在加载
// 标记是否正在执行搜索(用于防止 preloadedData 覆盖搜索结果)
const isSearching = ref(false);
// 获取诊疗项目列表
function getList() {
if (hasLoaded.value) return; // 如果已经加载过数据,则不再重复请求
@@ -66,6 +69,7 @@ function getList() {
// 服务端搜索(当用户输入搜索关键词时)
function searchList(searchKey) {
if (!searchKey || searchKey.trim() === '') return;
isSearching.value = true;
isLoading.value = true;
// 使用较大的pageSize确保搜索结果尽可能多
getDiagnosisTreatmentList({ statusEnum: 2, searchKey: searchKey.trim(), pageSize: 5000, pageNo: 1 })
@@ -79,6 +83,7 @@ function searchList(searchKey) {
})
.finally(() => {
isLoading.value = false;
isSearching.value = false;
});
}
@@ -119,6 +124,8 @@ watch(
watch(
() => props.preloadedData,
(newData) => {
// 正在搜索时跳过避免覆盖searchList的搜索结果
if (isSearching.value) return;
if (newData && newData.length > 0) {
diagnosisTreatmentList.value = newData;
filterList(); // 更新过滤