403 lines
12 KiB
Vue
403 lines
12 KiB
Vue
<!-- 输注计划管理 — 出库交接 -->
|
|
<!-- eslint-disable vue/no-v-model-argument -->
|
|
<template>
|
|
<el-dialog
|
|
:model-value="modelValue"
|
|
title="出库交接"
|
|
width="1120px"
|
|
class="dialog-form-layout outbound-handover-dialog"
|
|
align-center
|
|
destroy-on-close
|
|
:close-on-click-modal="false"
|
|
style="backdrop-filter: none"
|
|
@update:model-value="emit('update:modelValue', $event)"
|
|
@closed="handleClosed"
|
|
>
|
|
<div v-if="scheduleSummary" class="material-summary">
|
|
<div class="material-summary-row">
|
|
<span class="material-summary-label">申请单号</span>
|
|
<span class="material-summary-value">{{ scheduleSummary.applicationNo || '—' }}</span>
|
|
</div>
|
|
<div class="material-summary-row">
|
|
<span class="material-summary-label">患者姓名</span>
|
|
<span class="material-summary-value">{{ scheduleSummary.patientName || '—' }}</span>
|
|
</div>
|
|
<div class="material-summary-row">
|
|
<span class="material-summary-label">输注时间</span>
|
|
<span class="material-summary-value">{{ scheduleSummary.infusionTime || '—' }}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-loading="loading" class="handover-body">
|
|
<OutboundMaterialFormSections ref="materialSectionsRef" require-frozen-cell-product />
|
|
|
|
<section class="section-card handover-form-section">
|
|
<h3 class="section-title section-title--mint-bar">交接信息</h3>
|
|
<el-form label-position="top" class="biz-dialog-form">
|
|
<div class="form-grid-2">
|
|
<el-form-item label="交接人" required>
|
|
<el-select
|
|
v-model="handoverUserId"
|
|
filterable
|
|
remote
|
|
clearable
|
|
reserve-keyword
|
|
placeholder="搜索并选择用户"
|
|
:remote-method="remoteSearchHandoverUsers"
|
|
:loading="handoverUserLoading"
|
|
class="w-full"
|
|
@change="onHandoverUserChange"
|
|
>
|
|
<el-option
|
|
v-for="u in handoverUserOptions"
|
|
:key="u.id"
|
|
:label="formatHandoverUserLabel(u)"
|
|
:value="u.id"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="交接时间" required>
|
|
<el-date-picker
|
|
v-model="handoverTime"
|
|
type="datetime"
|
|
value-format="YYYY-MM-DD HH:mm:ss"
|
|
format="YYYY-MM-DD HH:mm:ss"
|
|
placeholder="选择交接时间"
|
|
style="width: 100%"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="交接地点">
|
|
<el-input
|
|
v-model="handoverLocation"
|
|
placeholder="可选"
|
|
maxlength="200"
|
|
clearable
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="接收人" required>
|
|
<el-input
|
|
v-model="receiverPerson"
|
|
placeholder="请输入接收人"
|
|
maxlength="200"
|
|
clearable
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="备注" class="form-col-span-2">
|
|
<el-input
|
|
v-model="handoverRemark"
|
|
type="textarea"
|
|
:rows="2"
|
|
placeholder="可选"
|
|
maxlength="512"
|
|
show-word-limit
|
|
/>
|
|
</el-form-item>
|
|
</div>
|
|
</el-form>
|
|
</section>
|
|
</div>
|
|
|
|
<template #footer>
|
|
<el-button class="btn-ghost" @click="emit('update:modelValue', false)">
|
|
<el-icon><Close /></el-icon>
|
|
取消
|
|
</el-button>
|
|
<el-button class="btn-main" type="primary" :loading="submitting" @click="handleSubmit">
|
|
<el-icon><Check /></el-icon>
|
|
保存
|
|
</el-button>
|
|
</template>
|
|
</el-dialog>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ElMessage } from 'element-plus'
|
|
import { Check, Close } from '@element-plus/icons-vue'
|
|
import { fetchUserList } from '@/api/admin'
|
|
import {
|
|
fetchInfusionScheduleOutboundHandover,
|
|
saveInfusionScheduleOutboundHandover
|
|
} from '@/api/infusion-schedule-handover'
|
|
import OutboundMaterialFormSections from '@/components/business/outbound-material-form-sections/index.vue'
|
|
import { useUserStore } from '@/store/modules/user'
|
|
|
|
defineOptions({ name: 'InfusionScheduleHandoverDialog' })
|
|
|
|
const props = defineProps<{
|
|
modelValue: boolean
|
|
scheduleId: string
|
|
scheduleRow?: Record<string, any> | null
|
|
}>()
|
|
|
|
const emit = defineEmits<{
|
|
(e: 'update:modelValue', val: boolean): void
|
|
(e: 'saved'): void
|
|
}>()
|
|
|
|
const userStore = useUserStore()
|
|
const materialSectionsRef = ref<InstanceType<typeof OutboundMaterialFormSections> | null>(null)
|
|
|
|
const loading = ref(false)
|
|
const submitting = ref(false)
|
|
const scheduleSummary = ref<{
|
|
applicationNo?: string
|
|
patientName?: string
|
|
infusionTime?: string
|
|
} | null>(null)
|
|
|
|
const handoverUserId = ref('')
|
|
const handoverTime = ref('')
|
|
const handoverLocation = ref('')
|
|
const receiverPerson = ref('')
|
|
const handoverRemark = ref('')
|
|
|
|
const handoverUserOptions = ref<Api.User.UserItem[]>([])
|
|
const handoverSelectedSnapshot = ref<Api.User.UserItem | null>(null)
|
|
const handoverUserLoading = ref(false)
|
|
|
|
function formatNowDatetime() {
|
|
const d = new Date()
|
|
const pad = (n: number) => String(n).padStart(2, '0')
|
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
|
}
|
|
|
|
function formatHandoverUserLabel(u: Api.User.UserItem) {
|
|
const name = (u.nickName || '').trim() || '-'
|
|
const no = (u.userNo || '').trim()
|
|
const phone = (u.phoneNo || '').trim()
|
|
const parts = [name]
|
|
if (no) parts.push(no)
|
|
if (phone) parts.push(phone)
|
|
return parts.join(' · ')
|
|
}
|
|
|
|
function applyDefaultHandoverUser() {
|
|
const info = (userStore.info || {}) as Record<string, any>
|
|
const uid = String(info.userId ?? info.id ?? '').trim()
|
|
const nick = String(
|
|
info.nickName ?? info.realName ?? info.userName ?? info.username ?? ''
|
|
).trim()
|
|
if (!uid) return
|
|
handoverUserId.value = uid
|
|
handoverSelectedSnapshot.value = {
|
|
id: uid,
|
|
nickName: nick || uid,
|
|
userNo: info.userName || info.username || '',
|
|
phoneNo: info.phone || info.phoneNo || ''
|
|
} as Api.User.UserItem
|
|
handoverUserOptions.value = handoverSelectedSnapshot.value
|
|
? [handoverSelectedSnapshot.value]
|
|
: []
|
|
}
|
|
|
|
function resetHandoverForm() {
|
|
handoverUserId.value = ''
|
|
handoverTime.value = formatNowDatetime()
|
|
handoverLocation.value = ''
|
|
receiverPerson.value = ''
|
|
handoverRemark.value = ''
|
|
handoverUserOptions.value = []
|
|
handoverSelectedSnapshot.value = null
|
|
}
|
|
|
|
async function remoteSearchHandoverUsers(query: string) {
|
|
handoverUserLoading.value = true
|
|
try {
|
|
const q = (query || '').trim()
|
|
const res = await fetchUserList({
|
|
page: 1,
|
|
pageSize: 50,
|
|
keyword: q || undefined,
|
|
status: '1'
|
|
})
|
|
let list = [...(res.list || [])]
|
|
const curId = handoverUserId.value
|
|
if (
|
|
curId &&
|
|
handoverSelectedSnapshot.value?.id === curId &&
|
|
!list.some((x) => x.id === curId)
|
|
) {
|
|
list = [handoverSelectedSnapshot.value, ...list]
|
|
}
|
|
handoverUserOptions.value = list
|
|
} catch {
|
|
handoverUserOptions.value = handoverSelectedSnapshot.value
|
|
? [handoverSelectedSnapshot.value]
|
|
: []
|
|
} finally {
|
|
handoverUserLoading.value = false
|
|
}
|
|
}
|
|
|
|
function onHandoverUserChange(val: string | null | undefined) {
|
|
if (!val) {
|
|
handoverUserId.value = ''
|
|
handoverSelectedSnapshot.value = null
|
|
handoverUserOptions.value = []
|
|
return
|
|
}
|
|
const hit = handoverUserOptions.value.find((u) => u.id === val)
|
|
if (hit) handoverSelectedSnapshot.value = hit
|
|
}
|
|
|
|
function fillHandoverFromApi(handover?: {
|
|
handoverUserId?: string
|
|
handoverPerson?: string
|
|
handoverTime?: string
|
|
handoverLocation?: string
|
|
receiverPerson?: string
|
|
remark?: string
|
|
}) {
|
|
const hasRecord = !!(handover?.handoverUserId || handover?.handoverTime || handover?.receiverPerson)
|
|
if (!hasRecord) {
|
|
resetHandoverForm()
|
|
applyDefaultHandoverUser()
|
|
return
|
|
}
|
|
handoverUserId.value = handover?.handoverUserId || ''
|
|
handoverTime.value = handover?.handoverTime || formatNowDatetime()
|
|
handoverLocation.value = handover?.handoverLocation || ''
|
|
receiverPerson.value = handover?.receiverPerson || ''
|
|
handoverRemark.value = handover?.remark || ''
|
|
if (handoverUserId.value) {
|
|
handoverSelectedSnapshot.value = {
|
|
id: handoverUserId.value,
|
|
nickName: handover?.handoverPerson || handoverUserId.value,
|
|
userNo: '',
|
|
phoneNo: ''
|
|
} as Api.User.UserItem
|
|
handoverUserOptions.value = [handoverSelectedSnapshot.value]
|
|
}
|
|
}
|
|
|
|
async function loadData() {
|
|
if (!props.scheduleId) return
|
|
loading.value = true
|
|
try {
|
|
const data = await fetchInfusionScheduleOutboundHandover(props.scheduleId)
|
|
scheduleSummary.value = data.scheduleSummary || {
|
|
applicationNo: props.scheduleRow?.applicationNo,
|
|
patientName: props.scheduleRow?.patientName,
|
|
infusionTime: props.scheduleRow?.infusionTime
|
|
}
|
|
await materialSectionsRef.value?.ensureMaterialOptions()
|
|
await materialSectionsRef.value?.loadFromApiData({
|
|
remark: data.outboundMaterial?.remark,
|
|
cells: data.outboundMaterial?.cells as any,
|
|
qcMaterials: data.outboundMaterial?.qcMaterials,
|
|
paperMaterials: data.outboundMaterial?.paperMaterials
|
|
})
|
|
fillHandoverFromApi(data.handover)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
watch(
|
|
() => [props.modelValue, props.scheduleId] as const,
|
|
([vis, id]) => {
|
|
if (vis && id) {
|
|
nextTick(() => loadData())
|
|
}
|
|
},
|
|
{ immediate: true }
|
|
)
|
|
|
|
function handleClosed() {
|
|
materialSectionsRef.value?.resetState()
|
|
scheduleSummary.value = null
|
|
resetHandoverForm()
|
|
}
|
|
|
|
async function handleSubmit() {
|
|
if (!props.scheduleId) return
|
|
const sections = materialSectionsRef.value
|
|
if (!sections?.validateMaterial()) return
|
|
|
|
if (!handoverUserId.value?.trim()) {
|
|
ElMessage.warning('请选择交接人')
|
|
return
|
|
}
|
|
if (!handoverTime.value?.trim()) {
|
|
ElMessage.warning('请选择交接时间')
|
|
return
|
|
}
|
|
if (!receiverPerson.value?.trim()) {
|
|
ElMessage.warning('请填写接收人')
|
|
return
|
|
}
|
|
|
|
submitting.value = true
|
|
try {
|
|
await saveInfusionScheduleOutboundHandover(props.scheduleId, {
|
|
outboundMaterial: sections.buildSavePayload(),
|
|
handover: {
|
|
handoverUserId: handoverUserId.value.trim(),
|
|
handoverTime: handoverTime.value.trim(),
|
|
handoverLocation: handoverLocation.value.trim() || undefined,
|
|
receiverPerson: receiverPerson.value.trim(),
|
|
remark: handoverRemark.value.trim() || undefined
|
|
}
|
|
})
|
|
ElMessage.success('出库交接已保存')
|
|
emit('update:modelValue', false)
|
|
emit('saved')
|
|
} finally {
|
|
submitting.value = false
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.material-summary {
|
|
margin-bottom: 16px;
|
|
padding: 12px 16px;
|
|
background: #f8fafc;
|
|
border-radius: 8px;
|
|
border: 1px solid #e2e8f0;
|
|
display: grid;
|
|
grid-template-columns: repeat(3, 1fr);
|
|
gap: 8px 20px;
|
|
}
|
|
|
|
.material-summary-row {
|
|
display: flex;
|
|
gap: 8px;
|
|
font-size: 13px;
|
|
}
|
|
|
|
.material-summary-label {
|
|
color: #64748b;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.material-summary-value {
|
|
color: #1e293b;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.handover-body {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 20px;
|
|
}
|
|
|
|
.section-card {
|
|
border: 1px solid #e2e8f0;
|
|
border-radius: 8px;
|
|
padding: 12px 16px 16px;
|
|
background: #fff;
|
|
}
|
|
|
|
.section-title {
|
|
margin: 0 0 12px;
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
color: #1e293b;
|
|
}
|
|
|
|
.handover-form-section :deep(.el-form-item) {
|
|
margin-bottom: 0;
|
|
}
|
|
</style>
|