diff --git a/openhis-ui-vue3/src/views/inpatientNurse/InpatientBilling/components/FeeDialog.vue b/openhis-ui-vue3/src/views/inpatientNurse/InpatientBilling/components/FeeDialog.vue index b4651e4f6..55d2640bc 100755 --- a/openhis-ui-vue3/src/views/inpatientNurse/InpatientBilling/components/FeeDialog.vue +++ b/openhis-ui-vue3/src/views/inpatientNurse/InpatientBilling/components/FeeDialog.vue @@ -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 }); }