2026-10-21 16:58:38 +08:00
|
|
|
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
|
|
|
|
import type { DispatchStage } from '../dispatchContracts'
|
|
|
|
|
|
|
|
|
|
export const loadingPhotoSlots = ['LOADING_SCENE', 'LOADING_LIST', 'PRE_DEPARTURE_CHECK', 'DRIVER_LICENSE', 'RECEIPT'] as const
|
|
|
|
|
export type LoadingPhotoSlot = typeof loadingPhotoSlots[number]
|
2026-10-26 17:12:38 +08:00
|
|
|
export const loadingPhotoLabels: Record<LoadingPhotoSlot, string> = { LOADING_SCENE: '司机驾驶证', LOADING_LIST: '车牌照片', PRE_DEPARTURE_CHECK: '装车完成', DRIVER_LICENSE: '封车照片', RECEIPT: 'BOL司机签字' }
|
2026-10-21 16:58:38 +08:00
|
|
|
export interface LoadingPhoto { slot: LoadingPhotoSlot; fileId: string; fileName: string; contentType: string; savedAt: string | null }
|
2026-10-26 19:21:13 +08:00
|
|
|
export interface LoadingDocuments { dispatchNo: string; recordVersion: string; dispatchRecordVersion: string; reviewRound: string; stage: DispatchStage; editable: boolean; complete: boolean; photos: LoadingPhoto[] }
|
|
|
|
|
export interface BindLoadingPhoto { recordVersion: string; idempotencyKey: string; fileId: string; uploadKey: string; replaceFileId?: string }
|
2026-10-21 16:58:38 +08:00
|
|
|
const path = (no: string) => `/platform/v1/last-leg/dispatches/${encodeURIComponent(no)}/loading-documents`
|
|
|
|
|
export async function getLoadingDocuments(no: string) {
|
|
|
|
|
return unwrapApiResponse(await http.get<ApiEnvelope<LoadingDocuments>, ApiEnvelope<LoadingDocuments>>(path(no)))
|
|
|
|
|
}
|
2026-10-26 19:21:13 +08:00
|
|
|
export async function uploadLoadingPhoto(no: string, slot: LoadingPhotoSlot, file: File, key: string, reviewRound: string) {
|
|
|
|
|
const form = new FormData(); form.append('file', file); form.append('idempotencyKey', key); form.append('reviewRound', reviewRound)
|
2026-10-21 16:58:38 +08:00
|
|
|
return unwrapApiResponse(await http.post<ApiEnvelope<LoadingPhoto>, ApiEnvelope<LoadingPhoto>>(`${path(no)}/${slot}/uploads`, form))
|
|
|
|
|
}
|
|
|
|
|
export async function recoverLoadingPhoto(no: string, key: string) {
|
|
|
|
|
return unwrapApiResponse(await http.get<ApiEnvelope<LoadingPhoto>, ApiEnvelope<LoadingPhoto>>(`${path(no)}/uploads/${encodeURIComponent(key)}`))
|
|
|
|
|
}
|
|
|
|
|
export async function bindLoadingPhoto(no: string, slot: LoadingPhotoSlot, body: BindLoadingPhoto) {
|
|
|
|
|
return unwrapApiResponse(await http.put<ApiEnvelope<LoadingDocuments>, ApiEnvelope<LoadingDocuments>>(`${path(no)}/${slot}`, body))
|
|
|
|
|
}
|
|
|
|
|
export async function readLoadingPhoto(no: string, photo: LoadingPhoto) {
|
|
|
|
|
const blob = await http.get<Blob, Blob>(`${path(no)}/${photo.slot}/files/${encodeURIComponent(photo.fileId)}/content`, { responseType: 'blob' })
|
2026-10-26 18:52:21 +08:00
|
|
|
if (!(blob instanceof Blob) || !(['image/jpeg', 'image/png'].includes(blob.type) || photo.slot === 'LOADING_SCENE' && blob.type === 'application/pdf') || blob.type !== photo.contentType || !blob.size) throw new Error('资料读取失败,请重新核对')
|
2026-10-21 16:58:38 +08:00
|
|
|
return blob
|
|
|
|
|
}
|