146 lines
4.1 KiB
Vue
146 lines
4.1 KiB
Vue
<template>
|
|
<el-card shadow="never" class="patient-picker">
|
|
<template #header
|
|
><strong>授权患者</strong><span class="count">{{ total }} 位</span></template
|
|
>
|
|
<el-input
|
|
v-model="keyword"
|
|
clearable
|
|
placeholder="搜索患者姓名 / 手机号"
|
|
aria-label="搜索授权患者"
|
|
@keyup.enter="search"
|
|
@clear="search"
|
|
>
|
|
<template #append
|
|
><el-button :loading="loading" @click="search">搜索</el-button></template
|
|
>
|
|
</el-input>
|
|
<el-alert
|
|
v-if="error"
|
|
class="mt-3"
|
|
:title="error"
|
|
type="error"
|
|
:closable="false"
|
|
show-icon
|
|
/>
|
|
<el-button v-if="error" link type="primary" @click="load">重新加载</el-button>
|
|
<div v-loading="loading" class="patient-list">
|
|
<button
|
|
v-for="patient in rows"
|
|
:key="patient.diagnosis_id"
|
|
type="button"
|
|
class="patient-row"
|
|
:class="{ selected: selectedId === patient.diagnosis_id }"
|
|
:aria-pressed="selectedId === patient.diagnosis_id"
|
|
@click="$emit('select', patient)"
|
|
>
|
|
<strong>{{ patient.patient_name || '未命名患者' }}</strong>
|
|
<span>{{ patient.phone_masked || '未提供手机号' }}</span>
|
|
<small>诊单 #{{ patient.diagnosis_id }}</small>
|
|
</button>
|
|
<el-empty
|
|
v-if="!loading && !rows.length && !error"
|
|
description="当前范围内暂无匹配患者"
|
|
:image-size="70"
|
|
/>
|
|
</div>
|
|
<el-pagination
|
|
v-if="total"
|
|
v-model:current-page="page"
|
|
small
|
|
layout="prev, pager, next"
|
|
:pager-count="5"
|
|
:total="total"
|
|
:page-size="10"
|
|
@current-change="load"
|
|
/>
|
|
</el-card>
|
|
</template>
|
|
<script setup lang="ts">
|
|
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
|
import { assistantPatients, type Patient } from '@/api/assistantService'
|
|
import { errorText, isCancelled } from '../shared'
|
|
defineProps<{ selectedId: number }>()
|
|
defineEmits<{ (event: 'select', patient: Patient): void }>()
|
|
const keyword = ref(''),
|
|
page = ref(1),
|
|
total = ref(0),
|
|
rows = ref<Patient[]>([]),
|
|
loading = ref(false),
|
|
error = ref('')
|
|
let revision = 0,
|
|
request: AbortController | undefined
|
|
async function load() {
|
|
const token = ++revision
|
|
request?.abort()
|
|
request = new AbortController()
|
|
loading.value = true
|
|
error.value = ''
|
|
try {
|
|
const data = await assistantPatients(
|
|
{ keyword: keyword.value.trim(), page_no: page.value, page_size: 10 },
|
|
request.signal
|
|
)
|
|
if (token !== revision) return
|
|
rows.value = data.lists
|
|
total.value = data.count
|
|
} catch (cause) {
|
|
if (token !== revision || isCancelled(cause)) return
|
|
rows.value = []
|
|
total.value = 0
|
|
error.value = errorText(cause)
|
|
} finally {
|
|
if (token === revision) loading.value = false
|
|
}
|
|
}
|
|
function search() {
|
|
page.value = 1
|
|
void load()
|
|
}
|
|
onMounted(load)
|
|
onBeforeUnmount(() => {
|
|
revision++
|
|
request?.abort()
|
|
})
|
|
</script>
|
|
<style scoped>
|
|
.patient-picker {
|
|
height: fit-content;
|
|
min-width: 0;
|
|
}
|
|
.count {
|
|
float: right;
|
|
color: var(--el-text-color-secondary);
|
|
font-size: 13px;
|
|
}
|
|
.patient-list {
|
|
min-height: 180px;
|
|
margin: 14px -8px;
|
|
}
|
|
.patient-row {
|
|
width: 100%;
|
|
text-align: left;
|
|
display: grid;
|
|
gap: 5px;
|
|
padding: 12px;
|
|
background: transparent;
|
|
border: 1px solid transparent;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
color: var(--el-text-color-primary);
|
|
}
|
|
.patient-row + .patient-row {
|
|
border-top-color: var(--el-border-color-lighter);
|
|
}
|
|
.patient-row:hover,
|
|
.patient-row.selected {
|
|
background: var(--el-color-primary-light-9);
|
|
border-color: var(--el-color-primary-light-7);
|
|
}
|
|
.patient-row span,
|
|
.patient-row small {
|
|
color: var(--el-text-color-secondary);
|
|
font-size: 12px;
|
|
}
|
|
</style>
|