101 lines
2.7 KiB
TypeScript
101 lines
2.7 KiB
TypeScript
import api from './index'
|
|
import type { ApiResponse } from '@/types'
|
|
import type { EquipmentStatus } from '@/types'
|
|
|
|
export interface MountChildRequest {
|
|
child_id: number
|
|
notes?: string
|
|
}
|
|
|
|
export interface UnmountChildRequest {
|
|
child_id: number
|
|
notes?: string
|
|
released_child_status?: Extract<EquipmentStatus, '可用' | '维护中' | '待报废' | '已报废'>
|
|
}
|
|
|
|
export interface ReplaceChildRequest {
|
|
old_child_id: number
|
|
new_child_id: number
|
|
notes?: string
|
|
released_child_status?: Extract<EquipmentStatus, '可用' | '维护中' | '待报废' | '已报废'>
|
|
}
|
|
|
|
export interface ChildEquipment {
|
|
id: number
|
|
equipment_code: string
|
|
equipment_name: string
|
|
equipment_model?: string
|
|
equipment_type: string
|
|
unit_price: number
|
|
status: string
|
|
mount_status?: string
|
|
}
|
|
|
|
export interface MountHistory {
|
|
id: number
|
|
child_id: number
|
|
parent_id: number | null
|
|
operation_type: 'mount' | 'unmount' | 'replace'
|
|
operated_at: string
|
|
operated_by: number
|
|
notes?: string
|
|
child: {
|
|
id: number
|
|
equipment_code: string
|
|
equipment_name: string
|
|
}
|
|
parent?: {
|
|
id: number
|
|
equipment_code: string
|
|
equipment_name: string
|
|
} | null
|
|
operator: {
|
|
id: number
|
|
name: string
|
|
username: string
|
|
}
|
|
}
|
|
|
|
// 挂载子资产到父资产
|
|
export const mountChild = async (parentId: number, data: MountChildRequest): Promise<ApiResponse<any>> => {
|
|
const response = await api.post(`/mount/${parentId}/mount`, data)
|
|
return response.data
|
|
}
|
|
|
|
// 从父资产卸载子资产
|
|
export const unmountChild = async (parentId: number, data: UnmountChildRequest): Promise<ApiResponse<any>> => {
|
|
const response = await api.post(`/mount/${parentId}/unmount`, data)
|
|
return response.data
|
|
}
|
|
|
|
// 更换配件
|
|
export const replaceChild = async (parentId: number, data: ReplaceChildRequest): Promise<ApiResponse<any>> => {
|
|
const response = await api.post(`/mount/${parentId}/replace`, data)
|
|
return response.data
|
|
}
|
|
|
|
// 获取父资产的子资产列表
|
|
export const getChildren = async (parentId: number): Promise<ApiResponse<{
|
|
children: ChildEquipment[]
|
|
total_children_value: number
|
|
total_value_with_children: number
|
|
}>> => {
|
|
const response = await api.get(`/mount/${parentId}/children`)
|
|
return response.data
|
|
}
|
|
|
|
// 获取资产的挂载历史
|
|
export const getMountHistory = async (equipmentId: number): Promise<ApiResponse<MountHistory[]>> => {
|
|
const response = await api.get(`/mount/${equipmentId}/mount-history`)
|
|
return response.data
|
|
}
|
|
|
|
// 获取可挂载的子资产列表
|
|
export const getAvailableChildren = async (params?: {
|
|
keyword?: string
|
|
equipment_type?: string
|
|
}): Promise<ApiResponse<ChildEquipment[]>> => {
|
|
const response = await api.get('/mount/available-children', { params })
|
|
return response.data
|
|
}
|