Files
client-web/src/modules/cross-border/api/procurement.ts
T
2026-10-27 17:39:28 +08:00

150 lines
4.6 KiB
TypeScript

import { apiBlobRequest, apiRequest } from '@/api/http'
import type { PageResult } from './businessOrders'
export type Amount = number | string
export interface ProcurementSummary {
procurementDirection?: import('../procurementPresentation').ProcurementDirection
orderNo: string
purchaseCategory: string
productName: string
productSpecification: string | null
purchaseQuantity: number
budgetUnitPrice: Amount | null
currency: string | null
status: string
version: number
createdAt: string
updatedAt: string
}
export interface ProcurementOrder extends ProcurementSummary {
productUrl: string | null
receivingAddress: string
contactName: string
contactPhone: string
estimatedArrivalAt: string | null
plannedWarehouseName: string | null
actualWarehouseCode: string | null
actualWarehouseName: string | null
}
export interface ProcurementFee {
feeNo: string
purpose: string
name: string
version: number | null
active: boolean
determination: string
amount: Amount
currency: string
originalAmount: Amount | null
originalCurrency: string | null
exchangeRate: Amount | null
exchangeRateMonth: string | null
businessDate: string | null
parentFeeNo: string | null
walletStatus: string | null
sourceLinked: boolean
}
export interface ProcurementBox {
cartonNo: string
quantity: number
lengthCm: Amount
widthCm: Amount
heightCm: Amount
grossWeightKg: Amount
}
export interface ProcurementShipment {
shipmentNo: string
leg: 'OVERSEAS' | 'DOMESTIC'
shippedAt: string
cartonNo: string
quantity: number
carrier: string
trackingNo: string
}
export interface ProcurementDetail {
order: ProcurementOrder
budget: { totalAmount: Amount | null; currency: string; authorizedAt: string | null }
purchased: boolean
purchaseConfirmed: boolean
purchaseNeedsAttention: boolean
progress: { key: string; title: string; completedAt: string | null }[]
boxes: ProcurementBox[]
shipments: ProcurementShipment[]
fees: ProcurementFee[]
exceptionSummaries: string[]
}
export interface ProcurementCreate {
procurementDirection?: import('../procurementPresentation').ProcurementDirection
customerName: string
purchaseCategory: string
productName: string
productSpecification?: string
productUrl?: string
purchaseQuantity: number
budgetUnitPrice: number
currency: 'CNY' | 'USD'
receivingAddress: string
contactName: string
contactPhone: string
remark?: string
idempotencyKey: string
}
export interface ProcurementQuery {
page: number
size: number
orderNo?: string
productName?: string
purchaseCategory?: string
status?: string
}
export interface ProcurementWorkflowFile { fileId: string; fileName: string; contentType: string }
export interface ProcurementReceipt {
id: string
quantity: number
fileIds: string[]
receivedAt: string
}
export interface ProcurementOutbound {
id: string
outboundNo: string
quantity: number
trackingNo: string
status: string
fileIds: string[]
createdAt: string
completedAt: string | null
}
export interface ProcurementWorkflow {
orderNo: string
version: number
status: string
receivedQuantity: number
stockQuantity: number
reservedQuantity: number
availableQuantity: number
files: ProcurementWorkflowFile[]
receipts: ProcurementReceipt[]
outbounds: ProcurementOutbound[]
}
const endpoint = '/merchant/v1/last-leg/overseas-procurements'
export async function listProcurements(params: ProcurementQuery) {
const result = await apiRequest<PageResult<ProcurementSummary>>({ method: 'GET', url: endpoint, params })
return { ...result, page: Number(result.page), size: Number(result.size), total: Number(result.total), pages: Number(result.pages) }
}
export function getProcurement(orderNo: string) {
return apiRequest<ProcurementDetail>({ method: 'GET', url: `${endpoint}/${encodeURIComponent(orderNo)}` })
}
export function createProcurement(data: ProcurementCreate) {
return apiRequest<ProcurementDetail>({ method: 'POST', url: endpoint, data })
}
export function getProcurementWorkflow(orderNo: string) {
return apiRequest<ProcurementWorkflow>({ method: 'GET', url: `${endpoint}/${encodeURIComponent(orderNo)}/workflow` })
}
export function confirmProcurement(orderNo: string, data: { version: number; idempotencyKey: string }) {
return apiRequest<ProcurementWorkflow>({ method: 'POST', url: `${endpoint}/${encodeURIComponent(orderNo)}/confirm`, data })
}
export function getProcurementFile(orderNo: string, fileId: string) {
return apiBlobRequest({ method: 'GET', url: `${endpoint}/${encodeURIComponent(orderNo)}/files/${encodeURIComponent(fileId)}/content` })
}