import request from '@/utils/request' // ==================== 备件相关类型 ==================== // 备件分类 export interface SparePartCategory { id: string name: string description?: string createdAt?: string updatedAt?: string } // 备件 export interface SparePart { id: string name: string code: string categoryId?: string categoryName?: string projectId: string projectName?: string unit?: string currentStock?: number safeStock?: number lowStockWarning?: boolean description?: string createdAt?: string updatedAt?: string } // 备件表单 export interface SparePartForm { id?: string name: string code: string categoryId?: string projectId: string unit?: string currentStock?: number safeStock?: number description?: string } // 库存记录 export interface StockRecord { id: string sparePartId: string sparePartName?: string operationType: 'IN' | 'OUT' quantity: number beforeStock?: number afterStock?: number relatedOrderId?: string relatedOrderNo?: string operatorId?: string operatorName?: string remark?: string createdAt?: string } // 入库请求 export interface InStockRequest { sparePartId: string quantity: number remark?: string } // 出库请求 export interface OutStockRequest { sparePartId: string quantity: number relatedOrderId?: string relatedOrderNo?: string remark?: string } // 分页响应 export interface PageResponse { content: T[] totalElements: number totalPages: number size: number number: number } // ==================== 备件分类 API ==================== // 获取分类列表 export function getSparePartCategories() { return request.get('/api/v1/ops/spare-parts/categories') } // 创建分类 export function createSparePartCategory(data: { name: string; description?: string }) { return request.post('/api/v1/ops/spare-parts/categories', data) } // ==================== 备件 API ==================== // 获取备件列表 export function getSparePartList(projectId: string, categoryId?: string) { return request.get>('/api/v1/ops/spare-parts', { params: { projectId, categoryId } }) } // 获取备件详情 export function getSparePartDetail(id: string) { return request.get(`/api/v1/ops/spare-parts/${id}`) } // 创建备件 export function createSparePart(data: SparePartForm) { return request.post('/api/v1/ops/spare-parts', data) } // 更新备件 export function updateSparePart(id: string, data: SparePartForm) { return request.put(`/api/v1/ops/spare-parts/${id}`, data) } // 删除备件 export function deleteSparePart(id: string) { return request.delete(`/api/v1/ops/spare-parts/${id}`) } // 获取低库存备件 export function getLowStockSpareParts(projectId: string) { return request.get('/api/v1/ops/spare-parts/low-stock', { params: { projectId } }) } // 入库 export function inStock(data: InStockRequest) { return request.post('/api/v1/ops/spare-parts/in-stock', data) } // 出库 export function outStock(data: OutStockRequest) { return request.post('/api/v1/ops/spare-parts/out-stock', data) } // 获取备件记录 export function getSparePartRecords(id: string) { return request.get(`/api/v1/ops/spare-parts/${id}/records`) }