export type ProcessingOwner = 'supplier' | 'warehouse'; export const PROCESSING_OWNER_SUPPLIER: ProcessingOwner = 'supplier'; export const PROCESSING_OWNER_WAREHOUSE: ProcessingOwner = 'warehouse'; export const PROCESSING_OWNER_OPTIONS: Array<{ value: ProcessingOwner; label: string; hint: string }> = [ { value: 'supplier', label: '供应商已加工', hint: '入库后直接分拣,不进加工管理', }, { value: 'warehouse', label: '仓内加工', hint: '入库后需加工管理与加工验收', }, ]; export function requiresWarehouseProcessing( method: string | null | undefined, owner: string | null | undefined ): boolean { const trimmedMethod = String(method || '').trim(); if (!trimmedMethod || trimmedMethod === '原材料') return false; return String(owner || '').trim().toLowerCase() === PROCESSING_OWNER_WAREHOUSE; } export function normalizeProcessingOwner( method: string | null | undefined, owner: string | null | undefined ): ProcessingOwner | null { const trimmedMethod = String(method || '').trim(); if (!trimmedMethod || trimmedMethod === '原材料') return null; const normalized = String(owner || '').trim().toLowerCase(); if (normalized === PROCESSING_OWNER_WAREHOUSE) return PROCESSING_OWNER_WAREHOUSE; return PROCESSING_OWNER_SUPPLIER; } export function defaultProcessingOwnerForMethod( method: string | null | undefined, preferred?: string | null ): ProcessingOwner | null { return normalizeProcessingOwner(method, preferred ?? PROCESSING_OWNER_SUPPLIER); } /** 订单管理详情:非原材料默认仓内加工(不改录单页的供应商默认) */ export function resolveOrderManageProcessingOwner( method: string | null | undefined, owner: string | null | undefined ): ProcessingOwner | null { if (!needsProcessingOwnerChoice(method)) return null; const normalized = String(owner || '').trim().toLowerCase(); if (normalized === PROCESSING_OWNER_SUPPLIER) return PROCESSING_OWNER_SUPPLIER; return PROCESSING_OWNER_WAREHOUSE; } export function processingOwnerLabel(owner: string | null | undefined): string { const normalized = String(owner || '').trim().toLowerCase(); if (normalized === PROCESSING_OWNER_WAREHOUSE) return '仓内加工'; if (normalized === PROCESSING_OWNER_SUPPLIER) return '供应商已加工'; return '-'; } export function needsProcessingOwnerChoice(method: string | null | undefined): boolean { const trimmed = String(method || '').trim(); return Boolean(trimmed && trimmed !== '原材料'); }