fix(prescription): 解决处方列表中科室选择和数据删除问题

- 为科室选择下拉框添加最小宽度样式,确保内容完整显示
- 添加orgTreeLoading状态管理,避免重复加载组织机构树
- 在selectAdviceBase方法中添加异步处理和边界检查逻辑
- 实现诊疗项目默认使用患者就诊科室的逻辑验证
- 修复ensureOrgTreeLoaded方法中的加载状态管理
- 在处方删除操作中添加encounterId和patientId参数传递
- 优化组织机构树查找算法,提升性能表现
This commit is contained in:
2026-03-24 12:48:07 +08:00
parent e0b9081649
commit 9f6e94da4b
3 changed files with 77 additions and 11 deletions

View File

@@ -135,6 +135,8 @@
value-key="id"
check-strictly
placeholder="请选择执行科室"
style="min-width: 150px; width: auto;"
class="org-select"
/>
<span class="total-amount">
总金额{{ scope.row.totalPrice ? scope.row.totalPrice + ' 元' : '0.00 元' }}
@@ -302,6 +304,7 @@ const unitCodeList = ref([]);
const adviceTableRef = ref([]);
const organization = ref([]);
const orgTreeLoaded = ref(false);
const orgTreeLoading = ref(false);
const rowRules = ref({
conditionDefinitionId: [{ required: true, message: '请选择诊断', trigger: 'change' }],
dose: [{ required: true, message: '请输入单次剂量', trigger: 'change' }],
@@ -473,9 +476,9 @@ function handleChange(value) {
/**
* 选择药品/诊疗项目回调
* 这里恢复为之前能正常工作的简单逻辑,只做最小必要的修正
* 这里恢复为之前"能正常工作"的简单逻辑,只做最小必要的修正
*/
function selectAdviceBase(key, row) {
async function selectAdviceBase(key, row) {
if (!row) {
console.error('[selectAdviceBase] row 为空');
return;
@@ -491,6 +494,16 @@ function selectAdviceBase(key, row) {
rowIndex.value = foundIndex;
}
// rowIndex 理论上由 handleFocus 设置;防御一下越界
if (rowIndex.value < 0 || rowIndex.value >= prescriptionList.value.length) {
const foundIndex = prescriptionList.value.findIndex((item) => item.uniqueKey === key);
if (foundIndex === -1) {
console.error('[selectAdviceBase] 找不到对应行key =', key);
return;
}
rowIndex.value = foundIndex;
}
// 关闭当前行弹窗
const currentRow = prescriptionList.value[rowIndex.value];
if (currentRow) {
@@ -499,7 +512,7 @@ function selectAdviceBase(key, row) {
// 诊疗(adviceType=3) 才需要加载执行科室树,且只加载一次
if (row.adviceType === 3) {
ensureOrgTreeLoaded();
await ensureOrgTreeLoaded();
}
// 构建单位列表(保持原有逻辑)
@@ -573,11 +586,24 @@ function selectAdviceBase(key, row) {
}
} else {
// 诊疗:设置执行科室和价格
// 🔧 Bug Fix #238: 如果positionId为空使用orgId作为默认值
const rowData = JSON.parse(JSON.stringify(row));
const selectedPositionId = rowData.positionId;
const selectedOrgId = rowData.orgId;
prescriptionList.value[rowIndex.value].orgId = selectedPositionId || selectedOrgId;
// 🔧 Bug Fix #238: 诊疗项目默认使用患者就诊科室(需确保科室在当前用户权限范围内)
if (!prescriptionList.value[rowIndex.value].orgId && props.patientInfo.orgId) {
// 检查患者就诊科室是否在当前用户的organization树中
const orgIdStr = String(props.patientInfo.orgId);
const findOrgInTree = (tree, targetId) => {
for (const node of tree) {
if (String(node.id) === targetId) return true;
if (node.children && node.children.length > 0) {
if (findOrgInTree(node.children, targetId)) return true;
}
}
return false;
};
if (findOrgInTree(organization.value, orgIdStr)) {
prescriptionList.value[rowIndex.value].orgId = props.patientInfo.orgId;
}
}
if (row.priceList && row.priceList.length > 0) {
prescriptionList.value[rowIndex.value].unitPrice = row.priceList[0].price;
} else {
@@ -603,16 +629,33 @@ function selectAdviceBase(key, row) {
}
function ensureOrgTreeLoaded() {
if (orgTreeLoaded.value) return;
orgTreeLoaded.value = true;
getOrgTree()
if (orgTreeLoaded.value && organization.value.length > 0) {
return Promise.resolve();
}
if (orgTreeLoading.value) {
// 如果正在加载中,等待加载完成
return new Promise((resolve) => {
const timer = setInterval(() => {
if (!orgTreeLoading.value) {
clearInterval(timer);
resolve();
}
}, 100);
});
}
orgTreeLoading.value = true;
return getOrgTree()
.then((res) => {
// 组织机构树接口通常返回分页 records这里做兼容兜底
organization.value = res?.data?.records ?? res?.data ?? [];
orgTreeLoaded.value = true;
})
.catch(() => {
// 加载失败时允许重试
orgTreeLoaded.value = false;
})
.finally(() => {
orgTreeLoading.value = false;
});
}
@@ -906,4 +949,23 @@ defineExpose({ getListInfo });
.el-table__cell .el-form-item--default {
margin-bottom: 0px;
}
/* 🔧 Bug Fix #238: 科室选择框样式,确保内容完整显示 */
.org-select {
min-width: 150px;
width: auto;
:deep(.el-select__wrapper) {
min-width: 150px;
}
:deep(.el-select__selection) {
min-width: 120px;
}
:deep(.el-select__selected-item) {
max-width: none;
white-space: nowrap;
}
}
</style>

View File

@@ -1991,6 +1991,8 @@ function handleDelete() {
requestId: deleteItem.requestId,
dbOpType: '3',
adviceType: deleteItem.adviceType,
encounterId: deleteItem.encounterId, // 🔧 BugFix#219: 添加就诊ID
patientId: deleteItem.patientId, // 🔧 BugFix#219: 添加患者ID
});
}
}

View File

@@ -981,6 +981,8 @@ function handleDelete(pIndex) {
prescriptionNo: deleteItem.prescriptionNo,
dbOpType: '3',
adviceType: deleteItem.adviceType,
encounterId: deleteItem.encounterId, // 🔧 BugFix#219: 添加就诊ID
patientId: deleteItem.patientId, // 🔧 BugFix#219: 添加患者ID
});
}
}