import request from '@/utils/http'
|
import {
|
buildCheckDiffItemPageRequestParams,
|
buildCheckDiffPageRequestParams
|
} from '../views/orders/check-diff/checkDiffPage.helpers'
|
|
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 buildCheckDiffPageParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...filterParams(params, ['current', 'pageSize', 'size'])
|
}
|
}
|
|
export function buildCheckDiffItemPageParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...filterParams(params, ['current', 'pageSize', 'size'])
|
}
|
}
|
|
export function fetchCheckDiffPage(params = {}) {
|
return request.post({ url: '/checkDiff/page', params: buildCheckDiffPageRequestParams(params) })
|
}
|
|
export function fetchGetCheckDiffDetail(id) {
|
return request.get({ url: `/checkDiff/${id}` })
|
}
|
|
export function fetchGetCheckDiffMany(ids) {
|
return request.post({ url: `/checkDiff/many/${normalizeIds(ids)}` })
|
}
|
|
export function fetchCheckDiffItemPage(params = {}) {
|
return request.post({ url: '/checkDiffItem/page', params: buildCheckDiffItemPageRequestParams(params) })
|
}
|
|
export function fetchGetCheckDiffItemDetail(id) {
|
return request.get({ url: `/checkDiffItem/${id}` })
|
}
|
|
export function fetchGetCheckDiffItemMany(ids) {
|
return request.post({ url: `/checkDiffItem/many/${normalizeIds(ids)}` })
|
}
|
|
export function fetchUpdateCheckDiffItem(params = {}) {
|
return request.post({ url: '/checkDiffItem/update', params })
|
}
|
|
export function fetchDeleteCheckDiff(ids) {
|
return request.post({ url: `/checkDiff/remove/${normalizeIds(ids)}` })
|
}
|
|
export function fetchDeleteCheckDiffItem(ids) {
|
return request.post({ url: `/checkDiffItem/remove/${normalizeIds(ids)}` })
|
}
|
|
export async function fetchExportCheckDiffReport(payload = {}, options = {}) {
|
return fetch(`${import.meta.env.VITE_API_URL}/checkDiff/export`, {
|
method: 'POST',
|
headers: {
|
'Content-Type': 'application/json',
|
...(options.headers || {})
|
},
|
body: JSON.stringify(payload)
|
})
|
}
|
|
export async function fetchExportCheckDiffItemReport(payload = {}, options = {}) {
|
return fetch(`${import.meta.env.VITE_API_URL}/checkDiffItem/export`, {
|
method: 'POST',
|
headers: {
|
'Content-Type': 'application/json',
|
...(options.headers || {})
|
},
|
body: JSON.stringify(payload)
|
})
|
}
|