405 lines
13 KiB
Vue
405 lines
13 KiB
Vue
<!-- 质检任务 — 只读查看(参数、结论、附件) -->
|
||
<!-- eslint-disable vue/no-v-model-argument -->
|
||
<template>
|
||
<SystemViewDialog
|
||
v-model:visible="innerVisible"
|
||
title="质检任务详情"
|
||
width="960px"
|
||
:grid-columns="3"
|
||
:icon="Tickets"
|
||
:meta="viewDetail?.taskNo || ''"
|
||
:sections="viewSections"
|
||
:loading="loading"
|
||
append-to-body
|
||
compact
|
||
modal-class="qc-task-view-dialog-mask"
|
||
>
|
||
<template #reception-extra>
|
||
<div class="view-reception-attachments">
|
||
<div class="view-kv view-kv-span-2">
|
||
<dt>接收附件</dt>
|
||
<dd>
|
||
<ProtocolAttachmentReadonly
|
||
:files="viewReceptionAttachmentFiles"
|
||
@preview="handleAttachmentPreview"
|
||
@download="handleAttachmentDownload"
|
||
/>
|
||
</dd>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
<template #material-usages>
|
||
<div v-if="viewMaterialUsages.length" class="view-subtable-wrap">
|
||
<el-table :data="viewMaterialUsages" stripe class="list-table view-subtable">
|
||
<el-table-column
|
||
type="index"
|
||
label="序号"
|
||
min-width="56"
|
||
align="center"
|
||
header-align="center"
|
||
:index="(index) => index + 1"
|
||
/>
|
||
<el-table-column
|
||
prop="materialName"
|
||
label="物料名称"
|
||
min-width="160"
|
||
align="center"
|
||
header-align="center"
|
||
/>
|
||
<el-table-column label="规格型号" min-width="120" align="center" header-align="center">
|
||
<template #default="{ row }">{{ row.specModel || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="用量" min-width="100" align="center" header-align="center">
|
||
<template #default="{ row }">
|
||
{{ row.qty != null && row.qty !== '' ? row.qty : '—' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="单位" min-width="72" align="center" header-align="center">
|
||
<template #default="{ row }">{{ row.unit || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="备注" min-width="140" align="center" header-align="center">
|
||
<template #default="{ row }">{{ row.remark || '—' }}</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</div>
|
||
<p v-else class="view-empty-hint">暂无物料使用记录</p>
|
||
</template>
|
||
<template #task-attachments>
|
||
<ProtocolAttachmentReadonly
|
||
:files="viewDetail?.attachmentFiles || []"
|
||
@preview="handleAttachmentPreview"
|
||
@download="handleAttachmentDownload"
|
||
/>
|
||
</template>
|
||
</SystemViewDialog>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, computed, watch } from 'vue'
|
||
import { Tickets } from '@element-plus/icons-vue'
|
||
import ProtocolAttachmentReadonly from '@/views/cell-storage/protocol/ProtocolAttachmentReadonly.vue'
|
||
import SystemViewDialog from '@/components/business/system-view-dialog/index.vue'
|
||
import type { ViewSection } from '@/components/business/system-view-dialog/index.vue'
|
||
import { fetchQcTaskDetail, type QcTaskDetail } from '@/api/qc-task'
|
||
import {
|
||
fetchQcTaskResults,
|
||
fetchQcTaskMaterialUsages,
|
||
type QcTaskMaterialUsageItem
|
||
} from '@/api/qc-task-result'
|
||
import { fetchQcMaterialOptions, type QcMaterialOption } from '@/api/qc-material'
|
||
import {
|
||
taskTypeLabel,
|
||
taskStatusLabel,
|
||
qcBizTypeLabel,
|
||
receptionSourceLabel,
|
||
acceptConclusionLabel,
|
||
transportTypeLabel,
|
||
workOrderStatusLabel,
|
||
qcTaskConclusionLabel
|
||
} from '@/utils/qc-labels'
|
||
import { downloadAttachmentFile } from '@/utils/download-attachment'
|
||
|
||
const props = defineProps<{
|
||
visible: boolean
|
||
taskId?: string
|
||
}>()
|
||
|
||
const emit = defineEmits<{
|
||
(e: 'update:visible', val: boolean): void
|
||
}>()
|
||
|
||
const innerVisible = computed({
|
||
get: () => props.visible,
|
||
set: (val) => emit('update:visible', val)
|
||
})
|
||
|
||
type ViewMaterialUsageRow = {
|
||
materialId: string
|
||
materialName: string
|
||
specModel: string
|
||
unit: string
|
||
qty: number | undefined
|
||
remark: string
|
||
}
|
||
|
||
const loading = ref(false)
|
||
const viewDetail = ref<QcTaskDetail | null>(null)
|
||
const viewMaterialUsages = ref<ViewMaterialUsageRow[]>([])
|
||
const minioBaseUrl = (import.meta.env.VITE_MINIO_BASE_URL || '').replace(/\/$/, '')
|
||
|
||
function materialRowsFromApi(items: QcTaskMaterialUsageItem[]): ViewMaterialUsageRow[] {
|
||
const merged = new Map<string, ViewMaterialUsageRow>()
|
||
for (const u of items || []) {
|
||
const mid = (u.materialId || '').trim()
|
||
if (!mid) continue
|
||
const qtyRaw = Math.abs(Number(u.changeQty) || 0)
|
||
const prev = merged.get(mid)
|
||
if (prev) {
|
||
prev.qty = (Number(prev.qty) || 0) + qtyRaw
|
||
} else {
|
||
merged.set(mid, {
|
||
materialId: mid,
|
||
materialName: u.materialName || '',
|
||
specModel: '',
|
||
unit: '',
|
||
qty: qtyRaw > 0 ? qtyRaw : undefined,
|
||
remark: u.remark || ''
|
||
})
|
||
}
|
||
}
|
||
return Array.from(merged.values())
|
||
}
|
||
|
||
function enrichMaterialUsageRows(rows: ViewMaterialUsageRow[], options: QcMaterialOption[]) {
|
||
for (const row of rows) {
|
||
const opt = options.find((o) => o.id === row.materialId)
|
||
if (opt) {
|
||
row.materialName = opt.materialName || row.materialName
|
||
row.specModel = opt.specModel || ''
|
||
row.unit = opt.unit || ''
|
||
}
|
||
}
|
||
}
|
||
|
||
watch(
|
||
() => [props.visible, props.taskId] as const,
|
||
async ([vis, id]) => {
|
||
if (!vis || !id) {
|
||
viewDetail.value = null
|
||
viewMaterialUsages.value = []
|
||
return
|
||
}
|
||
loading.value = true
|
||
try {
|
||
const detail = await fetchQcTaskDetail(id)
|
||
try {
|
||
const results = await fetchQcTaskResults(id)
|
||
;(detail as QcTaskDetail).results = results || []
|
||
} catch {
|
||
;(detail as QcTaskDetail).results = []
|
||
}
|
||
viewMaterialUsages.value = []
|
||
if (detail.taskType !== 'dsfjc') {
|
||
try {
|
||
const [savedUsages, opts] = await Promise.all([
|
||
fetchQcTaskMaterialUsages(id).catch(() => [] as QcTaskMaterialUsageItem[]),
|
||
fetchQcMaterialOptions().catch(() => [] as QcMaterialOption[])
|
||
])
|
||
const rows = materialRowsFromApi(savedUsages || [])
|
||
enrichMaterialUsageRows(rows, opts || [])
|
||
viewMaterialUsages.value = rows
|
||
} catch {
|
||
viewMaterialUsages.value = []
|
||
}
|
||
}
|
||
viewDetail.value = detail
|
||
} catch {
|
||
viewDetail.value = null
|
||
viewMaterialUsages.value = []
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
},
|
||
{ immediate: true }
|
||
)
|
||
|
||
function formatMetric(v: unknown) {
|
||
if (v === null || v === undefined || v === '') return '—'
|
||
return String(v)
|
||
}
|
||
|
||
function formatCheckResults(items?: Array<{ itemName?: string; checked?: boolean }>) {
|
||
if (!items?.length) return '—'
|
||
return items.map((x) => `${x.itemName || ''}${x.checked ? '(✓)' : '(×)'}`).join('、')
|
||
}
|
||
|
||
const viewReceptionAttachmentFiles = computed(() => {
|
||
const r = viewDetail.value?.reception
|
||
if (!r) return []
|
||
if (Array.isArray(r.receiveAttachmentFiles) && r.receiveAttachmentFiles.length) {
|
||
return r.receiveAttachmentFiles as Array<Record<string, unknown>>
|
||
}
|
||
const urls = String(r.receiveAttachments || '')
|
||
if (!urls.trim()) return []
|
||
return urls
|
||
.split(',')
|
||
.map((u) => u.trim())
|
||
.filter(Boolean)
|
||
.map((fileUrl, i) => ({ id: `rec_${i}`, fileUrl, fileName: fileUrl.split('/').pop() || '' }))
|
||
})
|
||
|
||
const viewSections = computed<ViewSection[]>(() => {
|
||
const d = viewDetail.value
|
||
if (!d) return []
|
||
const r = d.reception || {}
|
||
const transportFields: ViewSection['fields'] = [
|
||
{ label: '运输方式', value: transportTypeLabel(String(r.transportType || '')) }
|
||
]
|
||
if (r.transportType === 'kdys') {
|
||
transportFields.push(
|
||
{ label: '快递公司', value: r.expressCompanyName || '—' },
|
||
{ label: '快递单号', value: r.waybillNo || '—' }
|
||
)
|
||
} else if (r.transportType === 'ryxd') {
|
||
transportFields.push(
|
||
{ label: '携带人', value: r.carrierName || '—' },
|
||
{ label: '携带人电话', value: r.carrierPhone || '—' }
|
||
)
|
||
}
|
||
if (r.etaTime) {
|
||
transportFields.push({ label: '预计到达', value: r.etaTime })
|
||
}
|
||
const taskResultSummaryFields: ViewSection['fields'] = [
|
||
{
|
||
label: '任务状态',
|
||
value: taskStatusLabel(d.taskStatus),
|
||
tagType: d.taskStatus === 'ywc' ? 'success' : d.taskStatus === 'jxz' ? 'warning' : 'info'
|
||
},
|
||
{
|
||
label: '检测结论',
|
||
value: d.conclusionLabel || qcTaskConclusionLabel(d.conclusion || '') || '—',
|
||
tagType: d.conclusion === 'tg' ? 'success' : d.conclusion === 'btg' ? 'danger' : 'info'
|
||
},
|
||
{ label: '备注', value: d.remark || '—' }
|
||
]
|
||
const resultSection: ViewSection[] = [
|
||
{
|
||
title: '质检结论',
|
||
fields: taskResultSummaryFields
|
||
},
|
||
...(d.results && d.results.length > 0
|
||
? [
|
||
{
|
||
title: '检测参数',
|
||
fields: d.results.map((item) => ({
|
||
label: item.paramName + (item.paramUnit ? `(${item.paramUnit})` : ''),
|
||
value: item.paramValue || '—'
|
||
}))
|
||
}
|
||
]
|
||
: [{ title: '检测参数', fields: [] }])
|
||
]
|
||
const tailSections: ViewSection[] = []
|
||
if (d.taskType !== 'dsfjc') {
|
||
tailSections.push({ title: '物料使用', fields: [], slot: 'material-usages' })
|
||
}
|
||
if (d.attachmentFiles?.length) {
|
||
tailSections.push({
|
||
title: d.taskType === 'dsfjc' ? '检测材料' : '检测附件',
|
||
fields: [],
|
||
slot: 'task-attachments'
|
||
})
|
||
}
|
||
return [
|
||
{
|
||
title: '任务信息',
|
||
fields: [
|
||
{ label: '任务号', value: d.taskNo },
|
||
{ label: '业务类型', value: d.qcBizTypeLabel || qcBizTypeLabel(d.qcBizType || ''), tagType: 'success' },
|
||
{ label: '工单号', value: d.workOrderNo || '—' },
|
||
{
|
||
label: '工单状态',
|
||
value: d.workOrderStatus ? workOrderStatusLabel(d.workOrderStatus) : '—',
|
||
tagType: d.workOrderStatus === 'ywc' ? 'success' : d.workOrderStatus === 'ypz' ? 'warning' : 'info'
|
||
},
|
||
{ label: '检测类型', value: taskTypeLabel(d.taskType), tagType: d.taskType === 'sysz' ? 'success' : 'info' },
|
||
{ label: '检测项目', value: d.itemName },
|
||
{ label: '项目编码', value: d.itemCode || '—' },
|
||
{ label: '第三方公司', value: d.companyName || '—' },
|
||
{ label: '完成时间', value: d.completedTime || '—' },
|
||
{ label: '创建时间', value: d.createTime || '—' }
|
||
]
|
||
},
|
||
{
|
||
title: '样本信息',
|
||
fields: [
|
||
{ label: '协议号', value: r.protocolNo || d.protocolNo || '—' },
|
||
{ label: '样本编码', value: r.sampleCode || d.sampleCode || '—' },
|
||
{
|
||
label: '样本来源',
|
||
value: r.sourceTypeLabel || d.receptionSourceLabel || receptionSourceLabel(d.receptionSource || ''),
|
||
tagType: 'primary'
|
||
},
|
||
{ label: '样本类型', value: r.sampleTypeName || d.sampleTypeName || '—' }
|
||
]
|
||
},
|
||
...(transportFields.length > 1 || r.transportType
|
||
? [{ title: '运输信息', fields: transportFields }]
|
||
: []),
|
||
{
|
||
title: '样本接收',
|
||
slot: 'reception-extra',
|
||
fields: [
|
||
{ label: '接收时间', value: r.receptionTime || d.receptionTime || '—' },
|
||
{ label: '接收经手人', value: r.handlerName || d.handlerName || '—' },
|
||
{
|
||
label: '接收温度(℃)',
|
||
value: r.receiveTemperature ? `${r.receiveTemperature}℃` : '—'
|
||
},
|
||
{ label: '体积(ml)', value: formatMetric(r.volumeMl) },
|
||
{ label: '净重(g)', value: formatMetric(r.netWeightG) },
|
||
{
|
||
label: '结论',
|
||
value:
|
||
r.acceptConclusionLabel ||
|
||
acceptConclusionLabel(String(r.acceptConclusion || ''))
|
||
},
|
||
{ label: '检查项', value: formatCheckResults(r.checkResults), span: true },
|
||
{ label: '备注', value: r.remark || '—', span: true }
|
||
]
|
||
},
|
||
...resultSection,
|
||
...tailSections
|
||
]
|
||
})
|
||
|
||
function attachmentFullUrl(url: string) {
|
||
const u = String(url || '').trim()
|
||
if (!u) return ''
|
||
if (/^https?:\/\//i.test(u)) return u
|
||
return minioBaseUrl ? `${minioBaseUrl}/${u.replace(/^\//, '')}` : u
|
||
}
|
||
|
||
function handleAttachmentPreview(file: Record<string, unknown>) {
|
||
const url = attachmentFullUrl(String(file.fileUrl || ''))
|
||
if (url) window.open(url, '_blank')
|
||
}
|
||
|
||
function handleAttachmentDownload(file: Record<string, unknown>) {
|
||
downloadAttachmentFile(file, { fullFileUrl: attachmentFullUrl })
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
/* 叠在协议/捐赠查看弹窗之上 */
|
||
.qc-task-view-dialog-mask {
|
||
z-index: 4000 !important;
|
||
}
|
||
</style>
|
||
|
||
<style scoped lang="scss">
|
||
.view-reception-attachments {
|
||
margin-top: 4px;
|
||
|
||
.view-kv {
|
||
display: grid;
|
||
grid-template-columns: 96px 1fr;
|
||
gap: 8px 12px;
|
||
font-size: 13px;
|
||
align-items: start;
|
||
|
||
dt {
|
||
margin: 0;
|
||
color: #64748b;
|
||
font-weight: 500;
|
||
}
|
||
|
||
dd {
|
||
margin: 0;
|
||
color: #1e293b;
|
||
}
|
||
}
|
||
}
|
||
|
||
</style>
|