diff --git a/openhis-ui-vue3/src/views/doctorstation/components/hospitalizationEmr/index.vue b/openhis-ui-vue3/src/views/doctorstation/components/hospitalizationEmr/index.vue index c29b0b80..300b6cf5 100644 --- a/openhis-ui-vue3/src/views/doctorstation/components/hospitalizationEmr/index.vue +++ b/openhis-ui-vue3/src/views/doctorstation/components/hospitalizationEmr/index.vue @@ -167,8 +167,29 @@ const handleNodeClick = (data, node) => { if (node.isLeaf) { // 存储当前节点数据 currentSelectTemplate.value = data.document; - currentComponent.value = currentSelectTemplate.value.vueRouter || ''; - // currentComponent.value = data.document.vueRouter || ''; + + // 在切换组件前先重置表单数据,避免显示之前的数据 + editForm.value = { + id: '', + definitionId: '', + definitionBusNo: '', + contentJson: '', + statusEnum: 1, + organizationId: 0, + encounterId: '', + patientId: '', + recordTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), + createBy: '', + source: '', + }; + + // 先清空当前组件,再设置新组件,确保组件完全重新渲染 + currentComponent.value = ''; + + // 使用 nextTick 确保 DOM 更新后再设置新组件 + nextTick(() => { + currentComponent.value = currentSelectTemplate.value.vueRouter || ''; + }); } else { currentSelectTemplate.value = { id: '', @@ -426,8 +447,21 @@ const loadLatestMedicalRecord = async () => { // 自动回显最新病历数据到模板 editForm.value = latestRecord; nextTick(() => { - if (emrComponentRef.value && latestRecord.contentJson) { - emrComponentRef.value.setFormData(JSON.parse(latestRecord.contentJson)); + if (emrComponentRef.value) { + // 确保动态组件已加载完成后再设置数据 + if (latestRecord.contentJson) { + try { + const parsedData = JSON.parse(latestRecord.contentJson); + emrComponentRef.value.setFormData(parsedData); + } catch (parseError) { + console.error('解析病历数据失败:', parseError); + // 解析失败时仍然尝试设置空数据以清空之前的残留数据 + emrComponentRef.value.setFormData({}); + } + } else { + // 如果没有内容数据,也要清空组件中的数据 + emrComponentRef.value.setFormData({}); + } } // 通知History组件更新选中状态 @@ -438,11 +472,51 @@ const loadLatestMedicalRecord = async () => { } else { // 清空选中状态 selectedHistoryRecordId.value = ''; + // 当没有历史记录时,也要清空当前表单数据,避免显示之前患者的数据 + editForm.value = { + id: '', + definitionId: '', + definitionBusNo: '', + contentJson: '', + statusEnum: 1, + organizationId: 0, + encounterId: '', + patientId: '', + recordTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), + createBy: '', + source: '', + }; + + nextTick(() => { + if (emrComponentRef.value) { + emrComponentRef.value.setFormData({}); + } + }); } } catch (error) { ElMessage.error('加载最新病历数据失败'); // 出错时也清空选中状态 selectedHistoryRecordId.value = ''; + // 出错时也要清空表单数据,避免显示之前患者的数据 + editForm.value = { + id: '', + definitionId: '', + definitionBusNo: '', + contentJson: '', + statusEnum: 1, + organizationId: 0, + encounterId: '', + patientId: '', + recordTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), + createBy: '', + source: '', + }; + + nextTick(() => { + if (emrComponentRef.value) { + emrComponentRef.value.setFormData({}); + } + }); } finally { loading.value = false; } @@ -689,6 +763,22 @@ watch( (newPatientInfo) => { // 当患者信息变化时,默认选中门诊病历模板并加载最新病历数据 if (newPatientInfo && newPatientInfo.patientId && Object.keys(newPatientInfo).length > 0) { + // 重置当前组件和表单数据,确保不会显示之前患者的数据 + currentComponent.value = ''; + editForm.value = { + id: '', + definitionId: '', + definitionBusNo: '', + contentJson: '', + statusEnum: 1, + organizationId: 0, + encounterId: '', + patientId: '', + recordTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), + createBy: '', + source: '', + }; + // 确保模板树已经加载 if (templateData.value && templateData.value.length > 0) { // 优先尝试使用更精确的selectDefaultTemplate函数 @@ -702,6 +792,22 @@ watch( }); }); } + } else { + // 如果没有患者信息,也要重置组件和表单数据 + currentComponent.value = ''; + editForm.value = { + id: '', + definitionId: '', + definitionBusNo: '', + contentJson: '', + statusEnum: 1, + organizationId: 0, + encounterId: '', + patientId: '', + recordTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), + createBy: '', + source: '', + }; } }, { deep: true, immediate: true }