优化
This commit is contained in:
@@ -55,3 +55,40 @@ export async function mergeReturnCartons(request) {
|
||||
export async function getReturnCartonLabel(cartonMark) {
|
||||
return normalizeReturnLabel(await overseasRequest('GET', `${BASE}/cartons/${encoded(cartonMark)}/label`))
|
||||
}
|
||||
|
||||
function normalizePlanBox(box = {}) {
|
||||
return {
|
||||
boxNo: Number(box.boxNo || 0),
|
||||
items: Array.isArray(box.items) ? box.items.map((item) => ({ skuCode: String(item.skuCode || ''), quantity: count(item.quantity) })) : [],
|
||||
length: count(box.length), width: count(box.width), height: count(box.height), weight: count(box.weight),
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeReturnPackingPlan(value = {}) {
|
||||
const skuLines = Array.isArray(value.skuLines) ? value.skuLines.map((item) => ({ skuCode: String(item.skuCode || ''), productNameZh: String(item.productNameZh || ''), quantity: count(item.quantity) })) : []
|
||||
const boxes = Array.isArray(value.boxes) && value.boxes.length ? value.boxes.map(normalizePlanBox) : skuLines.map((item, index) => ({ boxNo: index + 1, items: [{ skuCode: item.skuCode, quantity: item.quantity }], length: 0, width: 0, height: 0, weight: 0 }))
|
||||
return {
|
||||
planNo: String(value.planNo || ''), status: String(value.status || 'READY'), mode: String(value.mode || 'WAREHOUSE_RECOMMENDATION'),
|
||||
customerName: String(value.customerName || ''), customerReferenceNo: String(value.customerReferenceNo || ''),
|
||||
returnNos: Array.isArray(value.returnNos) ? value.returnNos.map((item) => String(item || '')).filter(Boolean) : [],
|
||||
skuLines, boxes, remark: String(value.remark || ''),
|
||||
}
|
||||
}
|
||||
|
||||
export async function listReturnPackingPlans() {
|
||||
try {
|
||||
const value = await overseasRequest('GET', `${BASE}/packing/plans`)
|
||||
const records = Array.isArray(value) ? value : Array.isArray(value?.records) ? value.records : []
|
||||
return records.map(normalizeReturnPackingPlan)
|
||||
}
|
||||
catch (error) { if (isNotFound(error)) return []; throw error }
|
||||
}
|
||||
|
||||
export async function getReturnPackingPlan(planNo) {
|
||||
return normalizeReturnPackingPlan(await overseasRequest('GET', `${BASE}/packing/plans/${encoded(planNo)}`))
|
||||
}
|
||||
|
||||
export async function mergeReturnPackingPlan(planNo, request) {
|
||||
const value = await overseasRequest('POST', `${BASE}/packing/plans/${encoded(planNo)}/complete`, request)
|
||||
return { ...value, labels: Array.isArray(value?.labels) ? value.labels.map(normalizeReturnLabel) : [normalizeReturnLabel(value?.label || value)], label: normalizeReturnLabel(value?.label || value) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user