import request from '@/utils/http'
|
|
function normalizeText(value) {
|
return typeof value === 'string' ? value.trim() : value
|
}
|
|
function normalizeNumber(value, fallback = void 0) {
|
if (value === '' || value === null || value === undefined) return fallback
|
const parsed = Number(value)
|
return Number.isNaN(parsed) ? fallback : parsed
|
}
|
|
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 buildTransferSearchParams(params = {}) {
|
const result = {}
|
;['condition', 'code', 'orgWareName', 'tarWareName', 'orgAreaName', 'tarAreaName', 'memo', 'timeStart', 'timeEnd'].forEach((key) => {
|
const value = normalizeText(params[key])
|
if (value) result[key] = value
|
})
|
;['type', 'source', 'exceStatus', 'status', 'orgWareId', 'tarWareId', 'orgAreaId', 'tarAreaId'].forEach((key) => {
|
if (params[key] !== '' && params[key] !== undefined && params[key] !== null) {
|
result[key] = normalizeNumber(params[key])
|
}
|
})
|
return result
|
}
|
|
export function buildTransferPageParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildTransferSearchParams(params)
|
}
|
}
|
|
export function buildTransferOrderPageParams(params = {}) {
|
return {
|
condition: normalizeText(params.code || params.condition),
|
code: normalizeText(params.code || params.condition),
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20
|
}
|
}
|
|
export function buildTransferSavePayload(formData = {}, areaOptions = []) {
|
const optionMap = new Map(
|
(Array.isArray(areaOptions) ? areaOptions : [])
|
.map((item) => {
|
const value = normalizeNumber(item?.value ?? item?.id, void 0)
|
if (value === void 0) return null
|
return [value, item?.raw || item]
|
})
|
.filter(Boolean)
|
)
|
|
const orgAreaId = normalizeNumber(formData.orgAreaId, void 0)
|
const tarAreaId = normalizeNumber(formData.tarAreaId, void 0)
|
const orgArea = optionMap.get(orgAreaId) || {}
|
const tarArea = optionMap.get(tarAreaId) || {}
|
const orgWareId = normalizeNumber(orgArea.warehouseId ?? orgArea.warehouse_id ?? orgArea.warehouseIdValue, void 0)
|
const tarWareId = normalizeNumber(tarArea.warehouseId ?? tarArea.warehouse_id ?? tarArea.warehouseIdValue, void 0)
|
|
return {
|
...(formData.id !== undefined && formData.id !== null && formData.id !== ''
|
? { id: normalizeNumber(formData.id) }
|
: {}),
|
...(normalizeText(formData.code) ? { code: normalizeText(formData.code) } : {}),
|
...(formData.type !== undefined && formData.type !== null && formData.type !== ''
|
? { type: normalizeNumber(formData.type) }
|
: {}),
|
...(orgAreaId !== void 0 ? { orgAreaId } : {}),
|
...(tarAreaId !== void 0 ? { tarAreaId } : {}),
|
...(orgWareId !== void 0 ? { orgWareId } : {}),
|
...(tarWareId !== void 0 ? { tarWareId } : {}),
|
...(normalizeText(orgArea.name || orgArea.areaName) ? { orgAreaName: normalizeText(orgArea.name || orgArea.areaName) } : {}),
|
...(normalizeText(tarArea.name || tarArea.areaName) ? { tarAreaName: normalizeText(tarArea.name || tarArea.areaName) } : {}),
|
...(normalizeText(orgArea.warehouseId$ || orgArea.warehouseName) ? { orgWareName: normalizeText(orgArea.warehouseId$ || orgArea.warehouseName) } : {}),
|
...(normalizeText(tarArea.warehouseId$ || tarArea.warehouseName) ? { tarWareName: normalizeText(tarArea.warehouseId$ || tarArea.warehouseName) } : {}),
|
...(formData.status !== undefined && formData.status !== null && formData.status !== ''
|
? { status: normalizeNumber(formData.status) }
|
: { status: 1 }),
|
memo: normalizeText(formData.memo) || ''
|
}
|
}
|
|
export function fetchTransferPage(params = {}) {
|
return request.post({ url: '/transfer/page', params: buildTransferPageParams(params) })
|
}
|
|
export function fetchTransferDetail(id) {
|
return request.get({ url: `/transfer/${id}` })
|
}
|
|
export function fetchTransferMany(ids) {
|
return request.post({ url: `/transfer/many/${normalizeIds(ids)}` })
|
}
|
|
export function fetchDeleteTransfer(ids) {
|
return request.post({ url: `/transfer/remove/${normalizeIds(ids)}` })
|
}
|
|
export function fetchSaveTransfer(payload = {}) {
|
return request.post({ url: '/transfer/save', params: payload })
|
}
|
|
export function fetchUpdateTransfer(payload = {}) {
|
return request.post({ url: '/transfer/update', params: payload })
|
}
|
|
export function fetchTransferOrdersPage(params = {}) {
|
return request.post({ url: '/transfer/orders/page', params: buildTransferOrderPageParams(params) })
|
}
|
|
export function fetchTransferPubOutStock(payload = {}) {
|
return request.post({ url: '/transfer/pub/outStock', params: payload })
|
}
|
|
export async function fetchExportTransferReport(payload = {}, options = {}) {
|
return fetch(`${import.meta.env.VITE_API_URL}/transfer/export`, {
|
method: 'POST',
|
headers: {
|
'Content-Type': 'application/json',
|
...(options.headers || {})
|
},
|
body: JSON.stringify(payload)
|
})
|
}
|