301 lines
10 KiB
TypeScript
301 lines
10 KiB
TypeScript
import type { QcWorkOrder } from '@/api/qc-work-order'
|
|
import { qcBizTypeLabel } from '@/utils/qc-labels'
|
|
import {
|
|
donationStatusLabel,
|
|
donationStatusTagType,
|
|
protocolStatusLabel,
|
|
protocolStatusTagType,
|
|
qcBizTypeTagType
|
|
} from '@/utils/status-tag-registry'
|
|
import type { TagType } from '@/utils/status-tag-registry'
|
|
import type { QcWorkOrderTabKey } from '@/utils/qc-work-order-tabs'
|
|
import { getQcWorkOrderTab } from '@/utils/qc-work-order-tabs'
|
|
import { formatMoneyDisplay } from '@/utils/money-format'
|
|
|
|
export type CardMetaFieldKind = 'text' | 'tag'
|
|
|
|
export type CardMetaField = {
|
|
label: string
|
|
kind?: CardMetaFieldKind
|
|
getValue: (row: QcWorkOrder) => string
|
|
getTagType?: (row: QcWorkOrder) => TagType | undefined
|
|
visible?: (row: QcWorkOrder) => boolean
|
|
/** 占满整行 */
|
|
wide?: boolean
|
|
/** 跨列数(如 2 表示占两列,宽于默认但不独占一行) */
|
|
colSpan?: number
|
|
}
|
|
|
|
export type QcWorkOrderCardMetaConfig = {
|
|
tabKey: QcWorkOrderTabKey
|
|
listLayout: 'inbound-grouped' | 'outbound-grouped' | 'standalone'
|
|
showTriggerTag: boolean
|
|
showProtocolFeeSummary: boolean
|
|
showOutboundFeeSummary: boolean
|
|
metaFields: CardMetaField[]
|
|
buildGroupContextParts: (row: QcWorkOrder) => string[]
|
|
allowEditTemporary: boolean
|
|
allowEditRemark: boolean
|
|
allowDelete: boolean
|
|
}
|
|
|
|
function formatDetectMethods(row: QcWorkOrder) {
|
|
const parts: string[] = []
|
|
if (row.hasLab) parts.push('实验室')
|
|
if (row.hasThirdParty) parts.push('第三方')
|
|
return parts.length ? parts.join(' / ') : '—'
|
|
}
|
|
|
|
function formatQcTarget(row: QcWorkOrder) {
|
|
if ((row.triggerSource || 'reception') === 'production') {
|
|
const parts = [row.cellProductCode, row.cellProductName].filter(Boolean)
|
|
return parts.length ? parts.join(' · ') : '—'
|
|
}
|
|
return '原始样本'
|
|
}
|
|
|
|
function formatOutboundScheduleSortNo(row: QcWorkOrder) {
|
|
const n = row.sortNo
|
|
if (n == null || n === '' || Number(n) <= 0) return '—'
|
|
return `第${Number(n)}次`
|
|
}
|
|
|
|
function formatOutboundScheduleTotalCount(row: QcWorkOrder) {
|
|
const n = row.totalCourseCount
|
|
if (n == null || n === '' || Number(n) <= 0) return '—'
|
|
return `共${Number(n)}次`
|
|
}
|
|
|
|
function formatTempCellProductField(row: QcWorkOrder, value?: string | null) {
|
|
if (row.workOrderType !== 'temporary') return '—'
|
|
return String(value || '').trim() || '—'
|
|
}
|
|
|
|
function protocolStatusLabelBySource(status: string, source: string): string {
|
|
return source === 'research_donation' ? donationStatusLabel(status) : protocolStatusLabel(status)
|
|
}
|
|
|
|
function protocolStatusTagTypeBySource(status: string, source: string): TagType {
|
|
return source === 'research_donation' ? donationStatusTagType(status) : protocolStatusTagType(status)
|
|
}
|
|
|
|
const commonTailFields: CardMetaField[] = [
|
|
{ label: '检测方式', getValue: formatDetectMethods },
|
|
{ label: '创建时间', getValue: (row) => row.createTime || '—' },
|
|
{
|
|
label: '备注',
|
|
getValue: (row) => row.remark || '—',
|
|
visible: (row) => !!row.remark,
|
|
wide: true
|
|
}
|
|
]
|
|
|
|
const inboundGroupedFields: CardMetaField[] = [
|
|
{ label: '质检对象', getValue: formatQcTarget, colSpan: 2 },
|
|
{
|
|
label: '关联生产工单',
|
|
getValue: (row) => row.productionWorkOrderNo || '—',
|
|
visible: (row) => (row.triggerSource || 'reception') === 'production'
|
|
},
|
|
{ label: '实验室入库编码', getValue: (row) => row.labStorageCode || '—' },
|
|
...commonTailFields
|
|
]
|
|
|
|
const outboundPilotClinicalFields: CardMetaField[] = [
|
|
{ label: '申请单号', getValue: (row) => row.applicationNo || '—' },
|
|
{ label: '申请单名称', getValue: (row) => row.applicationName || '—' },
|
|
{ label: '渠道名称', getValue: (row) => row.channelName || '—' },
|
|
{ label: '患者姓名', getValue: (row) => row.patientName || '—' },
|
|
{ label: '第几次', getValue: formatOutboundScheduleSortNo },
|
|
{ label: '总次数', getValue: formatOutboundScheduleTotalCount },
|
|
{ label: '输注时间', getValue: (row) => row.infusionTime || '—' },
|
|
...commonTailFields
|
|
]
|
|
|
|
const outboundBasicExperimentFields: CardMetaField[] = [
|
|
{ label: '申请单号', getValue: (row) => row.applicationNo || '—' },
|
|
{ label: '课题名称', getValue: (row) => row.projectTitle || row.applicationName || '—' },
|
|
{ label: '客户名称', getValue: (row) => row.customerName || '—' },
|
|
{ label: '交付时间', getValue: (row) => row.infusionTime || '—' },
|
|
{
|
|
label: '售卖金额',
|
|
getValue: (row) => {
|
|
const amount = row.feeSummary?.saleAmount
|
|
if (amount == null || amount === '') return '—'
|
|
return `¥${formatMoneyDisplay(amount)}`
|
|
}
|
|
},
|
|
...commonTailFields
|
|
]
|
|
|
|
const temporaryFields: CardMetaField[] = [
|
|
{
|
|
label: '业务类型',
|
|
kind: 'tag',
|
|
getValue: (row) => row.qcBizTypeLabel || qcBizTypeLabel('temporary'),
|
|
getTagType: () => qcBizTypeTagType('temporary')
|
|
},
|
|
{
|
|
label: '产品编码',
|
|
getValue: (row) => formatTempCellProductField(row, row.cellProductCode)
|
|
},
|
|
{
|
|
label: '产品名称',
|
|
getValue: (row) => formatTempCellProductField(row, row.cellProductName)
|
|
},
|
|
{
|
|
label: '产品类型',
|
|
getValue: (row) => formatTempCellProductField(row, row.cellProductTypeName)
|
|
},
|
|
...commonTailFields
|
|
]
|
|
|
|
function buildCellStorageGroupContext(row: QcWorkOrder): string[] {
|
|
const parts: string[] = []
|
|
if (row.sampleTypeName) parts.push(row.sampleTypeName)
|
|
if (row.protocolNo) parts.push(`协议 ${row.protocolNo}`)
|
|
if (row.protocolStatus) {
|
|
parts.push(protocolStatusLabelBySource(String(row.protocolStatus), 'cell_storage'))
|
|
}
|
|
if (row.receptionTime) parts.push(`接收 ${row.receptionTime}`)
|
|
if (row.handlerName) parts.push(row.handlerName)
|
|
return parts
|
|
}
|
|
|
|
function buildDonationGroupContext(row: QcWorkOrder): string[] {
|
|
const parts: string[] = []
|
|
if (row.sampleTypeName) parts.push(row.sampleTypeName)
|
|
if (row.protocolNo) parts.push(`捐赠 ${row.protocolNo}`)
|
|
if (row.protocolStatus) {
|
|
parts.push(donationStatusLabel(String(row.protocolStatus)))
|
|
}
|
|
if (row.receptionTime) parts.push(`接收 ${row.receptionTime}`)
|
|
if (row.handlerName) parts.push(row.handlerName)
|
|
return parts
|
|
}
|
|
|
|
const outboundGroupedFields: CardMetaField[] = [
|
|
{ label: '质检对象', getValue: formatQcTarget, colSpan: 2 },
|
|
{
|
|
label: '关联生产工单',
|
|
getValue: (row) => row.productionWorkOrderNo || '—',
|
|
visible: (row) => (row.triggerSource || 'reception') === 'production'
|
|
},
|
|
...commonTailFields
|
|
]
|
|
|
|
function buildOutboundPilotGroupContext(row: QcWorkOrder): string[] {
|
|
const parts: string[] = []
|
|
if (row.applicationName) parts.push(row.applicationName)
|
|
if (row.channelName) parts.push(row.channelName)
|
|
if (row.patientName) parts.push(row.patientName)
|
|
if (row.infusionTime) parts.push(`输注 ${row.infusionTime}`)
|
|
return parts
|
|
}
|
|
|
|
function buildOutboundBasicExperimentGroupContext(row: QcWorkOrder): string[] {
|
|
const parts: string[] = []
|
|
const title = row.projectTitle || row.applicationName
|
|
if (title) parts.push(title)
|
|
if (row.customerName) parts.push(row.customerName)
|
|
if (row.infusionTime) parts.push(`交付 ${row.infusionTime}`)
|
|
return parts
|
|
}
|
|
|
|
const CARD_META_BY_TAB: Record<QcWorkOrderTabKey, QcWorkOrderCardMetaConfig> = {
|
|
inbound_cell_storage: {
|
|
tabKey: 'inbound_cell_storage',
|
|
listLayout: 'inbound-grouped',
|
|
showTriggerTag: true,
|
|
showProtocolFeeSummary: true,
|
|
showOutboundFeeSummary: false,
|
|
metaFields: inboundGroupedFields,
|
|
buildGroupContextParts: buildCellStorageGroupContext,
|
|
allowEditTemporary: false,
|
|
allowEditRemark: true,
|
|
allowDelete: true
|
|
},
|
|
inbound_research_donation: {
|
|
tabKey: 'inbound_research_donation',
|
|
listLayout: 'inbound-grouped',
|
|
showTriggerTag: true,
|
|
showProtocolFeeSummary: false,
|
|
showOutboundFeeSummary: false,
|
|
metaFields: inboundGroupedFields,
|
|
buildGroupContextParts: buildDonationGroupContext,
|
|
allowEditTemporary: false,
|
|
allowEditRemark: true,
|
|
allowDelete: true
|
|
},
|
|
outbound_pilot_service: {
|
|
tabKey: 'outbound_pilot_service',
|
|
listLayout: 'outbound-grouped',
|
|
showTriggerTag: true,
|
|
showProtocolFeeSummary: false,
|
|
showOutboundFeeSummary: false,
|
|
metaFields: outboundGroupedFields,
|
|
buildGroupContextParts: buildOutboundPilotGroupContext,
|
|
allowEditTemporary: false,
|
|
allowEditRemark: true,
|
|
allowDelete: false
|
|
},
|
|
outbound_basic_experiment: {
|
|
tabKey: 'outbound_basic_experiment',
|
|
listLayout: 'outbound-grouped',
|
|
showTriggerTag: true,
|
|
showProtocolFeeSummary: false,
|
|
showOutboundFeeSummary: true,
|
|
metaFields: outboundGroupedFields,
|
|
buildGroupContextParts: buildOutboundBasicExperimentGroupContext,
|
|
allowEditTemporary: false,
|
|
allowEditRemark: true,
|
|
allowDelete: false
|
|
},
|
|
outbound_clinical_application: {
|
|
tabKey: 'outbound_clinical_application',
|
|
listLayout: 'standalone',
|
|
showTriggerTag: false,
|
|
showProtocolFeeSummary: false,
|
|
showOutboundFeeSummary: true,
|
|
metaFields: outboundPilotClinicalFields,
|
|
buildGroupContextParts: () => [],
|
|
allowEditTemporary: false,
|
|
allowEditRemark: true,
|
|
allowDelete: false
|
|
},
|
|
temporary: {
|
|
tabKey: 'temporary',
|
|
listLayout: 'standalone',
|
|
showTriggerTag: false,
|
|
showProtocolFeeSummary: false,
|
|
showOutboundFeeSummary: false,
|
|
metaFields: temporaryFields,
|
|
buildGroupContextParts: () => [],
|
|
allowEditTemporary: true,
|
|
allowEditRemark: false,
|
|
allowDelete: true
|
|
}
|
|
}
|
|
|
|
export function getCardMetaConfig(tabKey: QcWorkOrderTabKey): QcWorkOrderCardMetaConfig {
|
|
return CARD_META_BY_TAB[tabKey]
|
|
}
|
|
|
|
export function buildGroupContextSubtitle(row: QcWorkOrder, tabKey: QcWorkOrderTabKey): string {
|
|
const parts = getCardMetaConfig(tabKey).buildGroupContextParts(row)
|
|
return parts.length ? parts.join(' · ') : '—'
|
|
}
|
|
|
|
export function cardMetaUsesInboundGroups(tabKey: QcWorkOrderTabKey): boolean {
|
|
return getQcWorkOrderTab(tabKey)?.listLayout === 'inbound-grouped'
|
|
}
|
|
|
|
export function cardMetaUsesOutboundGroups(tabKey: QcWorkOrderTabKey): boolean {
|
|
return getQcWorkOrderTab(tabKey)?.listLayout === 'outbound-grouped'
|
|
}
|
|
|
|
export function cardMetaUsesGroupedList(tabKey: QcWorkOrderTabKey): boolean {
|
|
const layout = getQcWorkOrderTab(tabKey)?.listLayout
|
|
return layout === 'inbound-grouped' || layout === 'outbound-grouped'
|
|
}
|