Files
zkxw/web-admin/src/utils/production-work-order-tabs.ts
T
cykjandCursor c22a0d1eb0 feat(market): 完善临床科研与委托加工上线能力
补齐项目组负责人审批、费用信息、合作客户、生产出库菜单、申请单号 LCKY 前缀及配套 SQL 迁移,并同步相关前后端与单测。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-30 18:51:37 +08:00

193 lines
6.0 KiB
TypeScript
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.
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_contract_processing'
| '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' | 'contract_processing' | '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',
/** 与市场中试菜单一致:侧栏 Tab 隐藏,保留 key 供历史工单解析 */
hidden: true
},
{
key: 'outbound_basic_experiment',
label: '临床科研生产',
group: 'outbound',
workOrderType: 'outbound',
bizType: 'basic_experiment',
listLayout: 'standalone'
},
{
key: 'outbound_contract_processing',
label: '委托加工生产',
group: 'outbound',
workOrderType: 'outbound',
bizType: 'contract_processing',
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_basic_experiment'
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 === 'contract_processing') return 'outbound_contract_processing'
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' || tab.key === 'outbound_contract_processing') {
return '工单号/申请单号/课题名称/客户'
}
if (tab.group === 'outbound') return '工单号/申请单号/申请单名称/患者'
return '工单号/样本编码/入库编码'
}
/** 出库中试服务(含 bizType 缺省落成中试) */
export function isPilotServiceOutboundWorkOrder(row: {
workOrderType?: string
bizType?: string
}): boolean {
return resolveTabKeyFromWorkOrder(row) === 'outbound_pilot_service'
}
export function workOrderMatchesTab(
row: ProductionWorkOrderItem,
tabKey: ProductionWorkOrderTabKey
): boolean {
if (tabKey === 'all') return !isPilotServiceOutboundWorkOrder(row)
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'
)
}