460 lines
14 KiB
Vue
460 lines
14 KiB
Vue
<template>
|
||
<section class="daily-contacts" aria-label="今日维护名单">
|
||
<header class="daily-heading">
|
||
<div>
|
||
<h3>
|
||
今日维护 <span>{{ businessDate || '日期待确认' }} · 上海时间</span>
|
||
</h3>
|
||
<p>按患者合并到期任务;人工登记需要核实,不计入已联系。</p>
|
||
</div>
|
||
<el-button :loading="loading" @click="load()">刷新名单</el-button>
|
||
</header>
|
||
<el-alert v-if="error" :title="error" type="error" :closable="false" show-icon />
|
||
<el-alert
|
||
v-else-if="data && data.daily.state !== 'ready'"
|
||
:title="data.daily.reason || '今日计划尚未完整生成,暂不能确认维护完成情况'"
|
||
type="warning"
|
||
:closable="false"
|
||
show-icon
|
||
/>
|
||
<div v-if="data" class="daily-counts" aria-label="该医助今日患者小计">
|
||
<span
|
||
>应维护 <b>{{ data.summary.required ?? '—' }}</b></span
|
||
>
|
||
<span
|
||
>已联系 <b>{{ data.summary.contacted ?? '—' }}</b></span
|
||
>
|
||
<span
|
||
>待维护 <b>{{ data.summary.pending ?? '—' }}</b></span
|
||
>
|
||
<span
|
||
>人工登记待核实 <b>{{ data.summary.reported ?? '—' }}</b></span
|
||
>
|
||
<span class="muted">豁免 {{ data.summary.exempt ?? '—' }}</span>
|
||
</div>
|
||
<div class="status-filter" role="group" aria-label="今日名单状态">
|
||
<button
|
||
v-for="item in statuses"
|
||
:key="item.value"
|
||
type="button"
|
||
:aria-pressed="status === item.value"
|
||
:class="{ active: status === item.value }"
|
||
@click="setStatus(item.value)"
|
||
>
|
||
{{ item.label }}
|
||
</button>
|
||
</div>
|
||
<el-skeleton v-if="loading && !data" :rows="5" animated />
|
||
<template v-else>
|
||
<p
|
||
v-if="data && data.daily.state === 'ready' && data.summary.state === 'done'"
|
||
class="completion-note"
|
||
>
|
||
今日应维护患者均有联系记录。联系记录不代表患者已回复或服务质量已达标。
|
||
</p>
|
||
<ul v-if="data?.lists.length" class="patient-list" :aria-busy="loading">
|
||
<li v-for="patient in data.lists" :key="patient.key" class="patient-row">
|
||
<div class="patient-name">
|
||
<strong>{{ patient.patient_name || '未命名患者' }}</strong>
|
||
<small>诊单 #{{ patient.diagnosis_ids.join('、#') }}</small>
|
||
</div>
|
||
<div class="patient-reasons">
|
||
<p
|
||
v-for="reason in patient.reasons"
|
||
:key="`${reason.type}:${reason.source_id}`"
|
||
>
|
||
{{ reason.label
|
||
}}<small v-if="reason.due_at"
|
||
>到期 {{ shanghaiTime(reason.due_at) }}</small
|
||
>
|
||
</p>
|
||
<p v-if="patient.exempt_reason" class="muted">
|
||
豁免原因:{{ patient.exempt_reason }}
|
||
</p>
|
||
</div>
|
||
<div class="patient-state">
|
||
<strong
|
||
:class="{
|
||
attention:
|
||
patient.status === 'pending' || patient.status === 'reported'
|
||
}"
|
||
>
|
||
{{ statusLabels[patient.status] }}
|
||
</strong>
|
||
<small v-if="patient.status === 'pending'">未发现今日联系记录</small>
|
||
<small v-if="patient.last_contact_at"
|
||
>联系 {{ shanghaiTime(patient.last_contact_at) }}</small
|
||
>
|
||
<small
|
||
v-for="evidence in patient.evidence"
|
||
:key="`${evidence.type}:${evidence.id}`"
|
||
>
|
||
{{ evidence.label }} · {{ shanghaiTime(evidence.at) }}
|
||
</small>
|
||
</div>
|
||
<div class="record-links">
|
||
<el-button
|
||
v-for="(diagnosisId, index) in patient.diagnosis_ids"
|
||
:key="diagnosisId"
|
||
link
|
||
type="primary"
|
||
@click="openPatient(patient, diagnosisId)"
|
||
>
|
||
{{ index === 0 ? '查看记录' : `诊单 #${diagnosisId}` }}
|
||
</el-button>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
<el-empty v-else :description="emptyDescription" :image-size="70" />
|
||
</template>
|
||
<footer class="daily-footer">
|
||
<p>已联系仅依据该医助账号今日已归档的文字记录。电话、外部企微尚未接入。</p>
|
||
<el-pagination
|
||
v-if="data?.count"
|
||
v-model:current-page="page"
|
||
:total="data.count"
|
||
:page-size="10"
|
||
layout="total, prev, pager, next"
|
||
@current-change="load()"
|
||
/>
|
||
</footer>
|
||
<details v-if="data" class="coverage">
|
||
<summary>纳入规则与资料范围</summary>
|
||
<p>{{ data.daily.rule_label }}</p>
|
||
<p>
|
||
最近生成 {{ shanghaiTime(data.daily.last_scan_at) }} · 数据截至
|
||
{{ shanghaiTime(data.daily.as_of) }}
|
||
</p>
|
||
<p v-for="source in data.daily.coverage" :key="source.source">{{ source.note }}</p>
|
||
</details>
|
||
</section>
|
||
</template>
|
||
<script setup lang="ts">
|
||
import { computed, onActivated, onBeforeUnmount, onDeactivated, onMounted, ref, watch } from 'vue'
|
||
import {
|
||
assistantStaffDailyContacts,
|
||
type DailyPatient,
|
||
type DailyStatus,
|
||
type Patient,
|
||
type StaffDailyContacts
|
||
} from '@/api/assistantService'
|
||
import { errorText, isCancelled, shanghaiTime } from '../shared'
|
||
const props = defineProps<{
|
||
assistantId: number
|
||
businessDate: string
|
||
refreshKey: number
|
||
initialStatus?: DailyStatus
|
||
entryKey?: number
|
||
allowed: boolean
|
||
}>()
|
||
const emit = defineEmits<{
|
||
(event: 'open', patient: Patient): void
|
||
(event: 'date-change', date: string): void
|
||
(event: 'unavailable'): void
|
||
}>()
|
||
const data = ref<StaffDailyContacts | null>(null),
|
||
error = ref(''),
|
||
loading = ref(false),
|
||
page = ref(1),
|
||
status = ref<DailyStatus>(props.initialStatus || 'pending')
|
||
const statuses: Array<{ value: DailyStatus; label: string }> = [
|
||
{ value: 'pending', label: '待维护' },
|
||
{ value: 'reported', label: '人工登记待核实' },
|
||
{ value: 'contacted', label: '已联系' },
|
||
{ value: 'all', label: '全部' },
|
||
{ value: 'exempt', label: '已豁免' }
|
||
]
|
||
const statusLabels = {
|
||
pending: '待维护',
|
||
reported: '人工登记待核实',
|
||
contacted: '有联系记录',
|
||
exempt: '已豁免'
|
||
}
|
||
const emptyDescription = computed(() => {
|
||
if (error.value) return '名单读取失败,请重试'
|
||
if (
|
||
!data.value ||
|
||
data.value.daily.state !== 'ready' ||
|
||
data.value.summary.state === 'unavailable'
|
||
)
|
||
return '今日计划尚不可确认,请查看资料状态'
|
||
if (data.value.summary.state === 'no_tasks') return '今日暂无应维护患者'
|
||
return `当前筛选暂无患者${page.value > 1 ? ',可返回上一页查看' : ''}`
|
||
})
|
||
let disposed = false,
|
||
activated = true,
|
||
revision = 0
|
||
let request: AbortController | undefined
|
||
const visible = () =>
|
||
activated && (typeof document === 'undefined' || document.visibilityState !== 'hidden')
|
||
function clear() {
|
||
revision++
|
||
request?.abort()
|
||
data.value = null
|
||
error.value = ''
|
||
loading.value = false
|
||
}
|
||
async function load(silent = false) {
|
||
if (disposed || !visible() || !props.allowed || !props.businessDate) return
|
||
const token = ++revision,
|
||
assistantId = props.assistantId,
|
||
businessDate = props.businessDate
|
||
request?.abort()
|
||
request = new AbortController()
|
||
if (!silent) {
|
||
loading.value = true
|
||
data.value = null
|
||
}
|
||
error.value = ''
|
||
try {
|
||
const result = await assistantStaffDailyContacts(
|
||
{ assistant_id: assistantId, status: status.value, page_no: page.value, page_size: 10 },
|
||
request.signal
|
||
)
|
||
if (disposed || token !== revision || !props.allowed) return
|
||
if (
|
||
result.staff.id !== assistantId ||
|
||
result.daily.timezone !== 'Asia/Shanghai' ||
|
||
!/^\d{4}-\d{2}-\d{2}$/.test(result.daily.business_date)
|
||
)
|
||
throw new Error('名单与当前医助或业务日期不一致,请刷新后重试')
|
||
if (result.daily.business_date !== businessDate) {
|
||
data.value = null
|
||
if (result.daily.business_date > businessDate)
|
||
emit('date-change', result.daily.business_date)
|
||
else {
|
||
error.value = '已忽略旧业务日期的名单,请刷新后重试'
|
||
emit('unavailable')
|
||
}
|
||
return
|
||
}
|
||
data.value = result
|
||
} catch (cause) {
|
||
if (!disposed && token === revision && !isCancelled(cause)) {
|
||
data.value = null
|
||
error.value = errorText(cause)
|
||
emit('unavailable')
|
||
}
|
||
} finally {
|
||
if (!disposed && token === revision) loading.value = false
|
||
}
|
||
}
|
||
function setStatus(value: DailyStatus) {
|
||
if (value === status.value) return
|
||
status.value = value
|
||
page.value = 1
|
||
void load()
|
||
}
|
||
function openPatient(patient: DailyPatient, diagnosisId: number) {
|
||
if (
|
||
!props.allowed ||
|
||
!data.value?.lists.some(
|
||
(item) => item.key === patient.key && item.diagnosis_ids.includes(diagnosisId)
|
||
)
|
||
)
|
||
return
|
||
emit('open', {
|
||
diagnosis_id: diagnosisId,
|
||
patient_id: patient.patient_id,
|
||
patient_name: patient.patient_name,
|
||
assistant_id: props.assistantId
|
||
})
|
||
}
|
||
watch(
|
||
() => [props.assistantId, props.businessDate, props.allowed],
|
||
() => {
|
||
clear()
|
||
page.value = 1
|
||
void load()
|
||
},
|
||
{ immediate: true, flush: 'sync' }
|
||
)
|
||
watch(
|
||
() => props.entryKey,
|
||
() => {
|
||
status.value = props.initialStatus || 'pending'
|
||
page.value = 1
|
||
void load()
|
||
}
|
||
)
|
||
watch(
|
||
() => props.refreshKey,
|
||
() => void load(true)
|
||
)
|
||
function updateVisibility() {
|
||
if (!visible()) {
|
||
revision++
|
||
request?.abort()
|
||
loading.value = false
|
||
}
|
||
}
|
||
onMounted(() => {
|
||
if (typeof document !== 'undefined')
|
||
document.addEventListener('visibilitychange', updateVisibility)
|
||
updateVisibility()
|
||
})
|
||
onActivated(() => {
|
||
activated = true
|
||
})
|
||
onDeactivated(() => {
|
||
activated = false
|
||
updateVisibility()
|
||
})
|
||
onBeforeUnmount(() => {
|
||
disposed = true
|
||
clear()
|
||
if (typeof document !== 'undefined')
|
||
document.removeEventListener('visibilitychange', updateVisibility)
|
||
})
|
||
</script>
|
||
<style scoped>
|
||
.daily-heading {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: start;
|
||
gap: 16px;
|
||
margin-bottom: 16px;
|
||
}
|
||
h3 {
|
||
margin: 0;
|
||
font-size: 17px;
|
||
font-weight: 600;
|
||
}
|
||
h3 span,
|
||
small,
|
||
.muted,
|
||
.daily-heading p,
|
||
.daily-footer,
|
||
.coverage {
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary);
|
||
line-height: 1.7;
|
||
}
|
||
h3 span {
|
||
display: block;
|
||
margin-top: 5px;
|
||
font-weight: 400;
|
||
}
|
||
.daily-heading p {
|
||
margin: 5px 0 0;
|
||
}
|
||
.daily-counts {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 12px 24px;
|
||
padding: 18px 0;
|
||
font-size: 13px;
|
||
}
|
||
.daily-counts b {
|
||
margin-left: 6px;
|
||
font-size: 21px;
|
||
font-weight: 600;
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
.status-filter {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 5px;
|
||
border-bottom: 1px solid var(--el-border-color-light);
|
||
padding-bottom: 12px;
|
||
}
|
||
.status-filter button {
|
||
border: 0;
|
||
background: var(--el-fill-color-light);
|
||
padding: 8px 12px;
|
||
border-radius: 3px;
|
||
cursor: pointer;
|
||
color: var(--el-text-color-regular);
|
||
transition:
|
||
background-color 0.18s,
|
||
color 0.18s;
|
||
}
|
||
.status-filter button.active,
|
||
.status-filter button:hover {
|
||
background: var(--el-color-primary-light-9);
|
||
color: var(--el-color-primary);
|
||
}
|
||
.status-filter button:focus-visible,
|
||
summary:focus-visible {
|
||
outline: 2px solid var(--el-color-primary);
|
||
outline-offset: 3px;
|
||
}
|
||
.patient-list {
|
||
padding: 0;
|
||
margin: 0;
|
||
list-style: none;
|
||
}
|
||
.patient-row {
|
||
display: grid;
|
||
grid-template-columns: minmax(100px, 0.8fr) minmax(140px, 1.4fr) minmax(130px, 1.2fr) 84px;
|
||
gap: 20px;
|
||
padding: 20px 0;
|
||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||
font-size: 13px;
|
||
overflow-wrap: anywhere;
|
||
}
|
||
.patient-row strong {
|
||
font-weight: 500;
|
||
}
|
||
.patient-row small,
|
||
.record-links .el-button {
|
||
display: block;
|
||
margin: 4px 0 0;
|
||
}
|
||
.patient-reasons p {
|
||
margin: 0 0 8px;
|
||
}
|
||
.patient-reasons p:last-child {
|
||
margin-bottom: 0;
|
||
}
|
||
.attention {
|
||
color: var(--el-color-primary);
|
||
}
|
||
.completion-note {
|
||
background: var(--el-fill-color-light);
|
||
padding: 12px;
|
||
font-size: 13px;
|
||
line-height: 1.7;
|
||
}
|
||
.daily-footer {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 10px;
|
||
justify-content: space-between;
|
||
margin-top: 16px;
|
||
}
|
||
.daily-footer p {
|
||
max-width: 48ch;
|
||
margin: 0;
|
||
}
|
||
.coverage {
|
||
margin-top: 20px;
|
||
}
|
||
.coverage summary {
|
||
cursor: pointer;
|
||
}
|
||
@media (max-width: 700px) {
|
||
.patient-row {
|
||
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
||
gap: 12px 18px;
|
||
}
|
||
.patient-reasons {
|
||
grid-column: 1;
|
||
grid-row: 2;
|
||
}
|
||
.patient-state {
|
||
grid-column: 2;
|
||
grid-row: 1 / span 2;
|
||
}
|
||
.record-links {
|
||
grid-column: 1 / -1;
|
||
display: flex;
|
||
gap: 14px;
|
||
flex-wrap: wrap;
|
||
}
|
||
.daily-counts {
|
||
gap: 10px 18px;
|
||
}
|
||
}
|
||
</style>
|