bug362 413 498 504 507
This commit is contained in:
@@ -519,17 +519,31 @@ watch(
|
||||
}
|
||||
);
|
||||
|
||||
// 加载科室选项
|
||||
// 加载科室选项(支持树形/扁平两种数据结构)
|
||||
function loadDepartmentOptions() {
|
||||
getOrgList()
|
||||
.then((res) => {
|
||||
if (res.data && res.data.records && res.data.records.length > 0) {
|
||||
const firstRecord = res.data.records[0];
|
||||
// 优先使用 children(树形结构),回退到 records 本身(扁平结构)
|
||||
departmentOptions.value = (firstRecord.children && firstRecord.children.length > 0)
|
||||
? firstRecord.children
|
||||
: res.data.records;
|
||||
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;
|
||||
}
|
||||
}
|
||||
// 所有方式都失败,置空
|
||||
departmentOptions.value = [];
|
||||
})
|
||||
.catch(() => {
|
||||
console.warn('科室列表加载失败(可能无权限)');
|
||||
@@ -593,12 +607,14 @@ function getItemType_Text(type) {
|
||||
}
|
||||
function getUnitCodeOptions(row) {
|
||||
const unitCodes = [
|
||||
{ code: String(row.unitCode), codeText: row.unitCode_dictText },
|
||||
{ code: String(row.minUnitCode), codeText: row.minUnitCode_dictText },
|
||||
].filter(item => item.code);
|
||||
{ code: row.unitCode != null ? String(row.unitCode) : null, codeText: row.unitCode_dictText },
|
||||
{ code: row.minUnitCode != null ? String(row.minUnitCode) : null, codeText: row.minUnitCode_dictText },
|
||||
];
|
||||
// 过滤掉 code 为空的单位选项
|
||||
const validUnitCodes = unitCodes.filter(item => item.code != null && item.code !== '');
|
||||
// 使用 Set 来跟踪已经存在的 code
|
||||
const seenCodes = new Set();
|
||||
const uniqueUnitCodes = unitCodes.filter((item) => {
|
||||
const uniqueUnitCodes = validUnitCodes.filter((item) => {
|
||||
// 如果 Set 中没有这个 code,就保留它,并把它加入 Set
|
||||
if (!seenCodes.has(item.code)) {
|
||||
seenCodes.add(item.code);
|
||||
@@ -667,14 +683,36 @@ function selectChange(row) {
|
||||
defaultUnitCode = String(row.minUnitCode);
|
||||
} else if (row.unitCode) {
|
||||
defaultUnitCode = String(row.unitCode);
|
||||
} else if (row.minUnitCode_dictText) {
|
||||
// 兜底:如果 minUnitCode 为空但字典文本存在,使用文本作为选项值
|
||||
defaultUnitCode = row.minUnitCode_dictText;
|
||||
} else if (row.unitCode_dictText) {
|
||||
defaultUnitCode = row.unitCode_dictText;
|
||||
}
|
||||
// 如果默认单位不在 uniqueUnitCodes 中,添加兜底选项
|
||||
if (defaultUnitCode && !uniqueUnitCodes.some(u => u.code === defaultUnitCode)) {
|
||||
uniqueUnitCodes.push({ code: defaultUnitCode, codeText: defaultUnitCode });
|
||||
}
|
||||
// 设置默认执行科室/位置(统一转为字符串,避免 el-select 类型不匹配)
|
||||
let defaultPositionId = undefined;
|
||||
if (row.adviceType === 3 && departmentOptions.value.length > 0) {
|
||||
// 诊疗:优先使用患者所在科室,否则取第一个科室
|
||||
const patientOrgId = props.patientInfo.organizationId;
|
||||
const matched = departmentOptions.value.find(d => String(d.id) === String(patientOrgId));
|
||||
defaultPositionId = matched ? String(matched.id) : String(departmentOptions.value[0].id);
|
||||
// 诊疗:
|
||||
// 1. 优先使用诊疗目录项目的"所属科室"(row.orgId)
|
||||
// 2. 其次使用患者当前病房科室(patientInfo.organizationId)
|
||||
// 3. 最后取第一个科室
|
||||
const orgIdPriority = [row.orgId, props.patientInfo.organizationId];
|
||||
for (const id of orgIdPriority) {
|
||||
if (id) {
|
||||
const matched = departmentOptions.value.find(d => String(d.id) === String(id));
|
||||
if (matched) {
|
||||
defaultPositionId = String(matched.id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!defaultPositionId) {
|
||||
defaultPositionId = String(departmentOptions.value[0].id);
|
||||
}
|
||||
} else if (row.adviceType === 2 && locationOptions.value.length > 0) {
|
||||
// 耗材:默认取第一个药房/耗材房
|
||||
defaultPositionId = String(locationOptions.value[0].value);
|
||||
|
||||
@@ -458,7 +458,9 @@ const loadPatientInfo = () => {
|
||||
'YYYY-MM-DD HH:mm:ss'
|
||||
);
|
||||
} else {
|
||||
interventionForm.value.startTime = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss');
|
||||
// 已有患者(entranceType == 1)不自动填充当前时间,避免覆盖历史数据
|
||||
// 新入科患者由后端默认返回当前时间,或由用户手动选择
|
||||
interventionForm.value.startTime = '';
|
||||
}
|
||||
interventionForm.value.height = res.data.height;
|
||||
interventionForm.value.weight = res.data.weight;
|
||||
|
||||
Reference in New Issue
Block a user