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

根因分析(与testApplication.vue对比发现):
1. getLocationInfo不是async函数,handleViewDetail中使用new Promise手动包装getDepartmentList
   作为降级方案,如果API调用失败则Promise永远不resolve(缺少catch),导致后续逻辑挂起
2. recursionFun缺少空值保护和break语句,可能在找到匹配后继续无效遍历

修复:
- getLocationInfo改为async/await模式(与testApplication.vue保持一致)
- handleViewDetail使用await getLocationInfo()替代不可靠的Promise包装
- recursionFun增加空值提前返回和break优化
This commit is contained in:
关羽
2026-05-13 18:19:15 +08:00
parent 31cac09126
commit 6258aa2589

View File

@@ -309,49 +309,46 @@ const hasMatchedFields = computed(() => {
});
/** 查询科室 */
const getLocationInfo = () => {
getDepartmentList().then((res) => {
orgOptions.value = res.data || [];
});
const getLocationInfo = async () => {
const res = await getDepartmentList();
orgOptions.value = res.data || [];
};
const recursionFun = (targetDepartment) => {
if (!targetDepartment) return '';
let name = '';
for (let index = 0; index < orgOptions.value.length; index++) {
const obj = orgOptions.value[index];
if (obj.id == targetDepartment) {
name = obj.name;
break;
}
const subObjArray = obj['children'];
if (subObjArray && subObjArray.length > 0) {
for (let index = 0; index < subObjArray.length; index++) {
const item = subObjArray[index];
for (let i = 0; i < subObjArray.length; i++) {
const item = subObjArray[i];
if (item.id == targetDepartment) {
name = item.name;
break;
}
}
}
if (name) break;
}
return name;
};
const handleViewDetail = async (row) => {
console.log('targetDepartment========>', JSON.stringify(row));
// 确保科室数据已加载,以便将 ID 解析为名称
if (!orgOptions.value || orgOptions.value.length === 0) {
await getLocationInfo();
}
currentDetail.value = row;
// 解析 descJson
if (row.descJson) {
try {
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);
descJsonData.value = obj;
} catch (e) {