Files
zkxw/web-admin/src/api/material.ts
T
2026-07-01 16:37:33 +08:00

235 lines
4.7 KiB
TypeScript

import request from '@/utils/http'
type PageList<T> = {
list: T[]
total: number
page: number
pageSize: number
totalPages: number
}
export type Material = {
id: string
materialCode: string
materialName: string
category: string
specModel: string
unit: string
stockQty: number
warningQty: number
status: string
imageUrls: string
tenantNo: string
orderNum: number
remark: string
createBy: string
createTime: string
updateTime: string
}
/** 入库批次列表行 */
export type MaterialBatch = {
id: string
batchId: string
materialId: string
materialCode: string
materialName: string
category: string
specModel: string
unit: string
stockInNo: string
stockInDate: string
expireDate: string
catalogNo: string
batchNo: string
manufacturer: string
unitPrice: number
amount: number
inQty: number
remainingQty: number
stockQty: number
warningQty: number
status: string
remark: string
createTime: string
updateTime: string
}
export type MaterialOption = {
id: string
label: string
materialCode: string
materialName: string
category: string
specModel: string
unit: string
stockQty: number
}
export type MaterialBatchOption = {
id: string
batchId: string
stockInNo: string
stockInDate?: string
expireDate?: string
materialId: string
materialCode: string
materialName: string
category?: string
specModel: string
unit: string
batchNo: string
catalogNo: string
manufacturer: string
unitPrice?: number
amount?: number
remainingQty: number
label: string
}
export type StockInPayload = {
stockInNo?: string
stockInDate?: string
expireDate?: string
catalogNo?: string
batchNo?: string
manufacturer?: string
unitPrice?: number
amount?: number
qty?: number
remark?: string
stockInTime?: string
operatorName?: string
}
export type BatchStockInLine = StockInPayload & {
materialId: string
materialCode?: string
materialName?: string
specModel?: string
unit?: string
}
export function fetchMaterialBatchList(params?: {
page?: number
pageSize?: number
keyword?: string
materialId?: string
category?: string
status?: string
}) {
return request.get<PageList<MaterialBatch>>({
url: '/web/admin/material-batches',
params
})
}
export function fetchMaterialBatchOptions(params?: {
keyword?: string
materialId?: string
onlyAvailable?: boolean
}) {
return request.get<MaterialBatchOption[]>({
url: '/web/admin/material-batches/options',
params
})
}
export function fetchMaterialList(params?: {
page?: number
pageSize?: number
keyword?: string
category?: string
status?: string
}) {
return request.get<PageList<Material>>({
url: '/web/admin/materials',
params
})
}
export function fetchMaterialOptions() {
return request.get<MaterialOption[]>({
url: '/web/admin/materials/options'
})
}
export function fetchCreateMaterial(data: Record<string, any>) {
return request.post<Material>({
url: '/web/admin/materials',
data
})
}
export function fetchUpdateMaterial(id: string, data: Record<string, any>) {
return request.put<Material>({
url: `/web/admin/materials/${id}`,
data
})
}
export function fetchDeleteMaterial(id: string) {
return request.delete<void>({
url: `/web/admin/materials/${id}`
})
}
export function fetchStockInMaterial(materialId: string, data: StockInPayload) {
return request.post<MaterialBatch>({
url: `/web/admin/materials/${materialId}/stock-in`,
data
})
}
export function fetchBatchStockInMaterial(data: {
items: BatchStockInLine[]
remark?: string
stockInTime?: string
operatorName?: string
}) {
return request.post<{ count: number }>({
url: '/web/admin/material-batches/batch-stock-in',
data
})
}
export function fetchUpdateMaterialBatch(id: string, data: Record<string, any>) {
return request.put<MaterialBatch>({
url: `/web/admin/material-batches/${id}`,
data
})
}
export function fetchDeleteMaterialBatch(id: string) {
return request.delete<void>({
url: `/web/admin/material-batches/${id}`
})
}
export function fetchBatchStockOutMaterial(data: {
items: { batchId: string; qty: number; usageUnit?: string; remark?: string }[]
receiver?: string
purpose?: string
remark?: string
stockOutTime?: string
operatorName?: string
}) {
return request.post<{ count: number }>({
url: '/web/admin/material-batches/batch-stock-out',
data
})
}
export function fetchBatchDiscardMaterial(data: {
items: { batchId: string; qty: number; usageUnit?: string; remark?: string }[]
discardReason: string
remark?: string
discardTime?: string
operatorName?: string
}) {
return request.post<{ count: number }>({
url: '/web/admin/material-batches/batch-discard',
data
})
}