import request from '@/utils/http'
|
|
function normalizeText(value) {
|
return typeof value === 'string' ? value.trim() : value
|
}
|
|
function normalizeIds(ids) {
|
if (Array.isArray(ids)) {
|
return ids
|
.map((id) => String(id).trim())
|
.filter(Boolean)
|
.join(',')
|
}
|
if (ids === null || ids === undefined) {
|
return ''
|
}
|
return String(ids).trim()
|
}
|
|
function filterParams(params = {}, ignoredKeys = []) {
|
return Object.fromEntries(
|
Object.entries(params)
|
.filter(([key, value]) => {
|
if (ignoredKeys.includes(key)) return false
|
if (value === undefined || value === null) return false
|
if (typeof value === 'string' && value.trim() === '') return false
|
return true
|
})
|
.map(([key, value]) => [key, normalizeText(value)])
|
)
|
}
|
|
export function buildDeliverySearchParams(params = {}) {
|
const result = {}
|
;['condition', 'code', 'platId', 'type', 'wkType', 'source', 'timeStart', 'timeEnd', 'memo'].forEach((key) => {
|
const value = normalizeText(params[key])
|
if (value) result[key] = value
|
})
|
if (params.status !== '' && params.status !== undefined && params.status !== null) {
|
result.status = Number(params.status)
|
}
|
if (params.exceStatus !== '' && params.exceStatus !== undefined && params.exceStatus !== null) {
|
result.exceStatus = Number(params.exceStatus)
|
}
|
return result
|
}
|
|
export function buildDeliveryPageParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildDeliverySearchParams(params)
|
}
|
}
|
|
export function buildDeliveryDetailQueryParams(params = {}) {
|
return {
|
deliveryId: params.deliveryId,
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20
|
}
|
}
|
|
export function buildDeliveryItemSearchParams(params = {}) {
|
const result = {}
|
;[
|
'condition',
|
'deliveryCode',
|
'platItemId',
|
'matnrCode',
|
'maktx',
|
'splrName',
|
'splrCode',
|
'splrBatch',
|
'timeStart',
|
'timeEnd',
|
'memo'
|
].forEach((key) => {
|
const value = normalizeText(params[key])
|
if (value) result[key] = value
|
})
|
if (params.deliveryId !== '' && params.deliveryId !== undefined && params.deliveryId !== null) {
|
result.deliveryId = Number(params.deliveryId)
|
}
|
if (params.status !== '' && params.status !== undefined && params.status !== null) {
|
result.status = Number(params.status)
|
}
|
return result
|
}
|
|
export function buildDeliveryItemPageParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildDeliveryItemSearchParams(params)
|
}
|
}
|
|
export function buildDeliveryItemDetailQueryParams(params = {}) {
|
return {
|
deliveryItemId: params.deliveryItemId,
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20
|
}
|
}
|
|
export function buildDeliveryExportParams(payload = {}) {
|
const params = buildDeliverySearchParams(payload)
|
return filterParams(params, ['ids'])
|
}
|
|
export function fetchDeliveryPage(params = {}) {
|
return request.post({
|
url: '/delivery/page',
|
params: buildDeliveryPageParams(params)
|
})
|
}
|
|
export function fetchGetDeliveryDetail(id) {
|
return request.get({
|
url: `/delivery/${id}`
|
})
|
}
|
|
export function fetchGetDeliveryMany(ids) {
|
return request.post({
|
url: `/delivery/many/${normalizeIds(ids)}`
|
})
|
}
|
|
export function fetchDeleteDelivery(id) {
|
return request.post({
|
url: `/delivery/remove/${id}`
|
})
|
}
|
|
export function fetchSaveDelivery(payload = {}) {
|
return request.post({
|
url: '/delivery/save',
|
params: payload
|
})
|
}
|
|
export function fetchUpdateDelivery(payload = {}) {
|
return request.post({
|
url: '/delivery/update',
|
params: payload
|
})
|
}
|
|
export function fetchDeliveryItemPage(params = {}) {
|
return request.post({
|
url: '/deliveryItem/page',
|
params: buildDeliveryItemPageParams(params)
|
})
|
}
|
|
export function fetchGetDeliveryItemDetail(id) {
|
return request.get({
|
url: `/deliveryItem/${id}`
|
})
|
}
|
|
export function fetchGetDeliveryItemMany(ids) {
|
return request.post({
|
url: `/deliveryItem/many/${normalizeIds(ids)}`
|
})
|
}
|
|
export function fetchDeleteDeliveryItem(id) {
|
return request.post({
|
url: `/deliveryItem/remove/${id}`
|
})
|
}
|
|
export function fetchSaveDeliveryItem(payload = {}) {
|
return request.post({
|
url: '/deliveryItem/save',
|
params: payload
|
})
|
}
|
|
export function fetchUpdateDeliveryItem(payload = {}) {
|
return request.post({
|
url: '/deliveryItem/update',
|
params: payload
|
})
|
}
|
|
export async function fetchExportDeliveryReport(payload = {}, options = {}) {
|
const exportRequest = { url: `/delivery/export` }
|
return fetch(`${import.meta.env.VITE_API_URL}${exportRequest.url}`, {
|
method: 'POST',
|
headers: {
|
'Content-Type': 'application/json',
|
...(options.headers || {})
|
},
|
body: JSON.stringify(buildDeliveryExportParams(payload))
|
})
|
}
|