优化
This commit is contained in:
@@ -37,6 +37,7 @@ export function normalizeDispatchTask(value) {
|
||||
warehouseRouteLabel: String(item?.warehouseRouteLabel || ''),
|
||||
scheduledPackages: count(item?.scheduledPackages),
|
||||
pickedPackages: count(item?.pickedPackages),
|
||||
returnCartons: asList(item?.returnCartons).map((carton) => ({ ...carton, id: String(carton.id || ''), cartonMark: String(carton.cartonMark || ''), productQuantity: count(carton.productQuantity) })),
|
||||
positions: asList(item?.positions).map((position) => ({
|
||||
...position,
|
||||
id: String(position?.id || ''),
|
||||
|
||||
@@ -17,7 +17,17 @@ function normalizeItems(items) {
|
||||
}
|
||||
|
||||
export function normalizePackingPreview(value = {}) {
|
||||
return {
|
||||
value = value && typeof value === 'object' ? value : {}
|
||||
const normalizeCustomer = (customer = {}) => ({
|
||||
customerId: customer.customerId == null ? '' : String(customer.customerId),
|
||||
orders: Array.isArray(customer.orders) ? customer.orders.map((item) => ({
|
||||
returnNo: String(item.returnNo || ''), customerReferenceNo: String(item.customerReferenceNo || ''), status: String(item.status || '')
|
||||
})) : [],
|
||||
skus: Array.isArray(customer.skus) ? customer.skus.map((item) => ({
|
||||
skuCode: String(item.skuCode || ''), productNameZh: String(item.productNameZh || ''), availableQuantity: count(item.availableQuantity)
|
||||
})) : []
|
||||
})
|
||||
const result = {
|
||||
customerKey: value.customerId == null ? '' : String(value.customerId),
|
||||
orders: Array.isArray(value.orders) ? value.orders.map((item) => ({
|
||||
returnNo: String(item.returnNo || ''), customerReferenceNo: String(item.customerReferenceNo || ''), status: String(item.status || '')
|
||||
@@ -26,6 +36,13 @@ export function normalizePackingPreview(value = {}) {
|
||||
skuCode: String(item.skuCode || ''), productNameZh: String(item.productNameZh || ''), availableQuantity: count(item.availableQuantity)
|
||||
})) : []
|
||||
}
|
||||
if (Array.isArray(value.customers)) result.customers = value.customers.map(normalizeCustomer).filter((item) => item.customerId)
|
||||
else if (result.customerKey && result.orders.length) {
|
||||
// Older service versions returned the single-customer shape. Keep the
|
||||
// PDA behavior consistent by exposing it through the grouped contract.
|
||||
result.customers = [{ customerId: result.customerKey, orders: result.orders, skus: result.skus }]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export function normalizeReturnLabel(value = {}) {
|
||||
@@ -37,16 +54,52 @@ export function normalizeReturnLabel(value = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function findPackingOrders(returnNo = '') {
|
||||
export async function findPackingOrders(returnNo = '', mode = 'RETURN_NO') {
|
||||
const query = String(returnNo || '').trim()
|
||||
try {
|
||||
return normalizePackingPreview(await overseasRequest('GET', `${BASE}/packing/orders${query ? `?returnNo=${encoded(query)}` : ''}`))
|
||||
return normalizePackingPreview(await overseasRequest('GET', `${BASE}/packing/orders${query ? `?${mode === 'RETURN_NO' ? 'returnNo' : 'skuCode'}=${encoded(query)}` : ''}`))
|
||||
} catch (error) {
|
||||
if (isNotFound(error)) return normalizePackingPreview()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export async function listPackingPlans() {
|
||||
const value = await overseasRequest('GET', `${BASE}/packing/plans`)
|
||||
return Array.isArray(value) ? value.map(normalizePackingPlan) : []
|
||||
}
|
||||
|
||||
export async function completePackingPlan(planNo, request) {
|
||||
const value = await overseasRequest('POST', `${BASE}/packing/plans/${encoded(planNo)}/complete`, request)
|
||||
return { planNo: String(value?.planNo || planNo), labels: Array.isArray(value?.labels) ? value.labels.map(normalizeReturnLabel) : [] }
|
||||
}
|
||||
|
||||
export function normalizePackingPlan(value = {}) {
|
||||
return { planNo: String(value.planNo || ''), customerId: String(value.customerId || ''), returnNos: Array.isArray(value.returnNos) ? value.returnNos.map(String) : [], sourceCartonMarks: Array.isArray(value.sourceCartonMarks) ? value.sourceCartonMarks.map(String) : [], sources: Array.isArray(value.sources) ? value.sources : [], mode: String(value.mode || ''), status: String(value.status || ''), boxes: Array.isArray(value.boxes) ? value.boxes : [], remark: String(value.remark || '') }
|
||||
}
|
||||
|
||||
export async function getPackingPlan(planNo) {
|
||||
return normalizePackingPlan(await overseasRequest('GET', `${BASE}/packing/plans/${encoded(planNo)}`))
|
||||
}
|
||||
|
||||
export async function scanReturnCarton(mark) {
|
||||
return overseasRequest('GET', `${BASE}/cartons/${encoded(mark)}`)
|
||||
}
|
||||
|
||||
export async function mergeReturnBoxes(request) {
|
||||
const value = await overseasRequest('POST', `${BASE}/cartons/merge-boxes`, request)
|
||||
return { labels: [normalizeReturnLabel(value?.label)] }
|
||||
}
|
||||
|
||||
export async function packReturnSkus(request) {
|
||||
const value = await overseasRequest('POST', `${BASE}/cartons/pack`, request)
|
||||
return { labels: Array.isArray(value?.labels) ? value.labels.map(normalizeReturnLabel) : [] }
|
||||
}
|
||||
|
||||
export async function putawayReturnCarton(mark, request) {
|
||||
return overseasRequest('POST', `${BASE}/cartons/${encoded(mark)}/putaway`, request)
|
||||
}
|
||||
|
||||
export async function mergeReturnCartons(request) {
|
||||
const value = await overseasRequest('POST', `${BASE}/cartons/merge`, request)
|
||||
return { cartonMark: String(value?.cartonMark || ''), skuCode: String(value?.skuCode || ''), totalQuantity: count(value?.totalQuantity), label: normalizeReturnLabel(value?.label) }
|
||||
|
||||
Reference in New Issue
Block a user