Fix Bug #477: 住院检查申请详情弹窗中"发往科室"字段显示异常

根因:recursionFun 使用嵌套循环搜索科室树,但 API 返回扁平列表导致匹配失败。
修复:改用递归 findTreeItem 搜索(与 medicalExaminations.vue 一致),添加 API 错误处理,
并在 ID 匹配失败时回退显示原始值而非空白。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
关羽
2026-05-14 03:21:55 +08:00
parent c7f87a9c95
commit 5b6f33912d

View File

@@ -310,32 +310,26 @@ const hasMatchedFields = computed(() => {
/** 查询科室 */ /** 查询科室 */
const getLocationInfo = async () => { const getLocationInfo = async () => {
try {
const res = await getDepartmentList(); const res = await getDepartmentList();
orgOptions.value = res.data || []; orgOptions.value = Array.isArray(res.data) ? res.data : [];
} catch (e) {
console.warn('科室列表加载失败:', e.message);
orgOptions.value = [];
}
}; };
const recursionFun = (targetDepartment) => { // 递归查找树形科室节点
if (!targetDepartment) return ''; const findTreeItem = (list, id) => {
let name = ''; if (!list || list.length === 0) return null;
for (let index = 0; index < orgOptions.value.length; index++) { for (const item of list) {
const obj = orgOptions.value[index]; if (item.id == id) return item;
if (obj.id == targetDepartment) { if (item.children && item.children.length > 0) {
name = obj.name; const found = findTreeItem(item.children, id);
break; if (found) return found;
}
const subObjArray = obj['children'];
if (subObjArray && subObjArray.length > 0) {
for (let i = 0; i < subObjArray.length; i++) {
const item = subObjArray[i];
if (item.id == targetDepartment) {
name = item.name;
break;
} }
} }
} return null;
if (name) break;
}
return name;
}; };
const handleViewDetail = async (row) => { const handleViewDetail = async (row) => {
@@ -349,7 +343,11 @@ const handleViewDetail = async (row) => {
if (row.descJson) { if (row.descJson) {
try { try {
const obj = JSON.parse(row.descJson); const obj = JSON.parse(row.descJson);
obj.targetDepartment = recursionFun(obj.targetDepartment); // 将发往科室 ID 转换为名称
if (obj.targetDepartment) {
const deptItem = findTreeItem(orgOptions.value, obj.targetDepartment);
obj.targetDepartment = deptItem ? deptItem.name : obj.targetDepartment;
}
descJsonData.value = obj; descJsonData.value = obj;
} catch (e) { } catch (e) {
console.error('解析 descJson 失败:', e); console.error('解析 descJson 失败:', e);