2026-10-21 16:58:44 +08:00
|
|
|
import { overseasRequest, overseasUpload, overseasDownload } from './overseas.js'
|
|
|
|
|
|
|
|
|
|
export const loadingPhotoSlots = ['LOADING_SCENE', 'LOADING_LIST', 'PRE_DEPARTURE_CHECK', 'DRIVER_LICENSE', 'RECEIPT']
|
2026-10-26 17:12:38 +08:00
|
|
|
// 保留既有五框标识以维持文件归属,界面按当前装车资料分类展示。
|
|
|
|
|
export const loadingPhotoLabels = { LOADING_SCENE: '司机驾驶证', LOADING_LIST: '车牌照片', PRE_DEPARTURE_CHECK: '装车完成', DRIVER_LICENSE: '封车照片', RECEIPT: 'BOL司机签字' }
|
|
|
|
|
export const loadingPhotoLimit = 5
|
2026-10-21 16:58:44 +08:00
|
|
|
const path = no => {
|
|
|
|
|
if (!no || typeof no !== 'string') throw new Error('请先打开排车任务')
|
|
|
|
|
return `/pda/v1/last-leg/dispatches/${encodeURIComponent(no)}/loading-documents`
|
|
|
|
|
}
|
|
|
|
|
function slotPath(no, slot) {
|
|
|
|
|
if (!loadingPhotoSlots.includes(slot)) throw new Error('装车照片框无效')
|
|
|
|
|
return `${path(no)}/${slot}`
|
|
|
|
|
}
|
|
|
|
|
export function normalizeLoadingDocuments(value, no) {
|
|
|
|
|
if (value?.dispatchNo !== no || !/^\d+$/.test(String(value.recordVersion ?? '')) || !Array.isArray(value.photos)
|
2026-10-21 17:27:13 +08:00
|
|
|
|| !['LOADING', 'AFTER_LOADING', 'DELIVERING', 'DELIVERED'].includes(value.stage)) throw new Error('装车资料与当前排车事实不一致')
|
2026-10-26 17:12:38 +08:00
|
|
|
const files = new Set(), counts = {}
|
2026-10-21 16:58:44 +08:00
|
|
|
for (const photo of value.photos) {
|
2026-10-26 17:12:38 +08:00
|
|
|
if (!loadingPhotoSlots.includes(photo.slot) || !photo.fileId || files.has(String(photo.fileId))) throw new Error('装车照片引用不完整或重复')
|
|
|
|
|
files.add(String(photo.fileId)); counts[photo.slot] = (counts[photo.slot] || 0) + 1
|
|
|
|
|
if (counts[photo.slot] > loadingPhotoLimit) throw new Error('每类装车照片最多5张')
|
2026-10-21 16:58:44 +08:00
|
|
|
}
|
|
|
|
|
return { ...value, editable: value.editable === true, complete: value.complete === true }
|
|
|
|
|
}
|
|
|
|
|
export async function getLoadingDocuments(no) { return normalizeLoadingDocuments(await overseasRequest('GET', path(no)), no) }
|
|
|
|
|
export function uploadLoadingPhoto(no, slot, filePath, key) { return overseasUpload(`${slotPath(no, slot)}/uploads?idempotencyKey=${encodeURIComponent(key)}`, filePath) }
|
|
|
|
|
export async function bindLoadingPhoto(no, slot, body) { return normalizeLoadingDocuments(await overseasRequest('PUT', slotPath(no, slot), body), no) }
|
|
|
|
|
export function readLoadingPhoto(no, photo) { return overseasDownload(`${slotPath(no, photo.slot)}/files/${encodeURIComponent(photo.fileId)}/content`, { expectedContentTypePrefix: 'image/' }) }
|