173 lines
5.3 KiB
TypeScript
173 lines
5.3 KiB
TypeScript
import type { ProductionWorkOrderItem } from '@/api/production-work-order'
|
||
|
||
export type ProductionWorkOrderTabKey =
|
||
| 'all'
|
||
| 'inbound_cell_storage'
|
||
| 'inbound_research_donation'
|
||
| 'outbound_pilot_service'
|
||
| 'outbound_basic_experiment'
|
||
| 'outbound_clinical_application'
|
||
| 'temporary'
|
||
|
||
export type ProductionWorkOrderTabGroup = 'all' | 'inbound' | 'outbound' | 'temporary'
|
||
|
||
export type ProductionWorkOrderTabConfig = {
|
||
key: ProductionWorkOrderTabKey
|
||
label: string
|
||
group: ProductionWorkOrderTabGroup
|
||
workOrderType: 'inbound' | 'outbound' | 'temporary'
|
||
receptionSource?: 'cell_storage' | 'research_donation'
|
||
bizType?: 'pilot_service' | 'basic_experiment' | 'clinical_application'
|
||
listLayout: 'inbound-grouped' | 'standalone'
|
||
/** 侧栏 Tab 不展示(保留 key 供路由/数据解析) */
|
||
hidden?: boolean
|
||
}
|
||
|
||
export const PRODUCTION_WORK_ORDER_TABS: ProductionWorkOrderTabConfig[] = [
|
||
{
|
||
key: 'all',
|
||
label: '所有',
|
||
group: 'all',
|
||
workOrderType: 'inbound',
|
||
listLayout: 'inbound-grouped'
|
||
},
|
||
{
|
||
key: 'inbound_cell_storage',
|
||
label: '细胞存储生产',
|
||
group: 'inbound',
|
||
workOrderType: 'inbound',
|
||
receptionSource: 'cell_storage',
|
||
listLayout: 'inbound-grouped'
|
||
},
|
||
{
|
||
key: 'inbound_research_donation',
|
||
label: '科研捐赠生产',
|
||
group: 'inbound',
|
||
workOrderType: 'inbound',
|
||
receptionSource: 'research_donation',
|
||
listLayout: 'inbound-grouped'
|
||
},
|
||
{
|
||
key: 'outbound_pilot_service',
|
||
label: '中试服务生产',
|
||
group: 'outbound',
|
||
workOrderType: 'outbound',
|
||
bizType: 'pilot_service',
|
||
listLayout: 'standalone'
|
||
},
|
||
{
|
||
key: 'outbound_basic_experiment',
|
||
label: '基础实验生产',
|
||
group: 'outbound',
|
||
workOrderType: 'outbound',
|
||
bizType: 'basic_experiment',
|
||
listLayout: 'standalone'
|
||
},
|
||
{
|
||
key: 'outbound_clinical_application',
|
||
label: '临床应用生产',
|
||
group: 'outbound',
|
||
workOrderType: 'outbound',
|
||
bizType: 'clinical_application',
|
||
listLayout: 'standalone',
|
||
hidden: true
|
||
},
|
||
{
|
||
key: 'temporary',
|
||
label: '临时生产',
|
||
group: 'temporary',
|
||
workOrderType: 'temporary',
|
||
listLayout: 'standalone'
|
||
}
|
||
]
|
||
|
||
/** 生产工单 / 我的生产任务 Tab 栏展示项(不含 hidden) */
|
||
export const PRODUCTION_WORK_ORDER_VISIBLE_TABS = PRODUCTION_WORK_ORDER_TABS.filter(
|
||
(t) => !t.hidden
|
||
)
|
||
|
||
export const DEFAULT_PRODUCTION_WORK_ORDER_TAB: ProductionWorkOrderTabKey = 'all'
|
||
|
||
export function getProductionWorkOrderTab(key: string): ProductionWorkOrderTabConfig | undefined {
|
||
return PRODUCTION_WORK_ORDER_TABS.find((t) => t.key === key)
|
||
}
|
||
|
||
export function parseProductionWorkOrderTabKey(raw?: string | null): ProductionWorkOrderTabKey {
|
||
const k = (raw || '').trim()
|
||
const tab = getProductionWorkOrderTab(k)
|
||
if (tab && !tab.hidden) return tab.key
|
||
if (k === 'inbound') return 'inbound_cell_storage'
|
||
if (k === 'outbound') return 'outbound_pilot_service'
|
||
if (k === 'temporary') return 'temporary'
|
||
return DEFAULT_PRODUCTION_WORK_ORDER_TAB
|
||
}
|
||
|
||
export function toWorkOrderListQuery(tab: ProductionWorkOrderTabConfig) {
|
||
if (tab.key === 'all') {
|
||
return {
|
||
workOrderType: undefined as string | undefined,
|
||
receptionSource: undefined as string | undefined,
|
||
bizType: undefined as string | undefined
|
||
}
|
||
}
|
||
return {
|
||
workOrderType: tab.workOrderType,
|
||
receptionSource: tab.receptionSource,
|
||
bizType: tab.bizType
|
||
}
|
||
}
|
||
|
||
export function resolveTabKeyFromWorkOrder(row: {
|
||
workOrderType?: string
|
||
receptionSource?: string
|
||
bizType?: string
|
||
}): ProductionWorkOrderTabKey {
|
||
const wt = row.workOrderType || 'inbound'
|
||
if (wt === 'temporary') return 'temporary'
|
||
if (wt === 'outbound') {
|
||
const bt = row.bizType || 'pilot_service'
|
||
if (bt === 'basic_experiment') return 'outbound_basic_experiment'
|
||
if (bt === 'clinical_application') return 'outbound_clinical_application'
|
||
return 'outbound_pilot_service'
|
||
}
|
||
return row.receptionSource === 'research_donation'
|
||
? 'inbound_research_donation'
|
||
: 'inbound_cell_storage'
|
||
}
|
||
|
||
export function keywordPlaceholderForTab(tab: ProductionWorkOrderTabConfig): string {
|
||
if (tab.key === 'all') return '工单号 / 样本编码 / 申请单号 / 产品名称等'
|
||
if (tab.key === 'temporary') return '工单号'
|
||
if (tab.key === 'outbound_basic_experiment') {
|
||
return '工单号/申请单号/课题名称/客户'
|
||
}
|
||
if (tab.group === 'outbound') return '工单号/申请单号/申请单名称/患者'
|
||
return '工单号/样本编码/入库编码'
|
||
}
|
||
|
||
export function workOrderMatchesTab(
|
||
row: ProductionWorkOrderItem,
|
||
tabKey: ProductionWorkOrderTabKey
|
||
): boolean {
|
||
if (tabKey === 'all') return true
|
||
return resolveTabKeyFromWorkOrder(row) === tabKey
|
||
}
|
||
|
||
export function isAllProductionWorkOrderTab(tabKey: ProductionWorkOrderTabKey): boolean {
|
||
return tabKey === 'all'
|
||
}
|
||
|
||
/** 列表 Tab 为「所有」时,按工单解析其分类 Tab Key */
|
||
export function resolveEffectiveRowTabKey(
|
||
listTabKey: ProductionWorkOrderTabKey,
|
||
row: ProductionWorkOrderItem
|
||
): ProductionWorkOrderTabKey {
|
||
return isAllProductionWorkOrderTab(listTabKey) ? resolveTabKeyFromWorkOrder(row) : listTabKey
|
||
}
|
||
|
||
export function tabSupportsInactiveProtocolFilter(tabKey: ProductionWorkOrderTabKey): boolean {
|
||
return (
|
||
tabKey === 'all' || tabKey === 'inbound_cell_storage' || tabKey === 'inbound_research_donation'
|
||
)
|
||
}
|