Files
zkxw/web-admin/src/views/quality-inspection/qc-work-order/OutboundQcViewDialog.vue
T
2026-06-12 15:17:54 +08:00

556 lines
19 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 -->
<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>
<div v-if="detail?.products?.length" class="view-subtable-wrap">
<el-table
:data="detail?.products || []"
stripe
size="small"
class="list-table view-subtable 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>
</div>
<p v-else class="view-empty-hint">暂无产品明细</p>
</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>
<template v-for="task in labTasksWithMaterials" #[taskMaterialSlotName(task.id)]>
<div v-if="task.materialUsages?.length" :key="task.id" class="view-subtable-wrap">
<el-table :data="task.materialUsages" 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="stockInNo"
label="入库编号"
min-width="120"
align="center"
header-align="center"
/>
<el-table-column
prop="materialName"
label="物料名称"
min-width="140"
align="center"
header-align="center"
/>
<el-table-column label="批号" min-width="100" align="center" header-align="center">
<template #default="{ row }">{{ row.batchNo || '—' }}</template>
</el-table-column>
<el-table-column label="领用人" min-width="100" align="center" header-align="center">
<template #default="{ row }">{{ row.receiverName || '—' }}</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 :key="`${task.id}-empty`" class="view-empty-hint">暂无物料使用记录</p>
</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,
fetchQcTaskMaterialUsages,
type QcTaskResultItem,
type QcTaskMaterialUsageItem
} from '@/api/qc-task-result'
import { workOrderStatusLabel, taskStatusLabel, qcTaskConclusionLabel } from '@/utils/qc-labels'
import {
bizTypeLabel,
bizTypeTagType,
productStatusLabel,
productStatusTagType,
payStatusTagType
} from '@/utils/status-tag-registry'
import {
buildOutboundPilotContextSections,
resolveOutboundViewVariant
} 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'
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 ViewMaterialUsageRow = {
stockInNo: string
materialName: string
batchNo: string
receiverName: string
unit: string
qty: number | undefined
remark: string
}
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[]
materialUsages?: ViewMaterialUsageRow[]
companyName?: string
feeAmount?: number
}
const tasksWithResults = ref<TaskView[]>([])
const minioBaseUrl = (import.meta.env.VITE_MINIO_BASE_URL || '').replace(/\/$/, '')
function materialRowsFromApi(items: QcTaskMaterialUsageItem[]): ViewMaterialUsageRow[] {
return (items || [])
.filter((u) => (u.requisitionUsageId || u.parentUsageId || '').trim())
.map((u) => ({
stockInNo: u.stockInNo || '',
materialName: u.materialName || '',
batchNo: u.batchNo || '',
receiverName: u.requisitionReceiverName || u.receiverName || '',
unit: (u.usageUnit || '').trim(),
qty: Math.abs(Number(u.changeQty) || 0) || undefined,
remark: u.remark || ''
}))
}
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) => {
const base: TaskView = { ...task, results: [], materialUsages: [] }
if (task.taskStatus !== 'ywc') {
return base
}
try {
const results = await fetchQcTaskResults(task.id)
base.results = results || []
} catch {
base.results = []
}
if (task.taskType === 'sysz') {
try {
const savedUsages = await fetchQcTaskMaterialUsages(task.id)
base.materialUsages = materialRowsFromApi(savedUsages || [])
} catch {
base.materialUsages = []
}
}
return base
})
)
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)
)
const labTasksWithMaterials = computed(() =>
tasksWithResults.value.filter((t) => t.taskType === 'sysz')
)
function taskAttachmentSlotName(taskId: string) {
return `task-att-${taskId}`
}
function taskMaterialSlotName(taskId: string) {
return `task-mat-${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.flatMap((task, index) => {
const title = filtered.length > 1 ? `${sectionTitle}(${index + 1})` : sectionTitle
const taskInfoFields: 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') {
taskInfoFields.splice(2, 0, { label: '第三方公司', value: task.companyName || '—' })
if (task.feeAmount != null) {
taskInfoFields.push({ label: '费用(元)', value: String(task.feeAmount) })
}
}
const paramFields: ViewField[] = (task.results || []).map((item) => ({
label: item.paramName + (item.paramUnit ? `(${item.paramUnit})` : ''),
value: item.paramValue || '—'
}))
const remarkField: ViewField = { label: '备注', value: task.remark || '—', span: true }
const section: ViewSection =
taskType === 'sysz'
? {
title,
fields: [],
fieldGroups: [
{ fields: taskInfoFields },
{
title: '检测参数',
titleStyle: 'field',
fields: paramFields,
emptyHint: '—'
},
{ fields: [remarkField] }
]
}
: {
title,
fields: [
...taskInfoFields,
...(paramFields.length
? paramFields
: [{ label: '检测参数', value: '—' as const }]),
remarkField
]
}
if (task.attachmentFiles?.length) {
section.slot = taskAttachmentSlotName(task.id)
section.slotTitle = taskType === 'dsfjc' ? '检测材料' : '检测附件'
section.slotTitleStyle = 'field'
} else if (taskType === 'dsfjc') {
section.fields.push({ label: '检测材料', value: '—' })
} else if (taskType === 'sysz') {
section.fieldGroups?.push({ fields: [{ label: '检测附件', value: '—' }] })
} else {
section.fields.push({ label: '检测附件', value: '—' })
}
const sections: ViewSection[] = [section]
if (taskType === 'sysz') {
sections.push({
title: '',
fields: [],
slotTitle: '物料使用',
slotTitleStyle: 'field',
slot: taskMaterialSlotName(task.id)
})
}
return sections
})
}
// ── 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 || '—' }
]
})
const variant = resolveOutboundViewVariant(d.application?.bizType || d.workOrder?.bizType)
result.push(...buildOutboundPilotContextSections(d, variant))
const feeSummary = d.feeSummary || d.workOrder?.feeSummary
if (variant === 'basic_experiment') {
result.push({
title: '缴费信息',
fields: feeSummary
? [
{
label: '售卖金额(元)',
value:
feeSummary.saleAmount != null
? formatMoneyDisplay(feeSummary.saleAmount)
: '—'
},
{
label: '应缴金额(元)',
value:
feeSummary.paymentAmount != null
? formatMoneyDisplay(feeSummary.paymentAmount)
: '—'
},
{
label: '实收金额(元)',
value:
feeSummary.transferAmount != null
? formatMoneyDisplay(feeSummary.transferAmount)
: '—'
},
{
label: '缴费状态',
value: feeSummary.payStatusLabel || '—',
tagType: payStatusTagType(feeSummary.payStatus || '') as ViewField['tagType']
}
]
: [{ label: '缴费信息', value: '暂无缴费记录', span: true }]
})
}
// 检测结果 — 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: 0;
:deep(.el-table__header th.el-table__cell),
:deep(.el-table__body td.el-table__cell) {
font-size: 12px;
padding: 6px 0;
}
:deep(.el-table__header th.el-table__cell .cell),
:deep(.el-table__body td.el-table__cell .cell) {
font-size: 12px;
line-height: 1.35;
}
:deep(.el-tag) {
--el-tag-font-size: 11px;
height: 20px;
padding: 0 6px;
}
}
</style>