217 lines
5.6 KiB
TypeScript
217 lines
5.6 KiB
TypeScript
import api from './index'
|
|
import { toApiDateTime } from '@/utils/dateTime'
|
|
import type {
|
|
BorrowRecord,
|
|
PaginatedResponse,
|
|
ApiResponse,
|
|
EquipmentStatus,
|
|
StorageLocation
|
|
} from '@/types'
|
|
|
|
export interface ScanBorrowResult {
|
|
id: number
|
|
equipment_code: string
|
|
equipment_name: string
|
|
borrow_time: string
|
|
status: string
|
|
remaining_quantity?: number
|
|
equipment_status?: EquipmentStatus
|
|
storage_location_id?: number | null
|
|
storageLocation?: StorageLocation | null
|
|
}
|
|
|
|
export interface ReturnSearchAssetCandidate {
|
|
equipment_id: number
|
|
equipment_code: string
|
|
equipment_name: string
|
|
equipment_model?: string | null
|
|
equipment_type?: string | null
|
|
storage_location_id?: number | null
|
|
storageLocation?: StorageLocation | null
|
|
active_borrow_count: number
|
|
borrower_names?: string[]
|
|
borrower_departments?: string[]
|
|
can_return?: boolean
|
|
can_handle_borrow_anomaly?: boolean
|
|
borrow_anomaly_blocked_reason?: string | null
|
|
search_state?: 'returnable' | 'borrow_record_missing'
|
|
state_message?: string
|
|
}
|
|
|
|
// 借用设备
|
|
export const borrowEquipment = async (data: {
|
|
equipment_id?: number
|
|
equipment_code?: string
|
|
person_id: number
|
|
expected_return_time?: string
|
|
notes?: string
|
|
is_long_term?: boolean
|
|
}) => {
|
|
const response = await api.post<ApiResponse<BorrowRecord>>('/borrow', { ...data, expected_return_time: data.is_long_term ? undefined : toApiDateTime(data.expected_return_time) })
|
|
return response.data
|
|
}
|
|
|
|
// 扫码出库
|
|
export const scanBorrow = async (data: {
|
|
equipment_code: string
|
|
person_id: number
|
|
expected_return_time?: string
|
|
notes?: string
|
|
is_long_term?: boolean
|
|
}) => {
|
|
const response = await api.post<ApiResponse<ScanBorrowResult>>('/borrow/scan', { ...data, expected_return_time: data.is_long_term ? undefined : toApiDateTime(data.expected_return_time) })
|
|
return response.data
|
|
}
|
|
|
|
// 批量扫码出库
|
|
export const scanBorrowBatch = async (data: {
|
|
equipment_codes: string[]
|
|
person_id: number
|
|
expected_return_time?: string
|
|
notes?: string
|
|
is_long_term?: boolean
|
|
}) => {
|
|
const response = await api.post<ApiResponse<{
|
|
success_count: number
|
|
failed_count: number
|
|
results: Array<{
|
|
equipment_code: string
|
|
status: string
|
|
message: string
|
|
}>
|
|
}>>('/borrow/scan-batch', { ...data, expected_return_time: data.is_long_term ? undefined : toApiDateTime(data.expected_return_time) })
|
|
return response.data
|
|
}
|
|
|
|
// 归还设备
|
|
export const returnEquipment = async (data: {
|
|
equipment_id: number
|
|
equipment_code: string
|
|
person_id?: number
|
|
borrow_record_id?: number
|
|
return_condition?: string
|
|
notes?: string
|
|
confirm_children_diff?: boolean
|
|
confirmation_token?: string
|
|
}) => {
|
|
const response = await api.post<ApiResponse<BorrowRecord>>('/return', data)
|
|
return response.data
|
|
}
|
|
|
|
// 扫码入库
|
|
export const scanReturn = async (data: {
|
|
equipment_code: string
|
|
return_condition?: string
|
|
notes?: string
|
|
person_id?: number
|
|
borrow_record_id?: number
|
|
confirm_children_diff?: boolean
|
|
confirmation_token?: string
|
|
}) => {
|
|
const response = await api.post<
|
|
ApiResponse<{
|
|
id: number
|
|
equipment_code: string
|
|
equipment_name: string
|
|
return_time: string
|
|
status: string
|
|
person_id?: number
|
|
need_confirm?: boolean
|
|
message?: string
|
|
confirmation_token?: string
|
|
children_diff?: {
|
|
removed: Array<Record<string, any>>
|
|
added: Array<Record<string, any>>
|
|
}
|
|
}>
|
|
>('/return/scan', data)
|
|
return response.data
|
|
}
|
|
|
|
// 批量扫码入库
|
|
export const scanReturnBatch = async (data: {
|
|
equipment_codes: string[]
|
|
return_condition?: string
|
|
notes?: string
|
|
}) => {
|
|
const response = await api.post<ApiResponse<{
|
|
success_count: number
|
|
failed_count: number
|
|
results: Array<{
|
|
equipment_code: string
|
|
status: string
|
|
message: string
|
|
}>
|
|
}>>('/return/scan-batch', data)
|
|
return response.data
|
|
}
|
|
|
|
// 根据设备编码查询借用记录
|
|
export const getBorrowRecordByCode = async (equipmentCode: string) => {
|
|
const response = await api.get<ApiResponse<{
|
|
equipment_code: string
|
|
equipment_name: string
|
|
unit_price: number
|
|
equipment_value: number
|
|
storage_location_id?: number | null
|
|
storageLocation?: StorageLocation | null
|
|
borrow_records: BorrowRecord[]
|
|
can_return: boolean
|
|
message: string
|
|
}>>(`/borrow/scan/${equipmentCode}`)
|
|
return response.data
|
|
}
|
|
|
|
export const searchReturnAssets = async (params: { keyword?: string }) => {
|
|
const response = await api.get<ApiResponse<ReturnSearchAssetCandidate[]>>('/return/search-assets', {
|
|
params
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
export const resolveBorrowAnomalyAsReturned = async (equipmentId: number) => {
|
|
const response = await api.post<ApiResponse<{
|
|
equipment_id: number
|
|
equipment_code: string
|
|
equipment_name: string
|
|
status: string
|
|
remaining_quantity: number
|
|
}>>(`/borrow/anomalies/${equipmentId}/mark-returned`)
|
|
return response.data
|
|
}
|
|
|
|
export const registerBorrowAnomaly = async (
|
|
equipmentId: number,
|
|
data: {
|
|
person_id: number
|
|
borrow_time: string
|
|
notes?: string
|
|
}
|
|
) => {
|
|
const response = await api.post<ApiResponse<{
|
|
id: number
|
|
equipment_id: number
|
|
equipment_code: string
|
|
equipment_name: string
|
|
borrow_time: string
|
|
status: string
|
|
children_count: number
|
|
}>>(`/borrow/anomalies/${equipmentId}/register-borrow`, data)
|
|
return response.data
|
|
}
|
|
|
|
// 获取借用记录列表
|
|
export const getBorrowRecordList = async (params: {
|
|
page?: number
|
|
pageSize?: number
|
|
status?: string
|
|
person_name?: string
|
|
person_id?: number
|
|
keyword?: string
|
|
}) => {
|
|
const response = await api.get<ApiResponse<PaginatedResponse<BorrowRecord>>>('/borrow/records', {
|
|
params
|
|
})
|
|
return response.data
|
|
}
|