export const SF_TRANSPORT_MODE = 'sfkd' export function isSfExpress(mode: string | null | undefined) { return String(mode || '').trim() === SF_TRANSPORT_MODE } export function freightAmountText( mode: string | null | undefined, amount: number | string | null | undefined ) { if (isSfExpress(mode) && (amount === null || amount === undefined || amount === '')) return '月结' if (amount === null || amount === undefined || amount === '') return '' const value = Number(amount) if (!Number.isFinite(value)) return '' return value.toFixed(2) } export function validateFreightHeader(input: { transportMode: string freightAmount: number | null waybillNo: string }) { if (!String(input.transportMode || '').trim()) return '请选择运输方式' if (isSfExpress(input.transportMode)) { const waybill = String(input.waybillNo || '').trim() if (!waybill) return '请填写顺丰单号' if (waybill.length > 64) return '顺丰单号不能超过 64 个字符' return '' } if ( input.freightAmount == null || !Number.isFinite(Number(input.freightAmount)) || Number(input.freightAmount) < 0 ) { return '请填写运费' } return '' } export function buildFreightHeaderPayload(input: { transportMode: string freightAmount: number | null waybillNo: string }) { const sf = isSfExpress(input.transportMode) return { transportMode: String(input.transportMode || '').trim(), waybillNo: sf ? String(input.waybillNo || '').trim() : '', freightAmount: sf ? null : Number(input.freightAmount) } } export function buildSettlePayload(ids: string[], freightAmount: string) { const payload: { ids: string[]; freightAmount?: number } = { ids } if (ids.length === 1 && String(freightAmount || '').trim()) { payload.freightAmount = Number(String(freightAmount).trim()) } return payload }