Files
zyt/admin/src/components/PrescriptionAuditLayout.vue
T
2026-11-26 15:46:20 +08:00

116 lines
3.5 KiB
Vue

<template>
<div v-if="prescriptionId !== null" class="prescription-audit-layout">
<section class="prescription-audit-preview" aria-label="处方单" :aria-busy="loading">
<PrescriptionSlip v-if="detail" :data="detail" compact />
<el-skeleton v-else-if="loading" :rows="8" animated />
<div v-if="error" class="prescription-audit-preview__error" role="status">
<span>{{ error }}</span>
<el-button v-if="prescriptionId > 0" size="small" @click="retry++">重试加载处方</el-button>
</div>
</section>
<section class="prescription-audit-controls" aria-label="签署和审核">
<slot />
</section>
</div>
<slot v-else />
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { prescriptionDetail } from '@/api/tcm'
import PrescriptionSlip from '@/components/prescription-slip/index.vue'
const props = defineProps<{
prescriptionId: number | null
doctorSignedAt?: number
pharmacistSignedAt?: number
}>()
const detail = ref<Record<string, any> | null>(null)
const retry = ref(0)
const loading = ref(false)
const error = ref('')
watch([
() => props.prescriptionId,
() => props.doctorSignedAt,
() => props.pharmacistSignedAt,
retry
], async ([id, doctorAt, pharmacistAt, attempt], previous, onCleanup) => {
if (id !== previous?.[0]) detail.value = null
loading.value = false
error.value = ''
if (id === null) return
if (!Number.isSafeInteger(id) || id <= 0) {
error.value = '当前订单未关联处方'
return
}
const current = detail.value?.esign
if (detail.value && attempt === previous?.[3]
&& (!doctorAt || doctorAt === (current?.signature_time || current?.signed_at))
&& (!pharmacistAt || pharmacistAt === current?.review_signature_time)) return
const controller = new AbortController()
onCleanup(() => controller.abort())
loading.value = true
try {
const response = await prescriptionDetail({ id }, controller.signal)
const result = response?.data ?? response
if (controller.signal.aborted) return
if (Number(result?.id) !== id) throw new Error('处方编号不匹配')
detail.value = result
} catch {
if (!controller.signal.aborted) error.value = '无法加载处方单,请重试。'
} finally {
if (!controller.signal.aborted) loading.value = false
}
}, { immediate: true })
</script>
<style scoped>
.prescription-audit-layout {
display: grid;
grid-template-columns: minmax(0, 1.42fr) minmax(320px, 1fr);
gap: 18px;
align-items: start;
}
.prescription-audit-preview,
.prescription-audit-controls {
min-width: 0;
max-height: min(68vh, 780px);
overflow: auto;
scrollbar-gutter: stable;
}
.prescription-audit-preview {
padding: 10px;
border: 1px solid var(--el-border-color-light);
border-radius: 8px;
background: var(--el-fill-color-light);
}
.prescription-audit-controls { padding-right: 3px; }
.prescription-audit-preview__error {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
padding: 10px;
color: var(--el-text-color-regular);
}
@media (max-width: 840px) {
.prescription-audit-layout {
grid-template-columns: minmax(0, 1fr);
gap: 12px;
max-height: 70vh;
overflow-y: auto;
}
.prescription-audit-preview { max-height: min(50vh, 560px); }
.prescription-audit-controls { max-height: none; overflow: visible; }
}
</style>