92 lines
5.0 KiB
JavaScript
92 lines
5.0 KiB
JavaScript
import { apiDownload, apiRequest } from '@/api/http.js'
|
|
import { stableOperationId } from '@/utils/idempotency.js'
|
|
import { session } from '@/stores/session.js'
|
|
|
|
const ROOT = '/first-leg/pda-dropship'
|
|
|
|
function stableId(value) {
|
|
return String(value ?? '').trim()
|
|
}
|
|
|
|
function operationId(action, taskId, payload = {}) {
|
|
return stableOperationId('dropship-' + action, String(session.currentUser?.id) + '-' + taskId, payload)
|
|
}
|
|
|
|
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, payload) } })
|
|
}
|
|
|
|
export function bindDropshipPendingCartons(taskId, warehouseId, palletNo, taskVersion) {
|
|
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, { warehouseId, palletNo, taskVersion }) } })
|
|
}
|
|
|
|
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, { warehouseId, palletId: pallet.palletId, version: pallet.version }) } })
|
|
}
|
|
|
|
export function downloadDropshipPalletLabel(taskId, warehouseId, palletId) {
|
|
const baseUrl = String(session.apiBase || '/api/platform/v1').replace(/\/$/, '')
|
|
const url = `${baseUrl}${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
|
|
})
|
|
}
|
|
|
|
export function downloadAllDropshipPalletLabels(taskId, warehouseId) {
|
|
const baseUrl = String(session.apiBase || '/api/platform/v1').replace(/\/$/, '')
|
|
const url = `${baseUrl}${ROOT}/tasks/${encodeURIComponent(taskId)}/pallets/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))) throw new Error('全部托盘码打印文件生成失败')
|
|
return response.tempFilePath
|
|
})
|
|
}
|
|
|
|
function requireValue(value, message) {
|
|
if (value === null || value === undefined || value === '') throw new Error(message)
|
|
}
|
|
|
|
function operationHeader(operationId) {
|
|
return operationId ? { 'Idempotency-Key': String(operationId) } : {}
|
|
}
|
|
|
|
|
|
export function moveDropshipCarton(taskId, cartonId, payload = {}) {
|
|
requireValue(cartonId, '缺少箱明细标识')
|
|
for (const [field, message] of [['warehouseId', '缺少作业仓库标识'], ['operationId', '缺少操作幂等标识']]) requireValue(payload[field], message)
|
|
return apiRequest({
|
|
url: `${ROOT}/tasks/${encodeURIComponent(taskId)}/cartons/${encodeURIComponent(cartonId)}/move`,
|
|
method: 'POST',
|
|
header: operationHeader(payload.operationId),
|
|
data: { warehouseId: payload.warehouseId, targetPalletNo: payload.targetPalletNo || null, operationId: payload.operationId }
|
|
})
|
|
}
|