import type { OutboundQcDetail } from '@/api/qc-work-order' import type { ViewField, ViewSection } from '@/components/business/system-view-dialog/index.vue' import { maskIdCard } from '@/utils/mask-sensitive' import { applicationStatusLabel, applicationStatusTagType, infusionMethodLabel, infusionStatusLabel, infusionStatusTagType, qcStatusLabel, qcStatusTagType, scheduleStatusLabel, scheduleStatusTagType, sexLabel } from '@/utils/status-tag-registry' export type OutboundViewContextVariant = | 'pilot_service' | 'clinical_application' | 'basic_experiment' const SECTION_TITLES: Record< OutboundViewContextVariant, { application: string; schedule: string } > = { pilot_service: { application: '中试服务申请单信息', schedule: '本次输注计划信息' }, clinical_application: { application: '临床应用申请信息', schedule: '临床应用输注计划信息' }, basic_experiment: { application: '基础实验申请信息', schedule: '交付计划信息' } } function buildBasicExperimentApplicationFields(app: NonNullable) { return [ { label: '申请单号', value: app.applicationNo || '—' }, { label: '课题名称', value: app.projectTitle || '—' }, { label: '客户名称', value: app.customerName || '—' }, { label: '客户联系人', value: app.customerContact || '—' }, { label: '客户联系方式', value: app.customerPhone || '—' }, { label: '申请单状态', value: applicationStatusLabel(app.applicationStatus || ''), tagType: applicationStatusTagType(app.applicationStatus || '') as ViewField['tagType'] } ] } function buildDefaultApplicationFields( app: NonNullable, variant: OutboundViewContextVariant ) { if (variant === 'basic_experiment') { return buildBasicExperimentApplicationFields(app) } return [ { label: '申请单号', value: app.applicationNo || '—' }, { label: '申请单名称', value: app.applicationName || '—' }, { label: '申请单状态', value: applicationStatusLabel(app.applicationStatus || ''), tagType: applicationStatusTagType(app.applicationStatus || '') as ViewField['tagType'] }, { label: '渠道名称', value: app.channelName || '—' } ] } /** 出库工单/质检:申请单 / 患者 / 输注方案 / 输注计划 / 产品明细(码值转中文标签) */ export function buildOutboundPilotContextSections( detail: OutboundQcDetail, variant: OutboundViewContextVariant = 'pilot_service' ): ViewSection[] { const app = detail.application const patient = detail.patient const plan = detail.infusionPlan const schedule = detail.infusionSchedule const products = detail.products || [] const titles = SECTION_TITLES[variant] const result: ViewSection[] = [] if (app) { result.push({ title: titles.application, fields: buildDefaultApplicationFields(app, variant) }) } if (patient && variant !== 'basic_experiment') { result.push({ title: '患者信息', fields: [ { label: '患者姓名', value: patient.patientName || '—' }, { label: '性别', value: sexLabel(String(patient.sex ?? '')) || '—' }, { label: '年龄', value: patient.age || '—' }, { label: '联系电话', value: patient.phoneNo || '—' }, { label: '身份证号', value: patient.idCardNo ? maskIdCard(patient.idCardNo) : '—' }, { label: '紧急联系人', value: patient.emergencyContact || '—' }, { label: '紧急联系电话', value: patient.emergencyPhone || '—' }, { label: '临床诊断', value: patient.clinicalDiagnosis || '—', span: true } ], slotTitle: '诊断附件', slotTitleStyle: 'field', slot: 'diagnosis-attachments' }) } if (plan && variant !== 'basic_experiment') { result.push({ title: '输注方案信息', fields: [ { label: '总疗程数', value: plan.totalCourseCount != null ? String(plan.totalCourseCount) : '—' }, { label: '疗程间隔', value: plan.courseInterval || '—' }, { label: '输注开始日期', value: plan.infusionStartDate || '—' } ] }) } if (schedule) { const pickupLabel = variant === 'basic_experiment' ? '交付时间' : '输注时间' const scheduleFields: ViewField[] = [ { label: pickupLabel, value: schedule.infusionTime || '—' } ] if (variant === 'basic_experiment') { scheduleFields.push({ label: '售卖金额', value: schedule.amount != null && schedule.amount !== '' ? `¥${Number(schedule.amount).toLocaleString('zh-CN', { minimumFractionDigits: 2 })}` : '—' }) } else { scheduleFields.push( { label: '输注地点', value: schedule.infusionLocation || '—' }, { label: '输注方式', value: infusionMethodLabel(schedule.infusionMethod || '') } ) } scheduleFields.push({ label: '计划状态', value: scheduleStatusLabel(schedule.scheduleStatus || ''), tagType: scheduleStatusTagType(schedule.scheduleStatus || '') as ViewField['tagType'] }) if (variant !== 'basic_experiment') { scheduleFields.push({ label: '输注状态', value: infusionStatusLabel(schedule.infusionStatus || ''), tagType: infusionStatusTagType(schedule.infusionStatus || '') as ViewField['tagType'] }) } scheduleFields.push({ 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: titles.schedule, fields: scheduleFields }) } if (products.length) { result.push({ title: '产品明细', fields: [], slot: 'product-table' }) } return result } export function resolveOutboundViewVariant(bizType?: string | null): OutboundViewContextVariant { if (bizType === 'clinical_application' || bizType === 'basic_experiment') { return bizType } return 'pilot_service' } export function isOutboundPilotServiceQcTask( d?: { qcBizType?: string receptionSource?: string } | null ): boolean { return d?.qcBizType === 'outbound' && d?.receptionSource === 'pilot_service' }