Fix Bug #507: [住院护士站-住院记账-补费] 项目单位未获取、执行科室显示内码且缺乏默认/模糊搜索逻辑
根因分析: 1. 执行科室显示内码:loadDepartmentOptions 只读取树形结构的第一层(records[0].children), 但后端返回的是多层嵌套的树形数据。修复为递归扁平化 flattenTree() 提取所有科室节点。 2. 单位字段为空:getUnitCodeOptions 中 unitCode_dictText/minUnitCode_dictText 为 null 时, option 的 codeText 为 null 导致 el-select 无法显示。修复为 fallback 到 code 值本身。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -521,31 +521,28 @@ watch(
|
||||
}
|
||||
);
|
||||
|
||||
// 加载科室选项(支持树形/扁平两种数据结构)
|
||||
// 加载科室选项(递归扁平化树形结构)
|
||||
function loadDepartmentOptions() {
|
||||
getOrgList()
|
||||
.then((res) => {
|
||||
if (res.data) {
|
||||
// 尝试从树形结构中取:records[0].children
|
||||
if (res.data.records && res.data.records.length > 0) {
|
||||
if (res.data.records[0].children && res.data.records[0].children.length > 0) {
|
||||
departmentOptions.value = res.data.records[0].children;
|
||||
return;
|
||||
}
|
||||
// 如果 records[0] 有 id 和 name(非树根节点),直接用所有 records
|
||||
if (res.data.records[0].id) {
|
||||
departmentOptions.value = res.data.records;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 兜底:如果 records 不存在或为空,尝试直接使用 data 本身
|
||||
if (Array.isArray(res.data)) {
|
||||
departmentOptions.value = res.data;
|
||||
return;
|
||||
}
|
||||
if (!res?.data?.records?.length) {
|
||||
departmentOptions.value = [];
|
||||
return;
|
||||
}
|
||||
// 所有方式都失败,置空
|
||||
departmentOptions.value = [];
|
||||
// 递归扁平化树形结构,提取所有科室节点
|
||||
const flattenTree = (nodes) => {
|
||||
const result = [];
|
||||
for (const node of nodes) {
|
||||
if (node?.id && node?.name) {
|
||||
result.push(node);
|
||||
}
|
||||
if (node?.children?.length) {
|
||||
result.push(...flattenTree(node.children));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
departmentOptions.value = flattenTree(res.data.records);
|
||||
})
|
||||
.catch(() => {
|
||||
console.warn('科室列表加载失败(可能无权限)');
|
||||
@@ -611,13 +608,13 @@ function getUnitCodeOptions(row) {
|
||||
const unitCodes = [];
|
||||
// 大单位:优先用 code,code 缺失时用字典文本兜底
|
||||
if (row.unitCode != null && String(row.unitCode) !== '') {
|
||||
unitCodes.push({ code: String(row.unitCode), codeText: row.unitCode_dictText });
|
||||
unitCodes.push({ code: String(row.unitCode), codeText: row.unitCode_dictText || String(row.unitCode) });
|
||||
} else if (row.unitCode_dictText) {
|
||||
unitCodes.push({ code: row.unitCode_dictText, codeText: row.unitCode_dictText });
|
||||
}
|
||||
// 小单位:同上
|
||||
if (row.minUnitCode != null && String(row.minUnitCode) !== '') {
|
||||
unitCodes.push({ code: String(row.minUnitCode), codeText: row.minUnitCode_dictText });
|
||||
unitCodes.push({ code: String(row.minUnitCode), codeText: row.minUnitCode_dictText || String(row.minUnitCode) });
|
||||
} else if (row.minUnitCode_dictText) {
|
||||
unitCodes.push({ code: row.minUnitCode_dictText, codeText: row.minUnitCode_dictText });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user