Files
pda-overseas-uniapp/src/api/inbound.js
T

34 lines
3.4 KiB
JavaScript

import { overseasDownload, overseasRequest, overseasUpload } from '@/api/overseas.js'
import { normalizeReceivingAssignment, normalizeReceivingInbound, normalizeReceivingCandidate, normalizeReceivingSession, normalizeReceivingWarehouseProfile } from '@/api/receiving-adapter.js'
const RECEIVING_BASE = '/pda/v1/last-leg/receiving-containers'
const current = (suffix = '') => `${RECEIVING_BASE}/current${suffix}`
let warehouseProfileRequest = null
export const listReceivingCandidates = async () => (await overseasRequest('GET', `${RECEIVING_BASE}/candidates`)).map(normalizeReceivingCandidate)
export const getCurrentWarehouseProfile = () => {
if (!warehouseProfileRequest) {
warehouseProfileRequest = overseasRequest('GET', `${RECEIVING_BASE}/warehouse-profile`)
.then(normalizeReceivingWarehouseProfile)
.finally(() => { warehouseProfileRequest = null })
}
return warehouseProfileRequest
}
const receivingIdentityQuery = (sourceContainerBookingId) => `sourceContainerBookingId=${encodeURIComponent(sourceContainerBookingId)}`
export const getReceivingContainer = async (containerNo, sourceContainerBookingId) => normalizeReceivingSession(await overseasRequest('GET', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}?${receivingIdentityQuery(sourceContainerBookingId)}`))
export const prepareReceivingContainer = async (containerNo, sourceContainerBookingId, request) => normalizeReceivingSession(await overseasRequest('POST', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}/prepare?${receivingIdentityQuery(sourceContainerBookingId)}`, request))
export const uploadCurrentUnloadPhoto = (filePath) => overseasUpload(current('/unload-photos/files'), filePath)
export const downloadCurrentUnloadPhoto = (downloadPath) => overseasDownload(downloadPath, { expectedContentTypePrefix: 'image/' })
export const downloadCurrentDomesticLoadingPhoto = (downloadPath) => overseasDownload(downloadPath, { expectedContentTypePrefix: 'image/' })
export const signCurrentReceiving = async (request) => normalizeReceivingSession(await overseasRequest('POST', current('/sign'), request))
export const getCurrentReceiving = async () => normalizeReceivingSession(await overseasRequest('GET', current()))
export const resolveCurrentCarton = async (cartonMark) => normalizeReceivingInbound(await overseasRequest('POST', current('/cartons/resolve'), { cartonMark }))
export const resolveCurrentPallet = async (palletCode, inboundCode) => {
const value = await overseasRequest('POST', current('/pallets/resolve'), { palletCode, inboundCode })
return { ...value, palletCode: String(value?.palletCode || palletCode || ''), locationCode: String(value?.locationCode || value?.warehouseLocationCode || ''), locationType: String(value?.locationType || value?.warehouseLocationType || ''), locationStatus: String(value?.locationStatus || value?.warehouseLocationStatus || '') }
}
export const receiveCurrentBulk = async (request) => normalizeReceivingAssignment(await overseasRequest('POST', current('/receipts/bulk'), request))
export const receiveCurrentCarton = async (request) => normalizeReceivingAssignment(await overseasRequest('POST', current('/receipts/carton'), request))
export const receiveCurrentWholePallet = async (request) => normalizeReceivingAssignment(await overseasRequest('POST', current('/receipts/pallet'), request))
export const completeCurrentReceiving = async (request) => normalizeReceivingSession(await overseasRequest('POST', current('/complete'), request))