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 buildPurchasePageParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...filterParams(params, ['current', 'pageSize', 'size'])
|
}
|
}
|
|
export function buildPurchaseItemPageParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...filterParams(params, ['current', 'pageSize', 'size'])
|
}
|
}
|
|
export function fetchPurchasePage(params = {}) {
|
return request.post({
|
url: '/purchase/page',
|
params: buildPurchasePageParams(params)
|
})
|
}
|
|
export function fetchPurchaseList() {
|
return request.post({
|
url: '/purchase/list',
|
data: {}
|
})
|
}
|
|
export function fetchPurchaseMany(ids) {
|
return request.post({
|
url: `/purchase/many/${normalizeIds(ids)}`
|
})
|
}
|
|
export function fetchPurchaseDetail(id) {
|
return request.get({
|
url: `/purchase/${id}`
|
})
|
}
|
|
export function fetchSavePurchase(params = {}) {
|
return request.post({
|
url: '/purchase/save',
|
params
|
})
|
}
|
|
export function fetchUpdatePurchase(params = {}) {
|
return request.post({
|
url: '/purchase/update',
|
params
|
})
|
}
|
|
export function fetchDeletePurchase(ids) {
|
return request.post({
|
url: `/purchase/remove/${normalizeIds(ids)}`
|
})
|
}
|
|
export function fetchPurchaseQuery(condition = '') {
|
return request.post({
|
url: '/purchase/query',
|
params: { condition: normalizeText(condition) }
|
})
|
}
|
|
export function fetchPurchaseItemPage(params = {}) {
|
return request.post({
|
url: '/purchaseItem/page',
|
params: buildPurchaseItemPageParams(params)
|
})
|
}
|
|
export async function fetchExportPurchaseReport(payload = {}, options = {}) {
|
return fetch(`${import.meta.env.VITE_API_URL}/purchase/export`, {
|
method: 'POST',
|
headers: {
|
'Content-Type': 'application/json',
|
...(options.headers || {})
|
},
|
body: JSON.stringify(payload)
|
})
|
}
|