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((item) => String(item).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 buildPreparationPageParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...filterParams(params, ['current', 'pageSize', 'size'])
|
}
|
}
|
|
export function buildPreparationItemPageParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...(params.orderId !== undefined ? { orderId: Number(params.orderId) } : {}),
|
...filterParams(params, ['current', 'pageSize', 'size', 'orderId'])
|
}
|
}
|
|
export function fetchPreparationPage(params = {}) {
|
return request.post({ url: '/preparation/page', params: buildPreparationPageParams(params) })
|
}
|
|
export function fetchPreparationItemPage(params = {}) {
|
return request.post({
|
url: '/outStockItem/page',
|
params: buildPreparationItemPageParams(params)
|
})
|
}
|
|
export function fetchGetPreparationDetail(id) {
|
return request.get({ url: `/preparation/${id}` })
|
}
|
|
export function fetchGetPreparationMany(ids) {
|
return request.post({ url: `/preparation/many/${normalizeIds(ids)}` })
|
}
|
|
export function fetchDeletePreparation(ids) {
|
return request.post({ url: `/preparation/remove/${normalizeIds(ids)}` })
|
}
|
|
export function fetchCompletePreparation(id) {
|
return request.get({ url: `/preparation/complete/${id}` })
|
}
|
|
export function fetchCancelPreparation(id) {
|
return request.get({ url: `/preparation/cancel/${id}` })
|
}
|
|
export async function fetchExportPreparationReport(payload = {}, options = {}) {
|
return fetch(`${import.meta.env.VITE_API_URL}/preparation/export`, {
|
method: 'POST',
|
headers: {
|
'Content-Type': 'application/json',
|
...(options.headers || {})
|
},
|
body: JSON.stringify(payload)
|
})
|
}
|