Files
admin-web/src/modules/overseas-warehouse/api/deliveryDocuments.ts
T

34 lines
2.6 KiB
TypeScript
Raw Normal View History

2026-09-29 17:56:00 +08:00
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
export const deliveryDocumentCategories = [
{ category: 'LOADING_PHOTO', label: '装车照片' },
{ category: 'BOL', label: 'BOL文件(含签名)' },
{ category: 'RECEIPT', label: '签收文件(POD签收/快递签收)' },
] as const
export type DeliveryDocumentCategory = typeof deliveryDocumentCategories[number]['category']
export interface DeliveryDocumentFile { fileId: string; fileName: string; contentType: string | null; sizeBytes: number; uploadedAt: string }
export interface DeliveryDocumentCategorySummary { category: DeliveryDocumentCategory; status: 'UPLOADED' | 'MISSING'; fileCount: number }
export interface DeliveryDocumentSummary { uploadedCategoryCount: number; totalCategoryCount: number; categories: DeliveryDocumentCategorySummary[] }
export interface DeliveryDocuments extends DeliveryDocumentSummary {
deliveryNo: string; customerId: string; version: number; bolNo: string | null
categories: Array<DeliveryDocumentCategorySummary & { files: DeliveryDocumentFile[] }>
allowedActions: string[]; replayed: boolean
}
export interface SaveDeliveryDocuments { expectedVersion: number; idempotencyKey: string; bolNo: string | null; documents: Array<{ category: DeliveryDocumentCategory; fileIds: string[] }> }
const path = (deliveryNo: string) => `/platform/v1/last-leg/delivery-orders/${encodeURIComponent(deliveryNo)}/documents`
export async function getDeliveryDocuments(deliveryNo: string, customerId: string) {
2026-09-29 17:56:00 +08:00
return unwrapApiResponse(await http.get<ApiEnvelope<DeliveryDocuments>, ApiEnvelope<DeliveryDocuments>>(path(deliveryNo), { params: { customerId } }))
}
export async function saveDeliveryDocuments(deliveryNo: string, customerId: string, body: SaveDeliveryDocuments) {
2026-09-29 17:56:00 +08:00
return unwrapApiResponse(await http.put<ApiEnvelope<DeliveryDocuments>, ApiEnvelope<DeliveryDocuments>>(path(deliveryNo), body, { params: { customerId } }))
}
export async function uploadDeliveryDocument(deliveryNo: string, customerId: string, category: DeliveryDocumentCategory, file: File) {
const body = new FormData()
body.append('file', file)
2026-09-29 17:56:00 +08:00
return unwrapApiResponse(await http.post<ApiEnvelope<DeliveryDocumentFile>, ApiEnvelope<DeliveryDocumentFile>>(`${path(deliveryNo)}/${category}/files`, body, { params: { customerId } }))
}
export async function downloadDeliveryDocument(deliveryNo: string, customerId: string, category: DeliveryDocumentCategory, fileId: string) {
2026-09-29 17:56:00 +08:00
return http.get<Blob, Blob>(`${path(deliveryNo)}/${category}/files/${encodeURIComponent(fileId)}/download`, { params: { customerId }, responseType: 'blob' })
}