Files
zkxw/web-admin/src/views/pilot-service/infusion-schedule-management/InfusionScheduleHandoverDialog.vue
T
zlwuandCursor f3672d3cc2 feat(production): 临床科研出库细胞改由生产确认
市场出库交接对 basic_experiment 保留细胞只读并不改库存;生产工单新增确认出库细胞 API/弹窗,从细胞产品库勾选并联动已售状态。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-20 17:03:45 +08:00

840 lines
24 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- 输注计划管理 — 出库交接 -->
<!-- eslint-disable vue/no-v-model-argument vue/no-multiple-template-root -->
<template>
<el-dialog
:model-value="modelValue"
title="出库交接"
width="1280px"
class="dialog-form-layout outbound-handover-dialog"
align-center
append-to-body
modal-class="protocol-dialog-mask"
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">{{ pickupTimeLabel }}</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
:cells-readonly="isBasicExperiment"
/>
<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-3">
<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="细胞用途">
<el-input
v-model="cellPurpose"
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>
<el-form-item label="附件" class="form-col-span-2">
<div
class="attachment-upload"
:class="{ 'is-dragover': isHandoverAttachDragover }"
v-bind="handoverAttachDropHandlers"
>
<div class="attachment-list">
<el-upload
ref="attachmentUploadRef"
:auto-upload="false"
:show-file-list="false"
:multiple="true"
accept="image/*,video/*,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.zip,.rar"
@change="handleAttachmentChange"
>
<div class="upload-card">
<el-icon :size="28" color="#047857"><Plus /></el-icon>
<span class="upload-card-text">上传附件</span>
</div>
</el-upload>
<div
v-for="(file, fIdx) in attachmentFiles"
:key="file.id || fIdx"
class="attachment-item"
:class="{ 'is-uploading': file._uploading }"
>
<div
class="attachment-preview"
@click="
isImageFile(file) && file.fileUrl ? handlePreviewAttachment(file) : undefined
"
>
<template v-if="isImageFile(file) && file.fileUrl">
<img :src="fullFileUrl(file.fileUrl)" :alt="file.fileName" />
</template>
<template v-else-if="isImageFile(file) && !file.fileUrl">
<el-icon :size="24" color="#94a3b8"><Loading /></el-icon>
</template>
<template v-else-if="isVideoFile(file)">
<div class="attachment-preview__icon attachment-preview__icon--video">
<el-icon :size="28"><VideoPlay /></el-icon>
</div>
</template>
<template v-else>
<div class="attachment-preview__icon attachment-preview__icon--doc">
<el-icon :size="28"><Document /></el-icon>
</div>
</template>
</div>
<div class="attachment-footer">
<span class="attachment-name" :title="file.fileName">{{ file.fileName }}</span>
<div class="attachment-actions">
<el-icon
class="action-btn"
title="下载"
@click.stop="handleDownloadAttachment(file)"
>
<Download />
</el-icon>
<el-icon
class="action-btn action-btn--danger"
title="删除"
@click.stop="removeAttachment(fIdx)"
>
<Delete />
</el-icon>
</div>
</div>
</div>
</div>
<span class="upload-hint"
>支持拖拽或点击上传图片、视频、PDF、Word、Excel 等文件,单文件不超过 20MB</span
>
</div>
</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>
<el-dialog
v-model="previewVisible"
title="文件预览"
width="800px"
align-center
destroy-on-close
append-to-body
style="backdrop-filter: none"
>
<div v-if="previewType === 'image'" class="preview-container">
<img
:src="previewUrl"
alt="预览"
style="max-width: 100%; max-height: 70vh; display: block; margin: 0 auto"
/>
</div>
<div v-else class="preview-container">
<video
:src="previewUrl"
controls
style="max-width: 100%; max-height: 70vh; display: block; margin: 0 auto"
/>
</div>
</el-dialog>
</template>
<script setup lang="ts">
import { ElMessage } from 'element-plus'
import {
Check,
Close,
Plus,
Document,
Delete,
Download,
Loading,
VideoPlay
} from '@element-plus/icons-vue'
import { fetchUserList } from '@/api/admin'
import { fetchUploadAttachment } from '@/api/business'
import { useAttachmentDropZone } from '@/composables/useAttachmentDropZone'
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'
import { downloadAttachmentFile } from '@/utils/download-attachment'
import { getPilotBizConfig, resolvePilotBizType } from '@/config/pilot-biz-type'
type AttachmentItem = {
id: string
fileName: string
fileUrl: string
fileType: string
_uploading?: boolean
}
defineOptions({ name: 'InfusionScheduleHandoverDialog' })
const props = defineProps<{
modelValue: boolean
scheduleId: string
scheduleRow?: Record<string, any> | null
bizType?: string
}>()
const pickupTimeLabel = computed(
() => getPilotBizConfig(resolvePilotBizType(props.bizType)).pickupTimeLabel
)
const isBasicExperiment = computed(
() => resolvePilotBizType(props.bizType) === 'basic_experiment'
)
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 cellPurpose = ref('')
const handoverRemark = ref('')
const attachmentUploadRef = ref()
const attachmentFiles = ref<AttachmentItem[]>([])
const previewVisible = ref(false)
const previewUrl = ref('')
const previewType = ref<'image' | 'video'>('image')
const minioBaseUrl = (import.meta.env.VITE_MINIO_BASE_URL || '').replace(/\/$/, '')
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 = ''
cellPurpose.value = ''
handoverRemark.value = ''
attachmentFiles.value = []
previewVisible.value = false
handoverUserOptions.value = []
handoverSelectedSnapshot.value = null
}
function fullFileUrl(url: string) {
if (!url) return ''
if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('/')) {
return url
}
return minioBaseUrl ? `${minioBaseUrl}/${url.replace(/^\//, '')}` : url
}
function isImageFile(file: AttachmentItem) {
const url = (file.fileUrl || '').toLowerCase()
const name = (file.fileName || '').toLowerCase()
return (
/\.(jpg|jpeg|png|gif|bmp|webp|svg)(\?|$)/.test(url) ||
/\.(jpg|jpeg|png|gif|bmp|webp|svg)$/.test(name) ||
(file.fileType || '').startsWith('image/')
)
}
function isVideoFile(file: AttachmentItem) {
const url = (file.fileUrl || '').toLowerCase()
const name = (file.fileName || '').toLowerCase()
return (
/\.(mp4|webm|ogg|mov|avi)(\?|$)/.test(url) ||
/\.(mp4|webm|ogg|mov|avi)$/.test(name) ||
(file.fileType || '').startsWith('video/')
)
}
function parseAttachmentUrls(urls: string): AttachmentItem[] {
if (!urls?.trim()) return []
return urls
.split(',')
.map((u) => u.trim())
.filter(Boolean)
.map((fileUrl, i) => ({
id: `att_${i}`,
fileUrl,
fileName: fileUrl.split('/').pop() || '',
fileType: ''
}))
}
function removeAttachment(index: number) {
attachmentFiles.value.splice(index, 1)
}
function handlePreviewAttachment(file: AttachmentItem) {
if (file._uploading || !file.fileUrl) return
previewUrl.value = fullFileUrl(file.fileUrl)
previewType.value = isVideoFile(file) ? 'video' : 'image'
previewVisible.value = true
}
function handleDownloadAttachment(file: AttachmentItem) {
if (file._uploading || !file.fileUrl) return
downloadAttachmentFile(file, { fullFileUrl })
}
async function handleAttachmentChange(uploadFile: { raw?: File }) {
const file = uploadFile.raw
if (!file) return
const tempId = `temp_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`
attachmentFiles.value.push({
id: tempId,
fileName: file.name,
fileUrl: '',
fileType: file.type || '',
_uploading: true
})
const idx = attachmentFiles.value.length - 1
try {
const fd = new FormData()
fd.append('folder', 'outbound-handover')
fd.append('file', file)
const res = await fetchUploadAttachment(fd)
attachmentFiles.value[idx] = {
...attachmentFiles.value[idx],
id: res.id || tempId,
fileName: file.name || res.fileName,
fileUrl: res.fileUrl,
fileType: res.fileType || file.type || '',
_uploading: false
}
} catch {
ElMessage.error('文件上传失败')
attachmentFiles.value.splice(idx, 1)
} finally {
nextTick(() => attachmentUploadRef.value?.clearFiles())
}
}
const { isDragover: isHandoverAttachDragover, dropZoneHandlers: handoverAttachDropHandlers } =
useAttachmentDropZone({
onFiles: (files) => {
for (const file of files) {
void handleAttachmentChange({ raw: file })
}
}
})
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
cellPurpose?: string
attachments?: 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 || ''
cellPurpose.value = handover?.cellPurpose || ''
handoverRemark.value = handover?.remark || ''
attachmentFiles.value = parseAttachmentUrls(handover?.attachments || '')
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?.remoteSearchMaterials('')
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
}
if (attachmentFiles.value.some((f) => f._uploading)) {
ElMessage.warning('附件上传中,请稍候')
return
}
const attachmentUrls = attachmentFiles.value
.filter((f) => f.fileUrl && !f._uploading)
.map((f) => f.fileUrl)
.join(',')
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(),
cellPurpose: cellPurpose.value.trim() || undefined,
attachments: attachmentUrls || undefined,
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: var(--mint-text-muted, #334155);
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;
}
/* 附件上传卡片化布局 */
.attachment-upload {
width: 100%;
}
.attachment-list {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.upload-card {
width: 140px;
height: 96px;
border: 1px dashed #a8d4c4;
border-radius: 8px;
background: #f0fdf4;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 6px;
cursor: pointer;
transition:
border-color 0.15s,
background 0.15s;
&:hover {
border-color: #047857;
border-style: solid;
background: #e8f4ee;
}
}
.upload-card-text {
font-size: 12px;
color: #047857;
font-weight: 500;
line-height: 1;
}
.upload-hint {
display: block;
font-size: 11px;
color: var(--mint-text-muted, #334155);
line-height: 1;
margin-top: 8px;
}
.attachment-item {
width: 140px;
display: flex;
flex-direction: column;
border: 1px solid #e2e8f0;
border-radius: 8px;
background: #fff;
overflow: hidden;
transition:
border-color 0.15s,
box-shadow 0.15s;
&:hover {
border-color: #047857;
box-shadow: 0 2px 8px rgba(4, 120, 87, 0.1);
}
&.is-uploading {
opacity: 0.6;
pointer-events: none;
}
}
.attachment-preview {
width: 100%;
height: 96px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
background: #f8fafc;
overflow: hidden;
cursor: pointer;
img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
}
.attachment-preview__icon {
width: 48px;
height: 48px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
&--video {
background: #ede9fe;
color: #7c3aed;
}
&--doc {
background: #e0f2fe;
color: #0284c7;
}
}
.attachment-footer {
display: flex;
flex-direction: column;
flex: 1;
padding: 6px 8px;
}
.attachment-name {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
font-size: 11px;
color: #334155;
line-height: 1.4;
word-break: break-all;
min-height: calc(11px * 1.4 * 2);
}
.attachment-actions {
display: flex;
justify-content: center;
align-items: center;
gap: 8px;
margin-top: 4px;
flex-shrink: 0;
}
.action-btn {
width: 22px;
height: 22px;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
color: var(--mint-text-muted, #334155);
cursor: pointer;
background: #f1f5f9;
transition:
background 0.15s,
color 0.15s;
&:hover {
background: #e2e8f0;
color: #334155;
}
&--danger:hover {
background: #fee2e2;
color: #dc2626;
}
}
</style>