338 lines
12 KiB
Vue
338 lines
12 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 #product-table>
|
||
<el-table :data="detail?.products || []" stripe size="small" class="outbound-product-table">
|
||
<el-table-column type="index" label="序号" min-width="60" align="center" />
|
||
<el-table-column prop="projectCode" label="项目编码" min-width="120" align="center" show-overflow-tooltip />
|
||
<el-table-column prop="projectName" label="项目名称" min-width="120" align="center" show-overflow-tooltip />
|
||
<el-table-column prop="cellTypeName" label="细胞类型" min-width="100" align="center" show-overflow-tooltip />
|
||
<el-table-column prop="specText" label="规格" min-width="100" align="center" show-overflow-tooltip />
|
||
<el-table-column prop="quantity" label="数量" min-width="70" align="center" />
|
||
<el-table-column label="产品状态" min-width="100" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag :type="productStatusTagType(row.productStatus || '') as any" size="small">
|
||
{{ productStatusLabel(row.productStatus || '') }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</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 { bizTypeLabel, bizTypeTagType, productStatusLabel, productStatusTagType } from '@/utils/status-tag-registry'
|
||
import { buildOutboundPilotContextSections } from '@/utils/outbound-qc-pilot-view-sections'
|
||
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'
|
||
|
||
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 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.configuredByName || wo.configuredBy || '—' },
|
||
{ label: '备注', value: wo.remark || '—', span: true },
|
||
{ label: '创建时间', value: wo.createTime || '—' }
|
||
]
|
||
})
|
||
|
||
result.push(...buildOutboundPilotContextSections(d))
|
||
|
||
// 检测结果 — 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;
|
||
}
|
||
|
||
.outbound-product-table {
|
||
margin-top: 4px;
|
||
}
|
||
</style>
|