442 lines
16 KiB
Vue
442 lines
16 KiB
Vue
<!-- 出库质检工单 — 查看详情弹窗 -->
|
||
<!-- eslint-disable vue/no-v-model-argument -->
|
||
<template>
|
||
<SystemViewDialog
|
||
v-model:visible="dialogVisible"
|
||
title="出库质检工单详情"
|
||
width="1200px"
|
||
:grid-columns="4"
|
||
compact
|
||
:loading="loading"
|
||
:icon="Document"
|
||
:meta="detail?.workOrder?.workOrderNo || ''"
|
||
:sections="sections"
|
||
>
|
||
<template #diagnosis-attachments>
|
||
<ProtocolAttachmentReadonly
|
||
:files="diagnosisAttachmentFiles"
|
||
@preview="handlePreview"
|
||
@download="handleDownload"
|
||
/>
|
||
</template>
|
||
<template v-for="task in tasksWithAttachments" #[taskAttachmentSlotName(task.id)]>
|
||
<div :key="task.id" class="outbound-qc-task-attachments">
|
||
<ProtocolAttachmentReadonly
|
||
:files="task.attachmentFiles || []"
|
||
@preview="handleTaskPreview"
|
||
@download="handleTaskDownload"
|
||
/>
|
||
</div>
|
||
</template>
|
||
</SystemViewDialog>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, computed, watch } from 'vue'
|
||
import { Document } from '@element-plus/icons-vue'
|
||
import {
|
||
fetchOutboundQcDetail,
|
||
type OutboundQcDetail,
|
||
type QcWorkOrderDetail
|
||
} from '@/api/qc-work-order'
|
||
import { fetchQcTaskResults, type QcTaskResultItem } from '@/api/qc-task-result'
|
||
import {
|
||
workOrderStatusLabel,
|
||
taskStatusLabel,
|
||
qcTaskConclusionLabel
|
||
} from '@/utils/qc-labels'
|
||
import {
|
||
scheduleStatusLabel,
|
||
scheduleStatusTagType,
|
||
infusionStatusLabel,
|
||
infusionStatusTagType,
|
||
qcStatusLabel,
|
||
qcStatusTagType,
|
||
applicationStatusLabel,
|
||
applicationStatusTagType,
|
||
bizTypeLabel,
|
||
bizTypeTagType,
|
||
productStatusLabel,
|
||
productStatusTagType
|
||
} from '@/utils/status-tag-registry'
|
||
import SystemViewDialog from '@/components/business/system-view-dialog/index.vue'
|
||
import type { ViewField, ViewSection } from '@/components/business/system-view-dialog/index.vue'
|
||
import ProtocolAttachmentReadonly from '@/views/cell-storage/protocol/ProtocolAttachmentReadonly.vue'
|
||
import { downloadAttachmentFile } from '@/utils/download-attachment'
|
||
import { formatMoneyDisplay } from '@/utils/money-format'
|
||
|
||
defineOptions({ name: 'OutboundQcViewDialog' })
|
||
|
||
const props = defineProps<{
|
||
visible: boolean
|
||
workOrderId: string
|
||
}>()
|
||
|
||
const emit = defineEmits<{
|
||
(e: 'update:visible', v: boolean): void
|
||
}>()
|
||
|
||
const dialogVisible = computed({
|
||
get: () => props.visible,
|
||
set: (v) => emit('update:visible', v)
|
||
})
|
||
|
||
const loading = ref(false)
|
||
const detail = ref<OutboundQcDetail | null>(null)
|
||
|
||
type TaskView = {
|
||
id: string
|
||
taskNo: string
|
||
taskType: string
|
||
itemCode?: string
|
||
itemName?: string
|
||
taskStatus: string
|
||
conclusion?: string
|
||
conclusionLabel?: string
|
||
remark?: string
|
||
completedTime?: string
|
||
attachmentFiles?: Array<{ id?: string; fileUrl?: string; fileName?: string }>
|
||
results?: QcTaskResultItem[]
|
||
companyName?: string
|
||
feeAmount?: number
|
||
}
|
||
|
||
const tasksWithResults = ref<TaskView[]>([])
|
||
|
||
const minioBaseUrl = (import.meta.env.VITE_MINIO_BASE_URL || '').replace(/\/$/, '')
|
||
|
||
watch(
|
||
() => props.visible,
|
||
async (v) => {
|
||
if (!v || !props.workOrderId) return
|
||
loading.value = true
|
||
tasksWithResults.value = []
|
||
try {
|
||
const d = await fetchOutboundQcDetail(props.workOrderId)
|
||
detail.value = d
|
||
const rawTasks = (d.workOrder?.tasks || d.tasks || []) as TaskView[]
|
||
const enriched = await Promise.all(
|
||
rawTasks.map(async (task) => {
|
||
if (task.taskType !== 'sysz' || task.taskStatus !== 'ywc') {
|
||
return { ...task, results: [] as QcTaskResultItem[] }
|
||
}
|
||
try {
|
||
const results = await fetchQcTaskResults(task.id)
|
||
return { ...task, results: results || [] }
|
||
} catch {
|
||
return { ...task, results: [] as QcTaskResultItem[] }
|
||
}
|
||
})
|
||
)
|
||
tasksWithResults.value = enriched
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
)
|
||
|
||
// ── URL helpers ──────────────────────────────────────────────────────────────
|
||
|
||
function fullUrl(url: string) {
|
||
const u = String(url || '').trim()
|
||
if (!u) return ''
|
||
if (/^https?:\/\//i.test(u)) return u
|
||
return minioBaseUrl ? `${minioBaseUrl}/${u.replace(/^\//, '')}` : u
|
||
}
|
||
|
||
// ── Diagnosis attachments ────────────────────────────────────────────────────
|
||
|
||
const diagnosisAttachmentFiles = computed(() => {
|
||
const urls = detail.value?.patient?.diagnosisAttachments || ''
|
||
if (!urls.trim()) return []
|
||
return urls
|
||
.split(',')
|
||
.map((u, i) => {
|
||
const url = u.trim()
|
||
if (!url) return null
|
||
const name = url.includes('/') ? url.split('/').pop() || `附件${i + 1}` : url
|
||
return { id: `url_${i}`, fileUrl: fullUrl(url), fileName: name }
|
||
})
|
||
.filter(Boolean) as Array<Record<string, unknown>>
|
||
})
|
||
|
||
function handlePreview(file: Record<string, unknown>) {
|
||
const url = fullUrl(String(file.fileUrl || ''))
|
||
if (url) window.open(url, '_blank')
|
||
}
|
||
|
||
function handleDownload(file: Record<string, unknown>) {
|
||
downloadAttachmentFile(file, { fullFileUrl: fullUrl })
|
||
}
|
||
|
||
// ── Task attachment helpers ─────────────────────────────────────────────────
|
||
|
||
const tasksWithAttachments = computed(() =>
|
||
tasksWithResults.value.filter((t) => (t.attachmentFiles?.length || 0) > 0)
|
||
)
|
||
|
||
function taskAttachmentSlotName(taskId: string) {
|
||
return `task-att-${taskId}`
|
||
}
|
||
|
||
function handleTaskPreview(file: Record<string, unknown>) {
|
||
const url = fullUrl(String(file.fileUrl || ''))
|
||
if (url) window.open(url, '_blank')
|
||
}
|
||
|
||
function handleTaskDownload(file: Record<string, unknown>) {
|
||
downloadAttachmentFile(file, { fullFileUrl: fullUrl })
|
||
}
|
||
|
||
// ── Tag helpers ─────────────────────────────────────────────────────────────
|
||
|
||
function conclusionTagType(conclusion?: string) {
|
||
if (conclusion === 'tg') return 'success' as const
|
||
if (conclusion === 'btg') return 'danger' as const
|
||
return 'info' as const
|
||
}
|
||
|
||
function taskStatusTagType(status?: string) {
|
||
if (status === 'ywc') return 'success' as const
|
||
if (status === 'jxz') return 'warning' as const
|
||
return 'info' as const
|
||
}
|
||
|
||
function workOrderStatusTagType(status?: string) {
|
||
if (status === 'ywc') return 'success' as const
|
||
if (status === 'ypz') return 'warning' as const
|
||
if (status === 'yzf') return 'danger' as const
|
||
return 'info' as const
|
||
}
|
||
|
||
function formatDetectMethods(wo?: Partial<QcWorkOrderDetail>) {
|
||
const parts: string[] = []
|
||
if (wo?.hasLab) parts.push('实验室')
|
||
if (wo?.hasThirdParty) parts.push('第三方')
|
||
return parts.length ? parts.join(' \\ ') : '—'
|
||
}
|
||
|
||
// ── Build task type sections (same pattern as index.vue) ────────────────────
|
||
|
||
function buildTaskTypeSections(
|
||
tasks: TaskView[],
|
||
taskType: 'sysz' | 'dsfjc',
|
||
sectionTitle: string
|
||
): ViewSection[] {
|
||
const filtered = tasks.filter((t) => t.taskType === taskType)
|
||
if (!filtered.length) return []
|
||
|
||
return filtered.map((task, index) => {
|
||
const title = filtered.length > 1 ? `${sectionTitle}(${index + 1})` : sectionTitle
|
||
const fields: ViewField[] = [
|
||
{ label: '检测项目', value: task.itemName || '—' },
|
||
{ label: '项目编码', value: task.itemCode || '—' },
|
||
{
|
||
label: '任务状态',
|
||
value: taskStatusLabel(task.taskStatus || ''),
|
||
tagType: taskStatusTagType(task.taskStatus)
|
||
},
|
||
{
|
||
label: '检测结论',
|
||
value: task.conclusionLabel || qcTaskConclusionLabel(task.conclusion || '') || '—',
|
||
tagType: conclusionTagType(task.conclusion)
|
||
},
|
||
{ label: '任务号', value: task.taskNo || '—' },
|
||
{ label: '完成时间', value: task.completedTime || '—' }
|
||
]
|
||
if (taskType === 'dsfjc') {
|
||
fields.splice(2, 0, { label: '第三方公司', value: task.companyName || '—' })
|
||
if (task.feeAmount != null) {
|
||
fields.push({ label: '费用(元)', value: String(task.feeAmount) })
|
||
}
|
||
}
|
||
if (task.results?.length) {
|
||
for (const item of task.results) {
|
||
fields.push({
|
||
label: item.paramName + (item.paramUnit ? `(${item.paramUnit})` : ''),
|
||
value: item.paramValue || '—'
|
||
})
|
||
}
|
||
} else if (taskType === 'sysz') {
|
||
fields.push({ label: '检测参数', value: '—' })
|
||
}
|
||
fields.push({ label: '备注', value: task.remark || '—', span: true })
|
||
|
||
const section: ViewSection = { title, fields }
|
||
if (task.attachmentFiles?.length) {
|
||
section.slot = taskAttachmentSlotName(task.id)
|
||
section.slotTitle = taskType === 'dsfjc' ? '检测材料' : '检测附件'
|
||
section.slotTitleStyle = 'field'
|
||
} else if (taskType === 'dsfjc') {
|
||
fields.push({ label: '检测材料', value: '—' })
|
||
} else {
|
||
fields.push({ label: '检测附件', value: '—' })
|
||
}
|
||
return section
|
||
})
|
||
}
|
||
|
||
// ── Sections computed ────────────────────────────────────────────────────────
|
||
|
||
const sections = computed<ViewSection[]>(() => {
|
||
if (!detail.value) return []
|
||
const d = detail.value
|
||
const wo: Partial<QcWorkOrderDetail> = d.workOrder || {}
|
||
const app = d.application
|
||
const patient = d.patient
|
||
const plan = d.infusionPlan
|
||
const schedule = d.infusionSchedule
|
||
const products = d.products || []
|
||
|
||
const result: ViewSection[] = []
|
||
|
||
// 1. 工单基本信息
|
||
result.push({
|
||
title: '工单基本信息',
|
||
fields: [
|
||
{ label: '工单号', value: wo.workOrderNo || '—' },
|
||
{ label: '工单类型', value: '出库', tagType: 'success' },
|
||
{
|
||
label: '业务类型',
|
||
value: wo.bizTypeLabel || bizTypeLabel(wo.bizType || ''),
|
||
tagType: bizTypeTagType(wo.bizType || '') as ViewField['tagType']
|
||
},
|
||
{
|
||
label: '状态',
|
||
value: workOrderStatusLabel(wo.workOrderStatus || ''),
|
||
tagType: workOrderStatusTagType(wo.workOrderStatus)
|
||
},
|
||
{ label: '检测方式', value: formatDetectMethods(wo) },
|
||
{ label: '配置时间', value: wo.configuredTime || '—' },
|
||
{ label: '配置人', value: wo.configuredBy || '—' },
|
||
{ label: '备注', value: wo.remark || '—', span: true },
|
||
{ label: '创建时间', value: wo.createTime || '—' }
|
||
]
|
||
})
|
||
|
||
// 2. 中试服务申请单信息
|
||
if (app) {
|
||
result.push({
|
||
title: '中试服务申请单信息',
|
||
fields: [
|
||
{ label: '申请单号', value: app.applicationNo || '—' },
|
||
{ label: '申请单名称', value: app.applicationName || '—' },
|
||
{
|
||
label: '申请单状态',
|
||
value: applicationStatusLabel(app.applicationStatus || ''),
|
||
tagType: applicationStatusTagType(app.applicationStatus || '') as ViewField['tagType']
|
||
},
|
||
{ label: '渠道名称', value: app.channelName || '—' }
|
||
]
|
||
})
|
||
}
|
||
|
||
// 3. 患者信息
|
||
if (patient) {
|
||
const patientFields: ViewField[] = [
|
||
{ label: '患者姓名', value: patient.patientName || '—' },
|
||
{ label: '性别', value: patient.sex || '—' },
|
||
{ label: '年龄', value: patient.age || '—' },
|
||
{ label: '联系电话', value: patient.phoneNo || '—' },
|
||
{ label: '身份证号', value: patient.idCardNo || '—' },
|
||
{ label: '紧急联系人', value: patient.emergencyContact || '—' },
|
||
{ label: '紧急联系电话', value: patient.emergencyPhone || '—' },
|
||
{ label: '临床诊断', value: patient.clinicalDiagnosis || '—', span: true }
|
||
]
|
||
result.push({
|
||
title: '患者信息',
|
||
fields: patientFields,
|
||
slotTitle: '诊断附件',
|
||
slotTitleStyle: 'field',
|
||
slot: 'diagnosis-attachments'
|
||
})
|
||
}
|
||
|
||
// 4. 输注方案信息
|
||
if (plan) {
|
||
result.push({
|
||
title: '输注方案信息',
|
||
fields: [
|
||
{ label: '细胞类型', value: plan.cellType || '—' },
|
||
{ label: '规格', value: plan.specText || '—' },
|
||
{ label: '总疗程数', value: plan.totalCourseCount != null ? String(plan.totalCourseCount) : '—' },
|
||
{ label: '疗程间隔', value: plan.courseInterval || '—' },
|
||
{ label: '输注途径', value: plan.infusionRoute || '—' },
|
||
{ label: '输注开始日期', value: plan.infusionStartDate || '—' }
|
||
]
|
||
})
|
||
}
|
||
|
||
// 5. 本次输注计划信息
|
||
if (schedule) {
|
||
const scheduleFields: ViewField[] = [
|
||
{ label: '输注时间', value: schedule.infusionTime || '—' },
|
||
{ label: '输注地点', value: schedule.infusionLocation || '—' },
|
||
{ label: '输注方式', value: schedule.infusionMethod || '—' },
|
||
{
|
||
label: '计划状态',
|
||
value: scheduleStatusLabel(schedule.scheduleStatus || ''),
|
||
tagType: scheduleStatusTagType(schedule.scheduleStatus || '') as ViewField['tagType']
|
||
},
|
||
{
|
||
label: '输注状态',
|
||
value: infusionStatusLabel(schedule.infusionStatus || ''),
|
||
tagType: infusionStatusTagType(schedule.infusionStatus || '') as ViewField['tagType']
|
||
},
|
||
{
|
||
label: '质检状态',
|
||
value: qcStatusLabel(schedule.qcStatus || ''),
|
||
tagType: qcStatusTagType(schedule.qcStatus || '') as ViewField['tagType']
|
||
}
|
||
]
|
||
if (schedule.cancelReason) {
|
||
scheduleFields.push({ label: '取消原因', value: schedule.cancelReason, span: true })
|
||
}
|
||
result.push({ title: '本次输注计划信息', fields: scheduleFields })
|
||
}
|
||
|
||
// 6. 产品明细
|
||
if (products.length) {
|
||
const productItems: string[] = products.map(
|
||
(p) =>
|
||
`${p.projectCode || '—'} / ${p.projectName || '—'} / ${p.cellTypeName || '—'} / ${p.specText || '—'} / 协议价:¥${p.agreementPrice != null ? formatMoneyDisplay(p.agreementPrice) : '—'} / 实际价:¥${p.actualPrice != null ? formatMoneyDisplay(p.actualPrice) : '—'} / 数量:${p.quantity ?? '—'} / ${productStatusLabel(p.productStatus || '')}`
|
||
)
|
||
result.push({
|
||
title: '产品明细',
|
||
fields: [{ label: '产品列表', value: '', span: true }],
|
||
slot: 'product-table'
|
||
})
|
||
// Override: we'll use items instead of a separate slot — use span field with items list
|
||
result[result.length - 1] = {
|
||
title: '产品明细',
|
||
fields: [
|
||
{
|
||
label: '产品列表',
|
||
span: true,
|
||
items: products.map(
|
||
(p) =>
|
||
`${p.projectCode || '—'} ${p.projectName || '—'} | ${p.cellTypeName || '—'} | ${p.specText || '—'} | 协议价 ¥${p.agreementPrice != null ? formatMoneyDisplay(p.agreementPrice) : '—'} | 实际价 ¥${p.actualPrice != null ? formatMoneyDisplay(p.actualPrice) : '—'} | 数量 ${p.quantity ?? '—'}`
|
||
)
|
||
}
|
||
]
|
||
}
|
||
}
|
||
|
||
// 7. 检测结果 — lab tasks
|
||
const labSections = buildTaskTypeSections(tasksWithResults.value, 'sysz', '实验室项目')
|
||
result.push(...labSections)
|
||
|
||
// 8. 检测结果 — third-party tasks
|
||
const thirdSections = buildTaskTypeSections(tasksWithResults.value, 'dsfjc', '第三方项目')
|
||
result.push(...thirdSections)
|
||
|
||
return result
|
||
})
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.outbound-qc-task-attachments {
|
||
margin-top: 0;
|
||
}
|
||
</style>
|