import request from '@/utils/http'
|
import {
|
buildStockItemPageQueryParams,
|
buildStockItemSavePayload,
|
buildStockItemSearchParams
|
} from '@/views/manager/stock-item/stockItemPage.helpers.js'
|
|
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()
|
}
|
|
export function fetchStockItemPage(params = {}) {
|
return request.post({
|
url: '/stockItem/page',
|
params: buildStockItemPageQueryParams(params)
|
})
|
}
|
|
export function fetchStockItemList(params = {}) {
|
return request.post({
|
url: '/stockItem/list',
|
data: buildStockItemSearchParams(params)
|
})
|
}
|
|
export function fetchStockItemDetail(id) {
|
return request.get({
|
url: `/stockItem/${id}`
|
})
|
}
|
|
export function fetchStockItemMany(ids) {
|
return request.post({
|
url: `/stockItem/many/${normalizeIds(ids)}`
|
})
|
}
|
|
export function fetchStockItemQuery(condition = '') {
|
return request.post({
|
url: '/stockItem/query',
|
params: {
|
condition
|
}
|
})
|
}
|
|
export function fetchSaveStockItem(params = {}) {
|
return request.post({
|
url: '/stockItem/save',
|
params: buildStockItemSavePayload(params)
|
})
|
}
|
|
export function fetchUpdateStockItem(params = {}) {
|
return request.post({
|
url: '/stockItem/update',
|
params: buildStockItemSavePayload(params)
|
})
|
}
|
|
export function fetchDeleteStockItem(ids) {
|
return request.post({
|
url: `/stockItem/remove/${normalizeIds(ids)}`
|
})
|
}
|
|
export async function fetchExportStockItemReport(payload = {}, options = {}) {
|
return fetch(`${import.meta.env.VITE_API_URL}/stockItem/export`, {
|
method: 'POST',
|
headers: {
|
'Content-Type': 'application/json',
|
...(options.headers || {})
|
},
|
body: JSON.stringify(payload)
|
})
|
}
|