59 lines
2.0 KiB
TypeScript
59 lines
2.0 KiB
TypeScript
import type { CurrentUser, DeliveryTask, FileUploadResult, RiderIncomeSummary } from '../types'
|
|
import { apiGet, apiPost, apiPut, http } from './http'
|
|
|
|
export interface TaskGroups<T extends { status: string }> {
|
|
assigned: T[]
|
|
delivering: T[]
|
|
completed: T[]
|
|
exception: T[]
|
|
canceled: T[]
|
|
}
|
|
|
|
export function groupTasksByStatus<T extends { status: string }>(tasks: T[]): TaskGroups<T> {
|
|
return {
|
|
assigned: tasks.filter((task) => task.status === 'ASSIGNED' || task.status === 'ACCEPTED'),
|
|
delivering: tasks.filter((task) => task.status === 'DELIVERING'),
|
|
completed: tasks.filter((task) => task.status === 'DELIVERED' || task.status === 'COMPLETED'),
|
|
exception: tasks.filter((task) => task.status === 'EXCEPTION'),
|
|
canceled: tasks.filter((task) => task.status === 'CANCELED')
|
|
}
|
|
}
|
|
|
|
export function riderLogin(username: string, password: string) {
|
|
return apiPost<CurrentUser>('/api/auth/admin-login', { username, password })
|
|
}
|
|
|
|
export function listRiderTasks() {
|
|
return apiGet<DeliveryTask[]>('/api/rider/tasks')
|
|
}
|
|
|
|
export function getRiderTask(id: number) {
|
|
return apiGet<DeliveryTask>(`/api/rider/tasks/${id}`)
|
|
}
|
|
|
|
export function startRiderTask(id: number) {
|
|
return apiPut<DeliveryTask>(`/api/rider/tasks/${id}/start`)
|
|
}
|
|
|
|
export function deliverRiderTask(id: number, photoUrl?: string) {
|
|
return apiPut<DeliveryTask>(`/api/rider/tasks/${id}/delivered`, { photoUrl })
|
|
}
|
|
|
|
export function markRiderTaskException(id: number, exceptionType: string, exceptionNote: string) {
|
|
return apiPut<DeliveryTask>(`/api/rider/tasks/${id}/exception`, { exceptionType, exceptionNote })
|
|
}
|
|
|
|
export function getIncomeSummary() {
|
|
return apiGet<RiderIncomeSummary>('/api/rider/income-summary')
|
|
}
|
|
|
|
export async function uploadDeliveredPhoto(file: File) {
|
|
const data = new FormData()
|
|
data.append('file', file)
|
|
const response = await http.post<{ code: number; message: string; data: FileUploadResult }>('/api/files/upload', data)
|
|
if (response.data.code !== 0) {
|
|
throw new Error(response.data.message || '上传失败')
|
|
}
|
|
return response.data.data
|
|
}
|