123 lines
3.4 KiB
TypeScript
123 lines
3.4 KiB
TypeScript
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
|
import type { SupplierCategory } from '@/modules/suppliers'
|
|
|
|
export type FeeItemTradeScope = 'DOMESTIC' | 'INTERNATIONAL'
|
|
export type FeeItemStatus = 'ACTIVE' | 'DISABLED'
|
|
|
|
export interface PlatformFeeItemResource {
|
|
id: number | string
|
|
category: string
|
|
tradeScope: FeeItemTradeScope
|
|
feeCode: string | null
|
|
supplierCategory: SupplierCategory | null
|
|
feeTypeName: string
|
|
pickupPayable: boolean
|
|
pickupReceivable: boolean
|
|
warehousePayable: boolean
|
|
warehouseReceivable: boolean
|
|
allocationFee: boolean
|
|
description: string | null
|
|
status: FeeItemStatus
|
|
createdByName?: string | null
|
|
updatedByName?: string | null
|
|
createdAt?: string | null
|
|
updatedAt?: string | null
|
|
}
|
|
|
|
export interface SavePlatformFeeItemRequest {
|
|
category: string
|
|
tradeScope: FeeItemTradeScope
|
|
feeTypeName: string
|
|
supplierCategory: SupplierCategory | null
|
|
pickupPayable: boolean
|
|
pickupReceivable: boolean
|
|
warehousePayable: boolean
|
|
warehouseReceivable: boolean
|
|
allocationFee: boolean
|
|
description: string | null
|
|
}
|
|
|
|
export interface PlatformFeeItemQuery {
|
|
category?: string
|
|
tradeScope?: FeeItemTradeScope | ''
|
|
keyword?: string
|
|
status?: FeeItemStatus | ''
|
|
page: number
|
|
size: number
|
|
}
|
|
|
|
export interface PlatformFeeItemPage {
|
|
records: PlatformFeeItemResource[]
|
|
page: number
|
|
size: number
|
|
total: number
|
|
pages: number
|
|
}
|
|
|
|
const basePath = '/platform/v1/fee-items'
|
|
|
|
export async function listPlatformFeeItems(query: PlatformFeeItemQuery) {
|
|
const response = await http.get<ApiEnvelope<PlatformFeeItemPage>, ApiEnvelope<PlatformFeeItemPage>>(basePath, {
|
|
params: {
|
|
category: query.category?.trim() || undefined,
|
|
tradeScope: query.tradeScope || undefined,
|
|
keyword: query.keyword?.trim() || undefined,
|
|
status: query.status || undefined,
|
|
page: query.page,
|
|
size: query.size,
|
|
},
|
|
})
|
|
const result = unwrapApiResponse(response)
|
|
return {
|
|
...result,
|
|
records: result.records || [],
|
|
page: Number(result.page),
|
|
size: Number(result.size),
|
|
total: Number(result.total),
|
|
pages: Number(result.pages),
|
|
}
|
|
}
|
|
|
|
export async function getPlatformFeeItem(id: number | string) {
|
|
const response = await http.get<ApiEnvelope<PlatformFeeItemResource>, ApiEnvelope<PlatformFeeItemResource>>(
|
|
`${basePath}/${id}`,
|
|
|
|
)
|
|
return unwrapApiResponse(response)
|
|
}
|
|
|
|
export async function createPlatformFeeItem(payload: SavePlatformFeeItemRequest) {
|
|
const response = await http.post<ApiEnvelope<PlatformFeeItemResource>, ApiEnvelope<PlatformFeeItemResource>>(
|
|
basePath,
|
|
payload,
|
|
|
|
)
|
|
return unwrapApiResponse(response)
|
|
}
|
|
|
|
export async function updatePlatformFeeItem(id: number | string, payload: SavePlatformFeeItemRequest) {
|
|
const response = await http.put<ApiEnvelope<PlatformFeeItemResource>, ApiEnvelope<PlatformFeeItemResource>>(
|
|
`${basePath}/${id}`,
|
|
payload,
|
|
|
|
)
|
|
return unwrapApiResponse(response)
|
|
}
|
|
|
|
export async function changePlatformFeeItemStatus(id: number | string, status: FeeItemStatus) {
|
|
const response = await http.patch<ApiEnvelope<null>, ApiEnvelope<null>>(
|
|
`${basePath}/${id}/status`,
|
|
{ status },
|
|
|
|
)
|
|
return unwrapApiResponse(response)
|
|
}
|
|
|
|
export async function deletePlatformFeeItem(id: number | string) {
|
|
const response = await http.delete<ApiEnvelope<null>, ApiEnvelope<null>>(
|
|
`${basePath}/${id}`,
|
|
|
|
)
|
|
return unwrapApiResponse(response)
|
|
}
|