import type { DeliveryOrderStatus, DeliveryOrderType } from '@/types/delivery.uts' export type DeliveryTabOptionType = { label: string value: string } function normalizeStatus(status: DeliveryOrderStatus): string { return String(status ?? '').trim().toLowerCase() } export function getDeliveryOrderTabs(): Array { return [ { label: '待接单', value: 'pending' } as DeliveryTabOptionType, { label: '进行中', value: 'today' } as DeliveryTabOptionType, { label: '历史订单', value: 'history' } as DeliveryTabOptionType ] } export function isHistoryStatus(status: DeliveryOrderStatus): boolean { const s = normalizeStatus(status) return s == 'completed' || s == 'settled' || s == 'archived' || s == 'cancelled' || s == 'canceled' || s == 'rejected' || s == 'abnormal' || s == 'exception_pending' || s == 'terminated' || s == 'order_completed' || s == 'order_cancelled' } export function getDeliveryStatusLabel(status: DeliveryOrderStatus): string { const s = normalizeStatus(status) if (s == 'pending' || s == 'pending_assignment' || s == 'pending_accept' || s == 'pending_assign' || s == 'pending_dispatch' || s == 'pending_acceptance_new') return '待接单' if (s == 'assigned') return '已派单' if (s == 'accepted' || s == 'order_accepted' || s == 'waiting_departure') return '待出发' if (s == 'departed' || s == 'on_the_way' || s == 'order_departed') return '已出发' if (s == 'arrival_pending') return '等待消费者确认到达' if (s == 'arrived' || s == 'checked_in' || s == 'order_checked_in') return '已到达' if (s == 'in_service' || s == 'serving' || s == 'order_in_service') return '服务中' if (s == 'pending_acceptance' || s == 'pending_confirm' || s == 'pending_submit') return '等待验收' if (s == 'completed' || s == 'order_completed' || s == 'settled') return '已完成' if (s == 'rejected') return '已拒单' if (s == 'cancelled' || s == 'canceled' || s == 'order_cancelled') return '已取消' if (s == 'abnormal' || s == 'exception_pending') return '异常上报' if (s == 'terminated') return '服务终止' if (s == 'archived') return '已归档' return '查看详情' } export function getPrimaryActionText(status: DeliveryOrderStatus): string { const s = normalizeStatus(status) if (s == 'pending' || s == 'pending_assignment' || s == 'pending_accept' || s == 'pending_assign' || s == 'pending_dispatch' || s == 'pending_acceptance_new') return '接单' if (s == 'assigned' || s == 'accepted' || s == 'waiting_departure' || s == 'order_accepted') return '出发' if (s == 'departed' || s == 'on_the_way' || s == 'order_departed') return '到达签到' if (s == 'arrival_pending') return '等待确认' if (s == 'arrived' || s == 'checked_in' || s == 'order_checked_in') return '开始服务' if (s == 'in_service' || s == 'serving' || s == 'order_in_service') return '继续服务' if (s == 'completed' || s == 'order_completed' || s == 'settled' || s == 'archived') return '查看详情' return '查看详情' } export function getNextStepText(status: DeliveryOrderStatus): string { const s = normalizeStatus(status) if (s == 'pending' || s == 'pending_assignment' || s == 'pending_accept' || s == 'pending_assign' || s == 'pending_dispatch' || s == 'pending_acceptance_new') return '确认是否接单' if (s == 'assigned' || s == 'accepted' || s == 'waiting_departure' || s == 'order_accepted') return '准备出发前往服务地址' if (s == 'departed' || s == 'on_the_way' || s == 'order_departed') return '到达服务地点后完成签到' if (s == 'arrival_pending') return '等待消费者确认到达' if (s == 'arrived' || s == 'checked_in' || s == 'order_checked_in') return '开始服务并补充记录' if (s == 'in_service' || s == 'serving' || s == 'order_in_service') return '继续服务并完善服务记录' if (s == 'pending_acceptance' || s == 'pending_confirm' || s == 'pending_submit') return '等待用户确认验收' if (s == 'completed' || s == 'order_completed' || s == 'settled') return '查看历史服务记录' if (s == 'abnormal' || s == 'exception_pending') return '跟进异常处理' return '查看订单详情' } export function getStatusClass(status: DeliveryOrderStatus): string { const s = normalizeStatus(status) if (s == 'pending' || s == 'pending_assignment' || s == 'pending_accept' || s == 'pending_assign' || s == 'pending_dispatch' || s == 'pending_acceptance_new' || s == 'pending_confirm' || s == 'pending_acceptance' || s == 'pending_submit' || s == 'arrival_pending') return 'warning' if (s == 'assigned' || s == 'accepted' || s == 'waiting_departure' || s == 'departed' || s == 'on_the_way' || s == 'order_accepted' || s == 'order_departed') return 'primary' if (s == 'completed' || s == 'order_completed' || s == 'settled' || s == 'archived') return 'success' if (s == 'abnormal' || s == 'exception_pending') return 'danger' if (s == 'rejected' || s == 'cancelled' || s == 'canceled' || s == 'terminated' || s == 'order_cancelled') return 'muted' return 'primary' } export function needsServiceRecord(order: DeliveryOrderType): boolean { return order.serviceRecord == null }