完成距离预校验
This commit is contained in:
@@ -16,7 +16,13 @@ import {
|
||||
getOrderDetail as getDirectServiceOrderDetail,
|
||||
getOrdersByTab as getDirectOrdersByTab
|
||||
} from '@/services/serviceOrderService.uts'
|
||||
import { getUserInfo, requireDeliveryAuth, setDeliveryInfo } from '@/utils/deliveryAuth.uts'
|
||||
import {
|
||||
getDeliveryInfo,
|
||||
getUserInfo,
|
||||
requireDeliveryAuth,
|
||||
setDeliveryInfo
|
||||
} from '@/utils/deliveryAuth.uts'
|
||||
import { getCurrentAkUserId as readCurrentAkUserId } from '@/utils/akUserMapping.uts'
|
||||
import type {
|
||||
DeliveryAbnormalReportType,
|
||||
DeliveryCheckinPayloadType,
|
||||
@@ -147,13 +153,17 @@ export async function checkDeliveryAuth(): Promise<boolean> {
|
||||
}
|
||||
|
||||
async function getCurrentStaffId(): Promise<string> {
|
||||
const profile = await getDeliveryProfile()
|
||||
if (profile == null) {
|
||||
return ''
|
||||
}
|
||||
return profile.id
|
||||
// 旧 delivery RPC(dashboard / order_list)需要 ml_delivery_staff.id(513449ca...)
|
||||
const deliveryInfo = getDeliveryInfo()
|
||||
if (deliveryInfo != null && deliveryInfo.id != null && String(deliveryInfo.id) != '') {
|
||||
console.warn('[deliveryService] getCurrentStaffId: 使用 deliveryStaffId =', String(deliveryInfo.id))
|
||||
return String(deliveryInfo.id)
|
||||
}
|
||||
|
||||
console.error('[deliveryService] getCurrentStaffId: 未获取到 deliveryStaffId')
|
||||
return ''
|
||||
}
|
||||
|
||||
function createEmptyLocation(): DeliveryLocationType {
|
||||
return {
|
||||
latitude: 0,
|
||||
@@ -168,7 +178,9 @@ export async function getDeliveryDashboard(): Promise<DeliveryDashboardType> {
|
||||
if (staffId != '') {
|
||||
return await getDeliveryDashboardByStaffId(staffId)
|
||||
}
|
||||
return getDeliveryCareDashboard()
|
||||
// staffId 为空时返回空 dashboard
|
||||
console.error('[deliveryService] getDeliveryDashboard: staffId 为空,返回空数据')
|
||||
return emptyDashboard()
|
||||
}
|
||||
|
||||
export async function getDeliveryOrders(params: DeliveryOrderQueryType): Promise<Array<DeliveryOrderType>> {
|
||||
@@ -176,13 +188,9 @@ export async function getDeliveryOrders(params: DeliveryOrderQueryType): Promise
|
||||
if (staffId != '') {
|
||||
return await getDeliveryOrdersByStaffId(staffId, params)
|
||||
}
|
||||
if (params.tab == 'pending' || params.tab == 'pending_assignment') {
|
||||
return getPendingCareOrders()
|
||||
}
|
||||
if (params.tab == 'history' || params.tab == 'completed' || params.tab == 'archive') {
|
||||
return getHistoryCareOrders()
|
||||
}
|
||||
return getTodayCareOrders()
|
||||
// staffId 为空时返回空列表
|
||||
console.error('[deliveryService] getDeliveryOrders: staffId 为空,返回空列表')
|
||||
return [] as Array<DeliveryOrderType>
|
||||
}
|
||||
|
||||
export async function getDeliveryOrderDetail(id: string): Promise<DeliveryOrderType | null> {
|
||||
@@ -352,7 +360,60 @@ export async function getServiceOrderDetail(orderId: string): Promise<DeliveryOr
|
||||
}
|
||||
|
||||
export async function acceptServiceOrder(orderId: string): Promise<DeliveryOrderType | null> {
|
||||
return await acceptDeliveryOrder(orderId)
|
||||
// 居家服务订单必须调用 rpc_homecare_accept_assignment_v2
|
||||
// 不再调用 acceptDeliveryOrder / rpc_delivery_accept_order
|
||||
const akUserId = await resolveCurrentAkUserIdForDelivery()
|
||||
console.warn('[HOMECARE ACCEPT] acceptServiceOrder: orderId=', orderId, ' akUserId=', akUserId)
|
||||
|
||||
if (akUserId == '') {
|
||||
uni.showToast({ title: '未获取到业务用户 ID,请重新登录', icon: 'none' })
|
||||
return null
|
||||
}
|
||||
|
||||
// 调用居家服务接单 RPC
|
||||
const { acceptHomecareAssignmentV2 } = await import('@/api/delivery.uts')
|
||||
const result = await acceptHomecareAssignmentV2(orderId, akUserId)
|
||||
console.warn('[HOMECARE ACCEPT] rpc_homecare_accept_assignment_v2 result:', result)
|
||||
|
||||
// 刷新订单列表
|
||||
await loadData()
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前业务用户 ID(从 akUserMapping 或缓存)
|
||||
*/
|
||||
async function resolveCurrentAkUserIdForDelivery(): Promise<string> {
|
||||
try {
|
||||
const id = await readCurrentAkUserId()
|
||||
if (id != null && id != '') {
|
||||
console.warn('[deliveryService] resolveCurrentAkUserIdForDelivery: from akUserMapping =', id)
|
||||
return id
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[deliveryService] readCurrentAkUserId failed:', e)
|
||||
}
|
||||
|
||||
try {
|
||||
const cached = uni.getStorageSync('ak_user_id')
|
||||
if (cached != null && String(cached) != '') {
|
||||
console.warn('[deliveryService] resolveCurrentAkUserIdForDelivery: from storage ak_user_id =', String(cached))
|
||||
return String(cached)
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
const currentAkUser = uni.getStorageSync('current_ak_user')
|
||||
if (currentAkUser != null && String(currentAkUser) != '') {
|
||||
const obj = JSON.parse(String(currentAkUser)) as any
|
||||
if (obj != null && obj.id != null && String(obj.id) != '') {
|
||||
console.warn('[deliveryService] resolveCurrentAkUserIdForDelivery: from current_ak_user.id =', String(obj.id))
|
||||
return String(obj.id)
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
export async function rejectServiceOrder(orderId: string, reason: string): Promise<DeliveryOrderType | null> {
|
||||
|
||||
Reference in New Issue
Block a user