147 lines
4.3 KiB
TypeScript
147 lines
4.3 KiB
TypeScript
import { apiRequest } from '@/api/http'
|
|
|
|
export interface PageResult<T> {
|
|
records: T[]
|
|
page: number
|
|
size: number
|
|
total: number
|
|
pages: number
|
|
}
|
|
|
|
export type CrossBorderBusinessKind = 'trucking' | 'looseboard'
|
|
|
|
export interface BusinessOrderQuery {
|
|
page: number
|
|
size: number
|
|
orderNo?: string
|
|
status?: string
|
|
routeKeyword?: string
|
|
transportType?: string
|
|
vehicleType?: 'PALLET_15' | 'PALLET_30'
|
|
pickupFrom?: string
|
|
pickupTo?: string
|
|
requestedFrom?: string
|
|
requestedTo?: string
|
|
createdFrom?: string
|
|
createdTo?: string
|
|
}
|
|
|
|
export interface TransportSummary {
|
|
fleetArrangement: import('../fleetArrangement').FleetArrangement | null
|
|
orderNo: string
|
|
transportType?: string
|
|
palletRequired?: string | null
|
|
origin: string
|
|
destination: string
|
|
palletCount?: number
|
|
packageCount: number
|
|
totalWeightKg: number
|
|
totalVolumeCbm: number
|
|
budgetAmount: number | null
|
|
currency: string | null
|
|
productName?: string | null
|
|
estimatedPalletCount?: number | null
|
|
vehicleType?: 'PALLET_15' | 'PALLET_30' | null
|
|
originContactName?: string | null
|
|
originContactPhone?: string | null
|
|
destinationContactName?: string | null
|
|
destinationContactPhone?: string | null
|
|
pickupAt?: string | null
|
|
deliveryAt?: string | null
|
|
status: string
|
|
version: number
|
|
createdAt: string
|
|
updatedAt: string
|
|
}
|
|
|
|
export interface TransportDetail {
|
|
summary: TransportSummary
|
|
originAddress: string | null
|
|
destinationAddress: string | null
|
|
remark: string | null
|
|
}
|
|
|
|
export interface TransportCreate {
|
|
productName?: string
|
|
estimatedPalletCount: number
|
|
origin: string
|
|
originAddress?: string
|
|
destination: string
|
|
destinationAddress?: string
|
|
packageCount: number
|
|
totalWeightKg: number
|
|
totalVolumeCbm: number
|
|
budgetAmount?: number
|
|
currency?: string
|
|
originContactName: string
|
|
originContactPhone: string
|
|
destinationContactName: string
|
|
destinationContactPhone: string
|
|
pickupAt: string
|
|
deliveryAt: string
|
|
remark?: string
|
|
idempotencyKey: string
|
|
}
|
|
|
|
export interface TruckCreate {
|
|
vehicleType: 'PALLET_15' | 'PALLET_30'
|
|
origin: string
|
|
originAddress?: string
|
|
destination: string
|
|
destinationAddress?: string
|
|
originContactName: string
|
|
originContactPhone: string
|
|
destinationContactName: string
|
|
destinationContactPhone: string
|
|
pickupAt: string
|
|
deliveryAt: string
|
|
packageCount: number
|
|
totalWeightKg: number
|
|
totalVolumeCbm: number
|
|
budgetAmount?: number
|
|
currency?: string
|
|
remark?: string
|
|
idempotencyKey: string
|
|
}
|
|
|
|
export interface TransportUpdate extends Omit<TransportCreate, 'idempotencyKey'> {
|
|
version: number
|
|
}
|
|
|
|
export interface TruckUpdate extends Omit<TruckCreate, 'idempotencyKey'> {
|
|
version: number
|
|
}
|
|
|
|
const endpointByKind: Record<CrossBorderBusinessKind, string> = {
|
|
trucking: '/merchant/v1/last-leg/us-truck-orders',
|
|
looseboard: '/merchant/v1/last-leg/local-looseboard-orders',
|
|
}
|
|
|
|
function normalizePage<T>(data: PageResult<T>): PageResult<T> {
|
|
return { ...data, page: Number(data.page), size: Number(data.size), total: Number(data.total), pages: Number(data.pages) }
|
|
}
|
|
|
|
export function listBusinessOrders<T>(kind: CrossBorderBusinessKind, params: BusinessOrderQuery) {
|
|
return apiRequest<PageResult<T>>({ method: 'GET', url: endpointByKind[kind], params }).then(normalizePage)
|
|
}
|
|
|
|
export function getBusinessOrder<T>(kind: CrossBorderBusinessKind, orderNo: string) {
|
|
return apiRequest<T>({ method: 'GET', url: `${endpointByKind[kind]}/${encodeURIComponent(orderNo)}` })
|
|
}
|
|
|
|
export function createTransport(kind: 'trucking', payload: TruckCreate): Promise<TransportDetail>
|
|
export function createTransport(kind: 'looseboard', payload: TransportCreate): Promise<TransportDetail>
|
|
export function createTransport(kind: CrossBorderBusinessKind, payload: TransportCreate | TruckCreate) {
|
|
return apiRequest<TransportDetail>({ method: 'POST', url: endpointByKind[kind], data: payload })
|
|
}
|
|
|
|
export function updateTransport(kind: 'trucking', orderNo: string, payload: TruckUpdate): Promise<TransportDetail>
|
|
export function updateTransport(kind: 'looseboard', orderNo: string, payload: TransportUpdate): Promise<TransportDetail>
|
|
export function updateTransport(kind: CrossBorderBusinessKind, orderNo: string, payload: TransportUpdate | TruckUpdate) {
|
|
return apiRequest<TransportDetail>({
|
|
method: kind === 'trucking' ? 'PATCH' : 'PUT',
|
|
url: `${endpointByKind[kind]}/${encodeURIComponent(orderNo)}`,
|
|
data: payload,
|
|
})
|
|
}
|