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 buildStockTransferSourcePageParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
orderBy: 'create_time desc',
|
locCode: normalizeText(params.locCode || params.orgLoc || ''),
|
...filterParams(params, ['current', 'pageSize', 'size', 'locCode', 'orgLoc'])
|
}
|
}
|
|
export function buildStockTransferTargetLocPageParams(params = {}) {
|
const queryParams = {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 50,
|
locCode: normalizeText(params.locCode || params.orgLoc || '')
|
}
|
const q = normalizeText(params.q)
|
if (q) {
|
queryParams.q = q
|
}
|
return {
|
...queryParams,
|
...filterParams(params, ['current', 'pageSize', 'size', 'locCode', 'orgLoc', 'q'])
|
}
|
}
|
|
export function buildStockTransferTaskPayload(params = {}) {
|
return {
|
orgLoc: normalizeText(params.orgLoc),
|
tarLoc: normalizeText(params.tarLoc),
|
memo: normalizeText(params.memo)
|
}
|
}
|
|
export function fetchStockTransferSourcePage(params = {}) {
|
return request.post({ url: '/locItem/useO/page', params: buildStockTransferSourcePageParams(params) })
|
}
|
|
export function fetchStockTransferSourceDetail(id) {
|
return request.get({ url: `/locItem/${id}` })
|
}
|
|
export function fetchStockTransferTargetLocPage(params = {}) {
|
return request.post({ url: '/loc/areaNoUse/page', params: buildStockTransferTargetLocPageParams(params) })
|
}
|
|
export function fetchStockTransferMoveTask(params = {}) {
|
return request.post({ url: '/locItem/move/task', params: buildStockTransferTaskPayload(params) })
|
}
|
|
export function fetchStockTransferEnabledFields() {
|
return request.get({ url: '/fields/enable/list' })
|
}
|
|
export { normalizeIds }
|