43 lines
3.5 KiB
TypeScript
43 lines
3.5 KiB
TypeScript
import type { DispatchAction, DispatchActions, DispatchDetail, ReviewAttachments, Reviews } from './dispatchContracts'
|
||
export const dispatchReviewAttachmentFields = [
|
||
{ key: 'vehicleFileIds', kind: 'VEHICLE', label: '车辆图片' },
|
||
{ key: 'driverPhotoFileIds', kind: 'DRIVER_PHOTO', label: '司机照片' },
|
||
{ key: 'licenseFileIds', kind: 'DRIVER', label: '驾驶证照片' },
|
||
] as const
|
||
export const emptyReviewAttachments = (): ReviewAttachments => ({ vehicleFileIds: [], driverPhotoFileIds: [], licenseFileIds: [] })
|
||
export function dispatchReviewEvidence(detail: DispatchDetail | null): ReviewAttachments {
|
||
const result = emptyReviewAttachments()
|
||
if (!detail) return result
|
||
result.vehicleFileIds = [...(detail.vehicleInfo.vehicle?.evidenceFileIds || [])]
|
||
result.driverPhotoFileIds = [...(detail.vehicleInfo.driver?.evidence?.photoFileIds || [])]
|
||
result.licenseFileIds = [...(detail.vehicleInfo.driver?.evidence?.fileIds || [])]
|
||
for (const { key } of dispatchReviewAttachmentFields) {
|
||
result[key] = [...new Set([...result[key], ...(detail.reviews.dispatchReview.attachments?.[key] || []), ...(detail.reviews.loadingReview.attachments?.[key] || [])])]
|
||
}
|
||
return result
|
||
}
|
||
export const dispatchActionLabels: Record<DispatchAction, string> = {
|
||
MARK_EXCEPTION: '标记异常', CREATE: '新建排车', EDIT: '维护车辆信息', ADD_CARGO: '添加货物', REMOVE_CARGO: '移除货物', CANCEL: '取消排车',
|
||
SUBMIT_REVIEW: '提交调度审核', DISPATCH_REVIEW: '调度审核', LOADING_REVIEW: '理货员审核',
|
||
RETURN_TO_REVIEW: '退回装车前重审', PICK: '拣货', LOADING_COMPLETE: '确认装车完成', ARRANGE_DELIVERY: '安排派送', DEPART: '确认发车',
|
||
}
|
||
export const dispatchActionPermissions: Record<DispatchAction, string> = {
|
||
MARK_EXCEPTION: 'platform:overseas-warehouse:dispatch:edit', CREATE: 'platform:overseas-warehouse:dispatch:create', EDIT: 'platform:overseas-warehouse:dispatch:edit',
|
||
ADD_CARGO: 'platform:overseas-warehouse:dispatch:edit', REMOVE_CARGO: 'platform:overseas-warehouse:dispatch:edit',
|
||
CANCEL: 'platform:overseas-warehouse:dispatch:cancel', SUBMIT_REVIEW: 'platform:overseas-warehouse:dispatch:edit',
|
||
DISPATCH_REVIEW: 'platform:fleet:trip:dispatch-review', LOADING_REVIEW: 'platform:fleet:trip:loading-review',
|
||
RETURN_TO_REVIEW: 'platform:overseas-warehouse:dispatch:edit', PICK: 'lastleg:pda:operate',
|
||
LOADING_COMPLETE: 'platform:overseas-warehouse:dispatch:loading-complete', ARRANGE_DELIVERY: 'platform:overseas-warehouse:dispatch:transfer-delivery', DEPART: 'platform:overseas-warehouse:dispatch:depart',
|
||
}
|
||
export const canDispatchAction = (actions: DispatchActions | undefined, action: DispatchAction, can: (code: string) => boolean) => !['ARRANGE_DELIVERY', 'DEPART'].includes(action) && actions?.[action]?.allowed === true && can(dispatchActionPermissions[action])
|
||
export const displayDispatchValue = (value: unknown) => value === null || value === undefined || value === '' ? '—' : String(value)
|
||
export function dispatchRejectionReason(reviews: Reviews | undefined): string {
|
||
if (!reviews) return ''
|
||
return ([['调度审核', reviews.dispatchReview], ['理货员审核', reviews.loadingReview]] as const)
|
||
.filter(([, review]) => review.status === 'REJECTED')
|
||
.map(([label, review]) => `${label}退回:${review.reason?.trim() || '原因未提供'}`).join(';')
|
||
}
|
||
|
||
export const dispatchExceptionLabels = { REFUSED: '拒收', PARTIAL_RECEIPT: '部分签收', VEHICLE_EXCEPTION: '车辆异常' } as const
|
||
export const dispatchReturnDirectionLabels = { OVERSEAS_WAREHOUSE: '退回海外仓', OTHER: '其他' } as const
|