[bug]修改就诊时,就诊时间逻辑

This commit is contained in:
Auora
2025-10-31 16:23:12 +08:00
parent c07255fe5b
commit 2a7f1326b9
2 changed files with 38 additions and 20 deletions

View File

@@ -203,18 +203,32 @@ import { saveEmr, getEmrDetail, saveEmrTemplate } from '../api';
import emrTemplate from '../emr/emrtemplate.vue';
import emrhistory from '../emr/emrhistory.vue';
import { ref, computed } from 'vue';
import { ref, computed, watch, getCurrentInstance } from 'vue';
import { formatDate } from '@/utils/index';
// 2. 当前就诊日期(默认为当前时间;复诊为初诊日期)
const props = defineProps({
patientInfo: {
type: Object,
required: true,
},
visitType: { // 接收父组件传来的值
type: String,
default: '',
},
firstVisitDate: { // 父组件计算的初诊日期(若有历史病历)
type: String,
default: '',
},
});
// 2. 当前就诊日期(默认为当前时间)
const currentVisitDate = computed(() => {
return new Date().toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
});
// 复诊优先展示初诊日期
if (props.visitType === 'FOLLOW_UP' && props.firstVisitDate) {
return props.firstVisitDate;
}
// 初诊或未获取初诊日期时,展示挂号时间或当前时间
return formatDate(props.patientInfo?.registerTime || new Date());
});
const form = ref({});
@@ -228,16 +242,6 @@ const { proxy } = getCurrentInstance();
const showDialog = ref('');
const openEmrTemplate = ref(false);
const templateName = ref('');
const props = defineProps({
patientInfo: {
type: Object,
required: true,
},
visitType: { // ✅ 接收父组件传来的值
type: String,
default: '',
},
});
watch(
() => form.value,

View File

@@ -148,6 +148,7 @@
}
"
:visitType="visitType"
:firstVisitDate="firstVisitDate"
/>
</el-tab-pane>
<el-tab-pane label="诊断" name="diagnosis">
@@ -266,6 +267,7 @@ const waitCount = ref(0);
const loading = ref(false);
const { proxy } = getCurrentInstance();
const visitType = ref('');
const firstVisitDate = ref('');
const disabled = computed(() => {
return Object.keys(patientInfo.value).length === 0;
});
@@ -294,6 +296,7 @@ function setVisitType(type) {
function checkPatientHistory(patient) {
// 重置状态
visitTypeDisabled.value = false;
firstVisitDate.value = '';
// 如果患者没有身份证号,无法判断是否为初诊
if (!patient.idCard) {
@@ -320,20 +323,31 @@ function checkPatientHistory(patient) {
getEmrHistoryList(params).then(res => {
if (res.code === 200) {
const records = res.data?.records || [];
// 如果有历史记录,则为复诊
if (res.data && res.data.total > 0) {
visitType.value = 'FOLLOW_UP';
// 计算最早一次病历创建时间作为初诊日期
const earliest = records.reduce((min, cur) => {
const ct = new Date(cur.createTime).getTime();
return ct < min ? ct : min;
}, new Date(records[0].createTime).getTime());
// 使用统一格式化
firstVisitDate.value = formatDate(earliest);
} else {
// 如果没有历史记录,则为初诊
visitType.value = 'FIRST';
firstVisitDate.value = '';
}
} else {
// 请求失败,默认设置为初诊
visitType.value = 'FIRST';
firstVisitDate.value = '';
}
}).catch(() => {
// 异常情况,默认设置为初诊
visitType.value = 'FIRST';
firstVisitDate.value = '';
});
}
function getWaitPatient() {