66 lines
4.3 KiB
TypeScript
66 lines
4.3 KiB
TypeScript
import { regionText } from './procurementDirection'
|
|
import type { Amount, ProcurementFee } from './procurementTypes'
|
|
|
|
export const procurementStatuses: Record<string, string> = {
|
|
FUNDING_PENDING: '订单受理中', FUNDING_FAILED: '订单处理失败', PENDING_REVIEW: '待审核', RECEIVING: '收货中', WAIT_CUSTOMER_CONFIRM: '待客户确认', CONFIRMED: '已确认',
|
|
IN_TRANSIT: '运输中', DELIVERING: '派送中', COMPLETED: '签收完成',
|
|
REJECTED: '已拒绝', CANCELLED: '已取消',
|
|
}
|
|
export const feePurposes: Record<string, string> = {
|
|
SAMPLE_PAYMENT: '样品货款', INTERNATIONAL_ESTIMATE: '预估国际运费', INTERNATIONAL_FREIGHT: '实际国际运费',
|
|
DUTY: '关税', DOMESTIC_FREIGHT: '国内运费', OTHER: '其他费用', ADJUSTMENT: '追加费用', REFUND: '退款',
|
|
}
|
|
export function statusLabel(status: string | null | undefined, direction?: string | null) { return regionText(status ? procurementStatuses[status] || ({ EXCEPTION_CLOSED: '异常关闭' } as Record<string, string>)[status] || '待核对进度' : '—', direction) }
|
|
export function statusTone(status: string | null | undefined): 'success' | 'warning' | 'danger' | 'info' | 'primary' {
|
|
if (status === 'COMPLETED') return 'success'
|
|
if ((status === 'REJECTED' || status === 'FUNDING_FAILED') || status === 'EXCEPTION_CLOSED') return 'danger'
|
|
if (status === 'CANCELLED') return 'info'
|
|
if (status === 'IN_TRANSIT' || status === 'DELIVERING') return 'primary'
|
|
return 'warning'
|
|
}
|
|
export function cents(value: Amount | null | undefined): bigint | null {
|
|
if (value === null || value === undefined) return null
|
|
const match = /^(-?)(\d+)(?:\.(\d{1,2}))?$/.exec(String(value).trim())
|
|
if (!match) return null
|
|
const result = BigInt(match[2]) * 100n + BigInt((match[3] || '').padEnd(2, '0'))
|
|
return match[1] ? -result : result
|
|
}
|
|
export function decimal(value: bigint) {
|
|
const absolute = value < 0n ? -value : value
|
|
return `${value < 0n ? '-' : ''}${absolute / 100n}.${String(absolute % 100n).padStart(2, '0')}`
|
|
}
|
|
export function money(value: Amount | null | undefined, currency: string | null | undefined = 'CNY') {
|
|
const amount = cents(value)
|
|
return amount === null ? '—' : `${currency || '—'} ${decimal(amount)}`
|
|
}
|
|
export function dateTime(value: string | null | undefined) { return value ? value.replace('T', ' ').replace(/\.\d+$/, '') : '—' }
|
|
export function measurement(value: Amount | null | undefined, scale: number) {
|
|
if (value === null || value === undefined) return '—'
|
|
const parts = /^(\d+)(?:\.(\d+))?$/.exec(String(value))
|
|
if (!parts || (parts[2] || '').length > scale) return '待核对'
|
|
return `${parts[1]}.${(parts[2] || '').padEnd(scale, '0')}`
|
|
}
|
|
export function text(value: unknown) { return value === null || value === undefined || value === '' ? '—' : String(value) }
|
|
export function productHref(value: string | null | undefined) {
|
|
if (!value) return undefined
|
|
try { const url = new URL(value); return ['http:', 'https:'].includes(url.protocol) ? url.href : undefined } catch { return undefined }
|
|
}
|
|
export function feeStatus(fee: ProcurementFee) {
|
|
if (fee.purpose === 'INTERNATIONAL_ESTIMATE') {
|
|
const label: Record<string, string> = { FROZEN: '已冻结,未扣款', ZERO: '零预估已确认', SETTLED: '原预估已结清', RELEASED: '预估已释放' }
|
|
if (fee.walletStatus && label[fee.walletStatus]) return label[fee.walletStatus]
|
|
}
|
|
const labels: Record<string, string> = {
|
|
FREEZE_PENDING: '冻结处理中', FREEZE_FAILED: '冻结未成功', FROZEN: '等待扣款', SETTLE_PENDING: '扣款处理中', SETTLE_ACTUAL_PENDING: '实际费用结算中',
|
|
SETTLE_FAILED: '扣款未成功', SETTLE_ACTUAL_FAILED: '实际费用未结清', SETTLED: '已扣款', RELEASE_PENDING: '释放处理中', RELEASE_FAILED: '释放未成功',
|
|
RELEASED: '已释放冻结', REFUND_PENDING: '退款处理中', REFUND_FAILED: '退款未成功', REFUNDED: '已退款', ZERO: '已确认零元', NOT_APPLICABLE: '不适用', TERMINATED: '已终止',
|
|
}
|
|
return fee.walletStatus ? labels[fee.walletStatus] || '待核定' : '待核定'
|
|
}
|
|
export function feeTone(fee: ProcurementFee): 'success' | 'warning' | 'danger' | 'info' {
|
|
if (fee.walletStatus?.endsWith('_FAILED')) return 'danger'
|
|
if (['SETTLED', 'REFUNDED', 'ZERO', 'NOT_APPLICABLE', 'RELEASED'].includes(fee.walletStatus || '')) return 'success'
|
|
if (fee.walletStatus === 'TERMINATED') return 'info'
|
|
return 'warning'
|
|
}
|