Fix Bug #477: 住院医生工作站-住院检查申请详情弹窗中"发往科室"字段显示为短横线(-),未正常获取数据

根因分析:
1. 前端组件使用了错误的API获取科室列表:表单使用getDepartmentList(/app-common/department-list)
   保存的targetDepartment ID,但详情弹窗使用getOrgList(/base-data-manage/organization/organization)
   查询,两个接口返回的数据结构和ID不同,导致recursionFun无法匹配到科室名称
2. recursionFun中obj.children可能为null/undefined,直接遍历会抛TypeError
3. getLocationInfo是异步调用,handleViewDetail可能在科室数据加载完成前被调用

修复:
- 统一使用getDepartmentList(@/api/public.js)获取科室数据,与表单组件保持一致
- recursionFun增加children空值保护
- handleViewDetail改为async,打开详情前确保科室数据已加载
This commit is contained in:
张飞
2026-05-13 00:05:11 +08:00
parent 0600bbecbc
commit 4092abfce9

View File

@@ -168,7 +168,7 @@ import {computed, getCurrentInstance, ref, watch} from 'vue';
import {Refresh, Search} from '@element-plus/icons-vue'; import {Refresh, Search} from '@element-plus/icons-vue';
import {patientInfo} from '../../store/patient.js'; import {patientInfo} from '../../store/patient.js';
import {getCheck} from './api'; import {getCheck} from './api';
import {getOrgList} from '@/views/doctorstation/components/api.js'; import {getDepartmentList} from '@/api/public.js';
const { proxy } = getCurrentInstance(); const { proxy } = getCurrentInstance();
@@ -293,8 +293,8 @@ const hasMatchedFields = computed(() => {
/** 查询科室 */ /** 查询科室 */
const getLocationInfo = () => { const getLocationInfo = () => {
getOrgList().then((res) => { getDepartmentList().then((res) => {
orgOptions.value = res.data.records; orgOptions.value = res.data || [];
}); });
}; };
@@ -306,17 +306,19 @@ const recursionFun = (targetDepartment) => {
name = obj.name; name = obj.name;
} }
const subObjArray = obj['children']; const subObjArray = obj['children'];
for (let index = 0; index < subObjArray.length; index++) { if (subObjArray && subObjArray.length > 0) {
const item = subObjArray[index]; for (let index = 0; index < subObjArray.length; index++) {
if (item.id == targetDepartment) { const item = subObjArray[index];
name = item.name; if (item.id == targetDepartment) {
name = item.name;
}
} }
} }
} }
return name; return name;
}; };
const handleViewDetail = (row) => { const handleViewDetail = async (row) => {
console.log('targetDepartment========>', JSON.stringify(row)); console.log('targetDepartment========>', JSON.stringify(row));
currentDetail.value = row; currentDetail.value = row;
@@ -324,6 +326,15 @@ const handleViewDetail = (row) => {
if (row.descJson) { if (row.descJson) {
try { try {
const obj = JSON.parse(row.descJson); const obj = JSON.parse(row.descJson);
// 确保科室数据已加载
if (!orgOptions.value || orgOptions.value.length === 0) {
await new Promise((resolve) => {
getDepartmentList().then((res) => {
orgOptions.value = res.data || [];
resolve();
});
});
}
obj.targetDepartment = recursionFun(obj.targetDepartment); obj.targetDepartment = recursionFun(obj.targetDepartment);
descJsonData.value = obj; descJsonData.value = obj;
} catch (e) { } catch (e) {