189 lines
4.0 KiB
TypeScript
189 lines
4.0 KiB
TypeScript
import { formatTime, formatDate, formatDateTime, getHeaders } from './index';
|
|
|
|
const BASE_URL = 'http://localhost:3000' // 替换为你的实际后端地址
|
|
// 请求封装
|
|
const request = (url: string, options: any = {}) => {
|
|
const token = uni.getStorageSync('token')
|
|
return uni.request({
|
|
url: `${BASE_URL}${url}`,
|
|
method: options.method || 'GET',
|
|
data: options.data,
|
|
header: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': token ? `Bearer ${token}` : '',
|
|
...options.header
|
|
}
|
|
})
|
|
}
|
|
|
|
// 类型定义
|
|
export interface RequestItem {
|
|
id?: string
|
|
name: string
|
|
spec?: string
|
|
quantity: number
|
|
unit?: string
|
|
estimatedUnitCost?: number
|
|
remark?: string
|
|
catalogId?: string
|
|
requestId?: string
|
|
createdAt?: string
|
|
updatedAt?: string
|
|
}
|
|
|
|
export interface ConsumableRequest {
|
|
id?: string
|
|
applicantName?: string
|
|
applicantPhone: string
|
|
department?: string
|
|
reason?: string
|
|
status?: 'PENDING' | 'APPROVED' | 'REJECTED' | 'CANCELLED' | 'COMPLETED'
|
|
approverId?: string
|
|
approvedAt?: string
|
|
neededAt?: string
|
|
remark?: string
|
|
createdAt?: string
|
|
updatedAt?: string
|
|
items: RequestItem[]
|
|
}
|
|
|
|
export interface CatalogItem {
|
|
id?: string
|
|
name: string
|
|
spec?: string
|
|
unit?: string
|
|
isActive?: boolean
|
|
createdAt?: string
|
|
updatedAt?: string
|
|
}
|
|
|
|
export interface ListQuery {
|
|
page?: number
|
|
pageSize?: number
|
|
status?: string
|
|
applicantPhone?: string
|
|
from?: string
|
|
to?: string
|
|
}
|
|
|
|
export interface CatalogQuery {
|
|
page?: number
|
|
pageSize?: number
|
|
isActive?: boolean
|
|
q?: string
|
|
}
|
|
|
|
// API 方法
|
|
export default {
|
|
// 创建临时申请
|
|
createRequest(data: Partial<ConsumableRequest>) {
|
|
return request('/api/consumable-temp-requests', {
|
|
method: 'POST',
|
|
data
|
|
})
|
|
},
|
|
|
|
// 查询申请列表
|
|
getRequestList(params?: ListQuery) {
|
|
return request('/api/consumable-temp-requests', {
|
|
method: 'GET',
|
|
data: params
|
|
})
|
|
},
|
|
|
|
// 获取申请详情
|
|
getRequestDetail(id: string) {
|
|
return request(`/api/consumable-temp-requests/${id}`, {
|
|
method: 'GET'
|
|
})
|
|
},
|
|
|
|
// 更新申请
|
|
updateRequest(id: string, data: Partial<ConsumableRequest>) {
|
|
return request(`/api/consumable-temp-requests/${id}`, {
|
|
method: 'PUT',
|
|
data
|
|
})
|
|
},
|
|
|
|
// 删除申请
|
|
deleteRequest(id: string) {
|
|
return request(`/api/consumable-temp-requests/${id}`, {
|
|
method: 'DELETE'
|
|
})
|
|
},
|
|
|
|
// 更新申请状态
|
|
updateRequestStatus(id: string, data: {
|
|
status: string
|
|
approverId?: string
|
|
remark?: string
|
|
}) {
|
|
return request(`/api/consumable-temp-requests/${id}/status`, {
|
|
method: 'PATCH',
|
|
data
|
|
})
|
|
},
|
|
|
|
// 添加物料明细
|
|
addRequestItem(requestId: string, data: Partial<RequestItem>) {
|
|
return request(`/api/consumable-temp-requests/${requestId}/items`, {
|
|
method: 'POST',
|
|
data
|
|
})
|
|
},
|
|
|
|
// 更新物料明细
|
|
updateRequestItem(itemId: string, data: Partial<RequestItem>) {
|
|
return request(`/api/consumable-temp-items/${itemId}`, {
|
|
method: 'PUT',
|
|
data
|
|
})
|
|
},
|
|
|
|
// 删除物料明细
|
|
deleteRequestItem(itemId: string) {
|
|
return request(`/api/consumable-temp-items/${itemId}`, {
|
|
method: 'DELETE'
|
|
})
|
|
},
|
|
|
|
// 创建耗材目录
|
|
createCatalog(data: Partial<CatalogItem>) {
|
|
return request('/api/consumable-temp-catalog', {
|
|
method: 'POST',
|
|
data
|
|
})
|
|
},
|
|
|
|
// 查询目录列表
|
|
getCatalogList(params?: CatalogQuery) {
|
|
return request('/api/consumable-temp-catalog', {
|
|
method: 'GET',
|
|
data: params
|
|
})
|
|
},
|
|
|
|
// 获取目录详情
|
|
getCatalogDetail(id: string) {
|
|
return request(`/api/consumable-temp-catalog/${id}`, {
|
|
method: 'GET'
|
|
})
|
|
},
|
|
|
|
// 更新目录
|
|
updateCatalog(id: string, data: Partial<CatalogItem>) {
|
|
return request(`/api/consumable-temp-catalog/${id}`, {
|
|
method: 'PUT',
|
|
data
|
|
})
|
|
},
|
|
|
|
// 停用目录
|
|
deleteCatalog(id: string) {
|
|
return request(`/api/consumable-temp-catalog/${id}`, {
|
|
method: 'DELETE'
|
|
})
|
|
}
|
|
}
|