This commit is contained in:
2026-08-07 18:44:58 +08:00
parent dd7aa0e4cf
commit aa6c349fce
9 changed files with 297 additions and 124 deletions
+26 -47
View File
@@ -4,46 +4,7 @@ import {
type FirstLegOrderStatus,
type FirstLegTransportMode,
} from '@chongchong/shared'
import type { CargoBoxSizeType, FirstLegCargoItem, FirstLegOrderDraft } from '../types/firstLegOrder.ts'
export const CARGO_BOX_SIZES = [
{ code: 'SMALL', label: '小箱', inner: '30 × 20 × 20', lengthCm: 34, widthCm: 24, heightCm: 24 },
{ code: 'MEDIUM', label: '中箱', inner: '40 × 30 × 30', lengthCm: 44, widthCm: 34, heightCm: 34 },
{ code: 'LARGE', label: '大箱', inner: '50 × 40 × 40', lengthCm: 54, widthCm: 44, heightCm: 44 },
{ code: 'EXTRA_LARGE', label: '特大箱', inner: '60 × 50 × 50', lengthCm: 64, widthCm: 54, heightCm: 54 },
] as const satisfies ReadonlyArray<{
code: Exclude<CargoBoxSizeType, ''>
label: string
inner: string
lengthCm: number
widthCm: number
heightCm: number
}>
export function inferCargoBoxSizeType(lengthCm?: number, widthCm?: number, heightCm?: number): CargoBoxSizeType {
return CARGO_BOX_SIZES.find((box) => box.lengthCm === lengthCm && box.widthCm === widthCm && box.heightCm === heightCm)?.code ?? ''
}
export function applyCargoBoxSize(item: FirstLegCargoItem, type: CargoBoxSizeType) {
item.boxSizeType = type
const box = CARGO_BOX_SIZES.find((option) => option.code === type)
if (!box) {
item.lengthCm = 0
item.widthCm = 0
item.heightCm = 0
item.volumeCbm = 0
return
}
item.lengthCm = box.lengthCm
item.widthCm = box.widthCm
item.heightCm = box.heightCm
updateCargoBoxVolume(item)
}
export function updateCargoBoxVolume(item: FirstLegCargoItem) {
if (!item.boxSizeType || item.packageCount <= 0) return
item.volumeCbm = Number(((item.lengthCm * item.widthCm * item.heightCm * item.packageCount) / 1_000_000).toFixed(3))
}
import type { FirstLegCargoItem, FirstLegOrderDraft } from '../types/firstLegOrder.ts'
const statusLabels = new Map<FirstLegOrderStatus, string>(
FIRST_LEG_ORDER_STATUSES.map((item) => [item.code, item.label]),
@@ -92,14 +53,31 @@ export function createEmptyCargoItem(id = `cargo-${Date.now()}`): FirstLegCargoI
upc: '',
cargoNameCn: '',
cargoNameEn: '',
productImageFileId: '',
productImageName: '',
productImagePreviewUrl: '',
productImageUploading: false,
productImageError: '',
customsHsCode: '',
lengthCm: 0,
widthCm: 0,
heightCm: 0,
unitsPerPackage: 1,
pieces: 1,
packageCount: 1,
grossWeightKg: 0,
volumeCbm: 0,
boxSizeType: '',
lengthCm: 0,
widthCm: 0,
heightCm: 0,
netWeightKg: 0,
unitDeclaredValue: 0,
material: '',
usage: '',
model: '',
brand: '',
productLengthCm: 0,
productWidthCm: 0,
productHeightCm: 0,
shipmentId: '',
referenceId: '',
containerType: '',
containerCount: 0,
remark: '',
@@ -138,19 +116,20 @@ export function validateFirstLegOrderDraft(draft: FirstLegOrderDraft) {
if (draft.items.length === 0) errors.push('请至少添加一条货物明细')
if (draft.destinationType === 'FBA') {
if (!draft.referenceNo.trim()) errors.push('FBA 订单请填写客户参考号')
if (!draft.amazonWarehouseCode.trim()) errors.push('FBA 订单请填写 Amazon 仓库编码')
if (!draft.shipmentId.trim()) errors.push('FBA 订单请填写 Shipment ID')
}
draft.items.forEach((item, index) => {
const line = `第 ${index + 1} 条货物`
if (!item.cargoNameCn.trim()) errors.push(`${line}缺少中文品名`)
if (!item.packageType.trim()) errors.push(`${line}缺少包装类型`)
if (!item.boxSizeType) errors.push(`${line}请选择箱规`)
if (draft.destinationType === 'FBA' && !item.sku.trim()) errors.push(`${line}缺少客户 SKU`)
if (draft.destinationType === 'FBA' && !item.upc.trim()) errors.push(`${line}缺少 UPC`)
if (draft.destinationType === 'FBA' && !item.shipmentId.trim()) errors.push(`${line}缺少 Shipment ID`)
if (draft.destinationType === 'FBA' && !item.referenceId.trim()) errors.push(`${line}缺少 Reference ID`)
if (!Number.isInteger(item.pieces) || item.pieces <= 0) errors.push(`${line}件数必须为正整数`)
if (!Number.isInteger(item.packageCount) || item.packageCount <= 0) errors.push(`${line}箱数必须为正整数`)
if (!Number.isInteger(item.unitsPerPackage) || item.unitsPerPackage <= 0) errors.push(`${line}每箱数量必须为正整数`)
if (item.grossWeightKg <= 0) errors.push(`${line}毛重必须大于 0`)
if (item.volumeCbm <= 0) errors.push(`${line}体积必须大于 0`)
if (draft.transportMode === 'FCL' && (!item.containerType || item.containerCount <= 0)) {