Files
zkxw/web-admin/src/utils/qc-work-order-category.ts
T
cykjandCursor 9b5e68f4ae feat(market): 新增委托加工业务并复用临床科研流程
独立 biz_type=contract_processing,申请/缴费/出库与临床科研共用逻辑;
业务子类型支持胎盘冻干粉/脂肪外泌体/NK/MSC/其他自定义,并补充菜单与生产质检 Tab。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-23 12:28:23 +08:00

119 lines
3.9 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 { QcWorkOrder } from '@/api/qc-work-order'
import { isTemporaryQcFromProduction } from '@/utils/qc-work-order-groups'
import type { TagType } from '@/utils/status-tag-registry'
import {
resolveTabKeyFromWorkOrder,
type QcWorkOrderTabKey,
getQcWorkOrderTab,
QC_WORK_ORDER_VISIBLE_TABS
} from '@/utils/qc-work-order-tabs'
/** 「所有」Tab 内质检类型子筛选(不含 all / hidden clinical) */
export type QcWorkOrderCategoryKey = Exclude<
QcWorkOrderTabKey,
'all' | 'outbound_clinical_application'
>
export const QC_WORK_ORDER_CATEGORY_OPTIONS: { key: QcWorkOrderCategoryKey; label: string }[] =
QC_WORK_ORDER_VISIBLE_TABS.filter((t) => t.key !== 'all').map((t) => ({
key: t.key as QcWorkOrderCategoryKey,
label: t.label.replace(/质检$/, '')
}))
const CATEGORY_LABELS: Record<QcWorkOrderCategoryKey, string> = {
inbound_cell_storage: '细胞存储',
inbound_research_donation: '科研捐赠',
outbound_pilot_service: '中试服务',
outbound_basic_experiment: '临床科研',
outbound_contract_processing: '委托加工',
temporary: '临时'
}
const CATEGORY_TAG_TYPES: Record<QcWorkOrderCategoryKey, TagType> = {
inbound_cell_storage: 'primary',
inbound_research_donation: 'primary',
outbound_pilot_service: 'info',
outbound_basic_experiment: 'info',
outbound_contract_processing: 'info',
temporary: 'warning'
}
export function resolveWorkOrderCategoryKey(row: {
workOrderType?: string
receptionSource?: string
bizType?: string
}): QcWorkOrderCategoryKey {
const tabKey = resolveTabKeyFromWorkOrder(row)
if (tabKey === 'outbound_clinical_application') return 'outbound_pilot_service'
return tabKey as QcWorkOrderCategoryKey
}
export function qcWorkOrderCategoryLabel(row: QcWorkOrder): string {
return CATEGORY_LABELS[resolveWorkOrderCategoryKey(row)] || '—'
}
export function qcWorkOrderCategoryTagType(row: QcWorkOrder): TagType {
return CATEGORY_TAG_TYPES[resolveWorkOrderCategoryKey(row)] || 'info'
}
/** 「所有」Tab 工单来源筛选项 value(含临时专用值) */
export const QC_ALL_TAB_TRIGGER_SOURCE_OPTIONS = [
{ label: '样本接收', value: 'reception' },
{ label: '计划质检', value: 'schedule' },
{ label: '生产过程', value: 'production' },
{ label: '生产派发', value: 'temp_production' },
{ label: '手动创建', value: 'temp_manual' }
] as const
export type QcAllTabTriggerSource = (typeof QC_ALL_TAB_TRIGGER_SOURCE_OPTIONS)[number]['value']
export function toAllTabListQuery(categoryKey: string) {
const key = (categoryKey || '').trim()
if (!key) {
return {
workOrderType: undefined as string | undefined,
receptionSource: undefined as string | undefined,
bizType: undefined as string | undefined
}
}
const tab = getQcWorkOrderTab(key)
if (!tab || tab.key === 'all') {
return {
workOrderType: undefined,
receptionSource: undefined,
bizType: undefined
}
}
return {
workOrderType: tab.workOrderType,
receptionSource: tab.receptionSource,
bizType: tab.bizType
}
}
export function workOrderMatchesCategory(row: QcWorkOrder, categoryKey: string): boolean {
const key = (categoryKey || '').trim()
if (!key) return true
return resolveWorkOrderCategoryKey(row) === key
}
export function matchesAllTabTriggerSource(row: QcWorkOrder, value?: string): boolean {
const filterValue = (value || '').trim()
if (!filterValue) return true
const wt = row.workOrderType || 'inbound'
const ts = row.triggerSource || 'reception'
if (filterValue === 'reception' || filterValue === 'schedule') {
return ts === filterValue
}
if (filterValue === 'production') {
return wt !== 'temporary' && ts === 'production'
}
if (filterValue === 'temp_production') {
return wt === 'temporary' && isTemporaryQcFromProduction(row)
}
if (filterValue === 'temp_manual') {
return wt === 'temporary' && !isTemporaryQcFromProduction(row)
}
return ts === filterValue
}