34 lines
2.7 KiB
TypeScript
34 lines
2.7 KiB
TypeScript
import { overseasHttp } from '@/shared/api/overseasHttp'
|
|||
|
|
import { 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) {
|
||
|
|
return unwrapApiResponse(await overseasHttp.get<ApiEnvelope<DeliveryDocuments>, ApiEnvelope<DeliveryDocuments>>(path(deliveryNo), { params: { customerId } }))
|
||
|
|
}
|
||
|
|
export async function saveDeliveryDocuments(deliveryNo: string, customerId: string, body: SaveDeliveryDocuments) {
|
||
|
|
return unwrapApiResponse(await overseasHttp.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)
|
||
|
|
return unwrapApiResponse(await overseasHttp.post<ApiEnvelope<DeliveryDocumentFile>, ApiEnvelope<DeliveryDocumentFile>>(`${path(deliveryNo)}/${category}/files`, body, { params: { customerId } }))
|
||
|
|
}
|
||
|
|
export async function downloadDeliveryDocument(deliveryNo: string, customerId: string, category: DeliveryDocumentCategory, fileId: string) {
|
||
|
|
return overseasHttp.get<Blob, Blob>(`${path(deliveryNo)}/${category}/files/${encodeURIComponent(fileId)}/download`, { params: { customerId }, responseType: 'blob' })
|
||
|
|
}
|