Files
pda-uniapp/api/pda-dropship.js
T
2026-09-11 11:51:35 +08:00

64 lines
3.5 KiB
JavaScript

import { apiDownload, apiRequest } from '@/api/http.js'
const ROOT = '/first-leg/pda-dropship'
function stableId(value) {
return String(value ?? '').trim()
}
function operationId(action, taskId) {
const random = Math.random().toString(36).slice(2, 10)
return `pda-dropship-${action}-${taskId}-${Date.now()}-${random}`.slice(0, 128)
}
export function listDropshipPalletizationTasks(keyword = '', warehouseId) {
if (!warehouseId) throw new Error('请先选择作业仓库')
const query = String(keyword || '').trim()
const params = [`warehouseId=${encodeURIComponent(warehouseId)}`]
if (query) params.push(`keyword=${encodeURIComponent(query)}`)
return apiRequest({ url: `${ROOT}/tasks/pending?${params.join('&')}`, method: 'GET' })
}
export function getDropshipPalletizationTask(taskId, warehouseId) {
return apiRequest({ url: `${ROOT}/tasks/${encodeURIComponent(taskId)}?warehouseId=${encodeURIComponent(warehouseId)}`, method: 'GET' })
}
export function claimDropshipPalletizationTask(taskId, warehouseId) {
return apiRequest({ url: `${ROOT}/tasks/${encodeURIComponent(taskId)}/claim`, method: 'POST', data: { warehouseId: stableId(warehouseId) } })
}
export function resolveDropshipCarton(taskId, warehouseId, boxCode) {
return apiRequest({ url: `${ROOT}/tasks/${encodeURIComponent(taskId)}/cartons/resolve?warehouseId=${encodeURIComponent(warehouseId)}&boxCode=${encodeURIComponent(String(boxCode || '').trim())}`, method: 'GET' })
}
export function countDropshipCarton(taskId, payload) {
return apiRequest({ url: `${ROOT}/tasks/${encodeURIComponent(taskId)}/cartons/count`, method: 'POST', data: { ...payload, warehouseId: stableId(payload.warehouseId), operationId: payload.operationId || operationId('count', taskId) } })
}
export function bindDropshipPendingCartons(taskId, warehouseId, palletNo) {
return apiRequest({ url: `${ROOT}/tasks/${encodeURIComponent(taskId)}/pallets/bind-pending`, method: 'POST', data: { warehouseId: stableId(warehouseId), palletNo: String(palletNo || '').trim().toUpperCase(), operationId: operationId('bind', taskId) } })
}
export function createAndBindDropshipPallet(taskId, warehouseId) {
return apiRequest({ url: `${ROOT}/tasks/${encodeURIComponent(taskId)}/pallets/create-and-bind`, method: 'POST', data: { warehouseId: stableId(warehouseId), operationId: operationId('create-bind', taskId) } })
}
export function sealDropshipPallet(taskId, warehouseId, pallet) {
return apiRequest({ url: `${ROOT}/tasks/${encodeURIComponent(taskId)}/pallets/${encodeURIComponent(pallet.palletId)}/seal`, method: 'POST', data: { warehouseId: stableId(warehouseId), expectedVersion: pallet.version, operationId: operationId('seal', taskId) } })
}
export function downloadDropshipPalletLabel(taskId, warehouseId, palletId) {
const url = `${ROOT}/tasks/${encodeURIComponent(taskId)}/pallets/${encodeURIComponent(palletId)}/print?warehouseId=${encodeURIComponent(stableId(warehouseId))}`
return apiDownload({ url }).then((response) => {
const contentType = response.header?.['Content-Type'] || response.header?.['content-type'] || ''
if (response.statusCode < 200 || response.statusCode >= 300 || !response.tempFilePath || (contentType && !/^application\/pdf/i.test(contentType))) {
const error = new Error('托盘码打印文件生成失败')
error.statusCode = response.statusCode
error.requestId = response.header?.['X-Request-Id'] || response.header?.['x-request-id']
error.traceId = response.header?.['X-Trace-Id'] || response.header?.['x-trace-id']
throw error
}
return response.tempFilePath
})
}