优化
This commit is contained in:
+7
-6
@@ -1,17 +1,18 @@
|
||||
import { overseasRequest, overseasUpload } from '@/api/overseas.js'
|
||||
import { normalizeReceivingCandidate, normalizeReceivingSession } from '@/api/receiving-adapter.js'
|
||||
|
||||
const RECEIVING_BASE = '/pda/v1/last-leg/receiving-containers'
|
||||
const current = (suffix = '') => `${RECEIVING_BASE}/current${suffix}`
|
||||
|
||||
export const listReceivingCandidates = () => overseasRequest('GET', `${RECEIVING_BASE}/candidates`)
|
||||
export const getReceivingContainer = (containerNo) => overseasRequest('GET', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}`)
|
||||
export const prepareReceivingContainer = (containerNo, request) => overseasRequest('POST', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}/prepare`, request)
|
||||
export const listReceivingCandidates = async () => (await overseasRequest('GET', `${RECEIVING_BASE}/candidates`)).map(normalizeReceivingCandidate)
|
||||
export const getReceivingContainer = async (containerNo) => normalizeReceivingSession(await overseasRequest('GET', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}`))
|
||||
export const prepareReceivingContainer = async (containerNo, request) => normalizeReceivingSession(await overseasRequest('POST', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}/prepare`, request))
|
||||
export const uploadCurrentUnloadPhoto = (filePath) => overseasUpload(current('/unload-photos/files'), filePath)
|
||||
export const signCurrentReceiving = (request) => overseasRequest('POST', current('/sign'), request)
|
||||
export const getCurrentReceiving = () => overseasRequest('GET', current())
|
||||
export const signCurrentReceiving = async (request) => normalizeReceivingSession(await overseasRequest('POST', current('/sign'), request))
|
||||
export const getCurrentReceiving = async () => normalizeReceivingSession(await overseasRequest('GET', current()))
|
||||
export const resolveCurrentCarton = (cartonMark) => overseasRequest('POST', current('/cartons/resolve'), { cartonMark })
|
||||
export const resolveCurrentSku = (skuCode) => overseasRequest('POST', current('/skus/resolve'), { skuCode })
|
||||
export const resolveCurrentPallet = (palletCode, inboundCode) => overseasRequest('POST', current('/pallets/resolve'), { palletCode, inboundCode })
|
||||
export const receiveCurrentBulk = (request) => overseasRequest('POST', current('/receipts/bulk'), request)
|
||||
export const receiveCurrentCarton = (request) => overseasRequest('POST', current('/receipts/carton'), request)
|
||||
export const completeCurrentReceiving = (request) => overseasRequest('POST', current('/complete'), request)
|
||||
export const completeCurrentReceiving = async (request) => normalizeReceivingSession(await overseasRequest('POST', current('/complete'), request))
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
export const RECEIVING_PHOTO_ROLES = ['LICENSE_PLATE', 'CONTAINER_SEAL', 'DOOR_OPEN']
|
||||
|
||||
const number = (value) => Math.max(0, Number(value || 0))
|
||||
|
||||
export function normalizeReceivingInbound(value = {}) {
|
||||
return {
|
||||
...value,
|
||||
plannedPalletCount: number(value.plannedPalletCount),
|
||||
totalPackages: number(value.totalPackages),
|
||||
receivedPackages: number(value.receivedPackages),
|
||||
pendingPackages: number(value.pendingPackages)
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeReceivingCandidate(value = {}) {
|
||||
return {
|
||||
...value,
|
||||
destinationCodes: Array.isArray(value.destinationCodes) ? value.destinationCodes.filter(Boolean) : [],
|
||||
plannedPalletCount: number(value.plannedPalletCount),
|
||||
totalPackages: number(value.totalPackages),
|
||||
receivedPackages: number(value.receivedPackages),
|
||||
currentAccount: value.currentAccount === true
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeReceivingSession(value) {
|
||||
if (!value) return null
|
||||
const photos = Array.isArray(value.photos) ? value.photos : []
|
||||
return {
|
||||
...value,
|
||||
photos: RECEIVING_PHOTO_ROLES.map((role) => photos.find((photo) => photo?.role === role)).filter(Boolean),
|
||||
totalPackages: number(value.totalPackages),
|
||||
receivedPackages: number(value.receivedPackages),
|
||||
pendingPackages: number(value.pendingPackages),
|
||||
inbounds: Array.isArray(value.inbounds) ? value.inbounds.map(normalizeReceivingInbound) : []
|
||||
}
|
||||
}
|
||||
|
||||
export function isNoCurrentReceiving(error) {
|
||||
return ['404', 'A0404', 'B0404'].includes(String(error?.code || ''))
|
||||
}
|
||||
|
||||
export function isReceivingConflict(error) {
|
||||
return ['409', 'A0409', 'B0409'].includes(String(error?.code || ''))
|
||||
}
|
||||
Reference in New Issue
Block a user