修复订单显示bug
This commit is contained in:
@@ -12,28 +12,11 @@ import {
|
||||
startDepartById,
|
||||
startServiceById
|
||||
} from '@/api/delivery.uts'
|
||||
import { saveServiceRecord as saveRealServiceRecord } from '@/services/serviceOrderService.uts'
|
||||
import {
|
||||
acceptCareOrder,
|
||||
checkInCareOrder,
|
||||
completeCareOrder,
|
||||
getCareOrderDetail,
|
||||
getCareRecords,
|
||||
getDeliveryCareDashboard,
|
||||
getDeliveryCareProfile,
|
||||
getHistoryCareOrders,
|
||||
getPendingCareOrders,
|
||||
getTodayCareOrders,
|
||||
markCareOrderArrived,
|
||||
markCareOrderDeparted,
|
||||
rejectCareOrder,
|
||||
startCareService,
|
||||
submitCareAbnormalReport,
|
||||
submitCareServiceRecord,
|
||||
updateCareOrderStatus,
|
||||
updateDeliveryCareOnlineStatus
|
||||
} from '@/mock/delivery-care.mock.uts'
|
||||
import { requireDeliveryAuth } from '@/utils/deliveryAuth.uts'
|
||||
getOrderDetail as getDirectServiceOrderDetail,
|
||||
getOrdersByTab as getDirectOrdersByTab
|
||||
} from '@/services/serviceOrderService.uts'
|
||||
import { getUserInfo, requireDeliveryAuth, setDeliveryInfo } from '@/utils/deliveryAuth.uts'
|
||||
import type {
|
||||
DeliveryAbnormalReportType,
|
||||
DeliveryCheckinPayloadType,
|
||||
@@ -53,6 +36,87 @@ import type {
|
||||
DeliveryServiceRecordType
|
||||
} from '@/types/delivery.uts'
|
||||
|
||||
function nowText(): string {
|
||||
return new Date().toISOString().replace('T', ' ').substring(0, 19)
|
||||
}
|
||||
|
||||
function emptyDashboard(): DeliveryDashboardType {
|
||||
return {
|
||||
pendingAssignmentCount: 0,
|
||||
pendingAcceptCount: 0,
|
||||
todayOrderCount: 0,
|
||||
pendingDepartCount: 0,
|
||||
servingCount: 0,
|
||||
completedCount: 0,
|
||||
exceptionCount: 0,
|
||||
expectedIncome: 0,
|
||||
onlineStatus: 'resting',
|
||||
nextOrder: null,
|
||||
recentOrders: [] as Array<DeliveryOrderType>
|
||||
} as DeliveryDashboardType
|
||||
}
|
||||
|
||||
async function getCurrentStaffIdOrEmpty(): Promise<string> {
|
||||
const authResult = await requireDeliveryAuth({ redirectOnFail: false, toastOnFail: false })
|
||||
if (!authResult.ok || authResult.deliveryInfo == null) {
|
||||
return ''
|
||||
}
|
||||
return authResult.deliveryInfo.id
|
||||
}
|
||||
|
||||
function hasOrderCoreInfo(order: DeliveryOrderType | null): boolean {
|
||||
if (order == null) {
|
||||
return false
|
||||
}
|
||||
return order.serviceName != '' || order.elderName != '' || order.address != '' || order.contactName != ''
|
||||
}
|
||||
|
||||
function filterOrdersWithCoreInfo(orders: Array<DeliveryOrderType>): Array<DeliveryOrderType> {
|
||||
const result = [] as Array<DeliveryOrderType>
|
||||
for (let i = 0; i < orders.length; i++) {
|
||||
if (hasOrderCoreInfo(orders[i])) {
|
||||
result.push(orders[i])
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function shouldFallbackOrders(orders: Array<DeliveryOrderType>): boolean {
|
||||
if (orders.length == 0) {
|
||||
return false
|
||||
}
|
||||
for (let i = 0; i < orders.length; i++) {
|
||||
if (hasOrderCoreInfo(orders[i])) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function mapOrderToRecord(order: DeliveryOrderType): DeliveryRecordType {
|
||||
const isAccepted = order.status == 'completed' || order.status == 'pending_acceptance' || order.status == 'settled' || order.status == 'archived'
|
||||
return {
|
||||
id: order.id,
|
||||
orderId: order.id,
|
||||
orderNo: order.orderNo,
|
||||
serviceName: order.serviceName,
|
||||
elderName: order.fullElderName != '' ? order.fullElderName : order.elderName,
|
||||
elderNameMasked: order.elderNameMasked != '' ? order.elderNameMasked : order.elderName,
|
||||
status: order.status,
|
||||
statusText: order.statusText,
|
||||
appointmentStartTime: order.appointmentStartTime,
|
||||
appointmentTime: order.appointmentTime,
|
||||
actualStartTime: order.actualStartTime,
|
||||
actualEndTime: order.actualEndTime != '' ? order.actualEndTime : order.finishTime,
|
||||
staffIncome: order.staffIncome,
|
||||
settlementStatus: order.settlementStatus != '' ? order.settlementStatus : '待结算',
|
||||
acceptanceStatus: order.status,
|
||||
exceptionDesc: order.exceptionDesc,
|
||||
ratingText: isAccepted ? '已验收' : (order.status == 'pending_acceptance' ? '待验收' : '待补充'),
|
||||
hasServiceRecord: order.serviceRecord != null
|
||||
} as DeliveryRecordType
|
||||
}
|
||||
|
||||
export async function loginDelivery(payload: DeliveryLoginPayloadType): Promise<DeliveryLoginResultType> {
|
||||
return await loginDeliveryApi(payload)
|
||||
}
|
||||
@@ -228,19 +292,63 @@ export async function getDeliveryDashboardStats(): Promise<DeliveryDashboardType
|
||||
}
|
||||
|
||||
export async function getPendingServiceOrders(): Promise<Array<DeliveryOrderType>> {
|
||||
return await getDeliveryOrders({ tab: 'pending', keyword: '' } as DeliveryOrderQueryType)
|
||||
const orders = await getDeliveryOrders({ tab: 'pending', keyword: '' } as DeliveryOrderQueryType)
|
||||
const validOrders = filterOrdersWithCoreInfo(orders)
|
||||
if (validOrders.length > 0) {
|
||||
return validOrders
|
||||
}
|
||||
if (shouldFallbackOrders(orders)) {
|
||||
console.warn('[deliveryService] pending orders missing core info, fallback to direct query')
|
||||
const fallbackOrders = await getDirectOrdersByTab('pending')
|
||||
if (fallbackOrders.length > 0) {
|
||||
return fallbackOrders
|
||||
}
|
||||
}
|
||||
return orders
|
||||
}
|
||||
|
||||
export async function getTodayServiceOrders(): Promise<Array<DeliveryOrderType>> {
|
||||
return await getDeliveryOrders({ tab: 'today', keyword: '' } as DeliveryOrderQueryType)
|
||||
const orders = await getDeliveryOrders({ tab: 'today', keyword: '' } as DeliveryOrderQueryType)
|
||||
const validOrders = filterOrdersWithCoreInfo(orders)
|
||||
if (validOrders.length > 0) {
|
||||
return validOrders
|
||||
}
|
||||
if (shouldFallbackOrders(orders)) {
|
||||
console.warn('[deliveryService] today orders missing core info, fallback to direct query')
|
||||
const fallbackOrders = await getDirectOrdersByTab('today')
|
||||
if (fallbackOrders.length > 0) {
|
||||
return fallbackOrders
|
||||
}
|
||||
}
|
||||
return orders
|
||||
}
|
||||
|
||||
export async function getHistoryServiceOrders(): Promise<Array<DeliveryOrderType>> {
|
||||
return await getDeliveryOrders({ tab: 'history', keyword: '' } as DeliveryOrderQueryType)
|
||||
const orders = await getDeliveryOrders({ tab: 'history', keyword: '' } as DeliveryOrderQueryType)
|
||||
const validOrders = filterOrdersWithCoreInfo(orders)
|
||||
if (validOrders.length > 0) {
|
||||
return validOrders
|
||||
}
|
||||
if (shouldFallbackOrders(orders)) {
|
||||
console.warn('[deliveryService] history orders missing core info, fallback to direct query')
|
||||
const fallbackOrders = await getDirectOrdersByTab('history')
|
||||
if (fallbackOrders.length > 0) {
|
||||
return fallbackOrders
|
||||
}
|
||||
}
|
||||
return orders
|
||||
}
|
||||
|
||||
export async function getServiceOrderDetail(orderId: string): Promise<DeliveryOrderType | null> {
|
||||
return await getDeliveryOrderDetail(orderId)
|
||||
const order = await getDeliveryOrderDetailById(orderId)
|
||||
if (!hasOrderCoreInfo(order)) {
|
||||
console.warn('[deliveryService] order detail missing core info, fallback to direct query:', orderId)
|
||||
const fallbackOrder = await getDirectServiceOrderDetail(orderId)
|
||||
if (hasOrderCoreInfo(fallbackOrder)) {
|
||||
return fallbackOrder
|
||||
}
|
||||
}
|
||||
return order
|
||||
}
|
||||
|
||||
export async function acceptServiceOrder(orderId: string): Promise<DeliveryOrderType | null> {
|
||||
@@ -294,4 +402,4 @@ export async function updateOrderStatus(orderId: string, nextStatus: DeliveryOrd
|
||||
export async function getAbnormalReport(orderId: string): Promise<DeliveryAbnormalReportType | null> {
|
||||
const order = getCareOrderDetail(orderId)
|
||||
return order != null ? order.abnormalReport : null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user