修改页面逻辑
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<view class="delivery-order-detail">
|
||||
<view class="page-content">
|
||||
<!-- 返回按钮 -->
|
||||
<view class="back-header">
|
||||
<view class="back-box" @click="goBack">
|
||||
@@ -47,7 +48,7 @@
|
||||
<view class="route-icon">📦</view>
|
||||
<view class="route-content">
|
||||
<text class="route-title">取货地址</text>
|
||||
<text class="route-address">{{ merchant.contact_name }} · {{ merchant.contact_phone }}</text>
|
||||
<text class="route-address">{{ merchant.contact_name ? (merchant.contact_name + ' · ') : '' }}{{ merchant.contact_phone }}</text>
|
||||
<text class="route-detail">{{ pickupAddress }}</text>
|
||||
</view>
|
||||
<!-- 只在取货中状态且订单未完成时显示按钮 -->
|
||||
@@ -60,7 +61,7 @@
|
||||
<view class="route-icon">🏠</view>
|
||||
<view class="route-content">
|
||||
<text class="route-title">送货地址</text>
|
||||
<text class="route-address">{{ getDeliveryAddress().name }} · {{ getDeliveryAddress().phone }}</text>
|
||||
<text class="route-address">{{ getDeliveryAddress().name ? (getDeliveryAddress().name + ' · ') : '' }}{{ (order.delivery_address as UTSJSONObject)['phone'] || '' }}</text>
|
||||
<text class="route-detail">{{ getDeliveryAddress().detail }}</text>
|
||||
</view>
|
||||
<!-- 只在已取货状态且订单未完成时显示按钮 -->
|
||||
@@ -143,7 +144,7 @@
|
||||
<view class="contact-icon">📞</view>
|
||||
<view class="contact-info">
|
||||
<text class="contact-name">联系顾客</text>
|
||||
<text class="contact-phone">{{ getDeliveryAddress().phone }}</text>
|
||||
<text class="contact-phone">{{ (order.delivery_address as UTSJSONObject)['phone'] || '' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="contact-item" @click="callMerchant">
|
||||
@@ -156,6 +157,8 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
|
||||
<!-- 底部操作 -->
|
||||
<view class="bottom-actions">
|
||||
<!-- 只在待接单状态且订单未完成时显示接受/拒绝订单按钮 -->
|
||||
@@ -249,30 +252,78 @@ export default {
|
||||
async loadOrderDetail(orderId: string) {
|
||||
const originalStatus = this.order.status
|
||||
try {
|
||||
await supaReady
|
||||
console.log('loadOrderDetail called', { orderId })
|
||||
// 使用 1.5s 超时策略包装 supaReady,防止 session 刷新卡死页面
|
||||
const readyPromise = supaReady
|
||||
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('supaReady timeout')), 1500))
|
||||
try {
|
||||
await Promise.race([readyPromise, timeoutPromise])
|
||||
} catch (e) {
|
||||
console.warn('loadOrderDetail: supaReady timeout, proceeding with current session', e)
|
||||
}
|
||||
|
||||
// 获取订单主表:按 id(UUID) / cid(数字) / order_no 三种可能匹配
|
||||
console.log('loadOrderDetail: start loading', { orderId, originalStatus })
|
||||
uni.showLoading({ title: '加载中...' })
|
||||
|
||||
// 配送端详情页逻辑:
|
||||
// 1. 先尝试直接查 ml_orders (传入的是真实订单ID时)
|
||||
// 2. 如果没查到,尝试从 ml_delivery_tasks 查找 (传入的是任务ID时)
|
||||
// 3. 如果从任务表查到了,再拿其关联的 order_id 回查 ml_orders
|
||||
|
||||
let targetOrderId = orderId
|
||||
let orderRes: any = null
|
||||
let taskData: any = null
|
||||
|
||||
const isUuid = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(orderId)
|
||||
const isNumber = /^\d+$/.test(orderId)
|
||||
console.log('loadOrderDetail: supa session=', supa.getSession && supa.getSession())
|
||||
|
||||
console.log('loadOrderDetail: detect id format', { isUuid, isNumber })
|
||||
|
||||
// 步骤 A: 查 ml_orders
|
||||
if (isUuid) {
|
||||
console.log('loadOrderDetail: querying by id')
|
||||
orderRes = await supa.from('ml_orders').select('*').eq('id', orderId).limit(1).execute()
|
||||
} else if (isNumber) {
|
||||
console.log('loadOrderDetail: querying by cid')
|
||||
orderRes = await supa.from('ml_orders').select('*').eq('cid', Number(orderId)).limit(1).execute()
|
||||
} else {
|
||||
console.log('loadOrderDetail: querying by order_no')
|
||||
orderRes = await supa.from('ml_orders').select('*').eq('order_no', orderId).limit(1).execute()
|
||||
}
|
||||
console.log('loadOrderDetail: orderRes=', orderRes)
|
||||
|
||||
// 步骤 B: 如果订单没查到,尝试从任务表查
|
||||
if (!(orderRes && Array.isArray(orderRes.data) && orderRes.data.length > 0)) {
|
||||
console.log('loadOrderDetail: order not found directly, checking ml_delivery_tasks')
|
||||
const taskRes: any = await supa.from('ml_delivery_tasks').select('*').eq('id', orderId).limit(1).execute()
|
||||
if (taskRes && Array.isArray(taskRes.data) && taskRes.data.length > 0) {
|
||||
taskData = taskRes.data[0]
|
||||
console.log('loadOrderDetail: found task record', taskData)
|
||||
if (taskData.order_id) {
|
||||
targetOrderId = taskData.order_id
|
||||
console.log('loadOrderDetail: found linked order_id in task', targetOrderId)
|
||||
orderRes = await supa.from('ml_orders').select('*').eq('id', targetOrderId).limit(1).execute()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('loadOrderDetail: final orderRes data length=', orderRes?.data?.length)
|
||||
|
||||
if (orderRes && Array.isArray(orderRes.data) && orderRes.data.length > 0) {
|
||||
const row = orderRes.data[0]
|
||||
|
||||
const shipping = row.shipping_address || {}
|
||||
console.log('loadOrderDetail: discovered order details', row)
|
||||
|
||||
// 如果没有预先获取 taskData,在这里查一次
|
||||
if (!taskData) {
|
||||
const dtQuery: any = await supa.from('ml_delivery_tasks').select('*').eq('order_id', row.id).limit(1).execute()
|
||||
if (dtQuery && Array.isArray(dtQuery.data) && dtQuery.data.length > 0) taskData = dtQuery.data[0]
|
||||
}
|
||||
let shipping: UTSJSONObject = {} as UTSJSONObject
|
||||
try {
|
||||
const rawShipping = row.shipping_address
|
||||
if (typeof rawShipping == 'string' && (rawShipping as string).startsWith('{')) {
|
||||
shipping = JSON.parse(rawShipping as string) as UTSJSONObject
|
||||
} else if (rawShipping != null && typeof rawShipping == 'object') {
|
||||
shipping = rawShipping as UTSJSONObject
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('loadOrderDetail: parse shipping_address failed', e)
|
||||
}
|
||||
|
||||
this.order = Object.assign(this.order, {
|
||||
id: row.id,
|
||||
@@ -287,9 +338,9 @@ export default {
|
||||
payment_method: row.payment_method || 0,
|
||||
payment_status: row.payment_status || 0,
|
||||
delivery_address: {
|
||||
name: shipping.name || shipping.recipient || '',
|
||||
phone: shipping.phone || shipping.mobile || '',
|
||||
detail: shipping.detail || shipping.address || JSON.stringify(shipping)
|
||||
name: shipping['name'] || shipping['recipient'] || '',
|
||||
phone: shipping['phone'] || shipping['mobile'] || '',
|
||||
detail: shipping['detail'] || shipping['address'] || JSON.stringify(shipping)
|
||||
},
|
||||
created_at: row.created_at || ''
|
||||
})
|
||||
@@ -341,19 +392,63 @@ export default {
|
||||
}
|
||||
|
||||
// deliveryInfo 从 ml_delivery_tasks 中读取(如果存在)
|
||||
const dtRes: any = await supa.from('ml_delivery_tasks').select('*').eq('order_id', realOrderId).limit(1).execute()
|
||||
console.log('loadOrderDetail: dtRes=', dtRes)
|
||||
if (dtRes && Array.isArray(dtRes.data) && dtRes.data.length > 0) {
|
||||
const dt = dtRes.data[0]
|
||||
this.deliveryInfo.distance = Number(dt.distance) || this.deliveryInfo.distance
|
||||
this.deliveryInfo.estimated_time = Number(dt.estimated_time) || this.deliveryInfo.estimated_time
|
||||
this.deliveryInfo.courier_id = dt.driver_id || ''
|
||||
this.deliveryInfo.pickup_time = dt.pickup_time || ''
|
||||
this.deliveryInfo.delivery_time = dt.delivered_time || ''
|
||||
if (taskData) {
|
||||
this.deliveryInfo.distance = Number(taskData.distance) || this.deliveryInfo.distance
|
||||
this.deliveryInfo.estimated_time = Number(taskData.estimated_time) || this.deliveryInfo.estimated_time
|
||||
this.deliveryInfo.courier_id = taskData.driver_id || ''
|
||||
this.deliveryInfo.pickup_time = taskData.pickup_time || ''
|
||||
this.deliveryInfo.delivery_time = taskData.delivered_time || taskData.delivered_at || ''
|
||||
}
|
||||
} else if (taskData) {
|
||||
// ⚠️ 数据不一致兜底:订单主表查不到,但任务表查到了
|
||||
console.warn('loadOrderDetail: order missing but task found. Using fallback.')
|
||||
|
||||
const parseF = (v: any) => {
|
||||
if (!v) return { detail: '', name: '', phone: '' }
|
||||
let o: any = v
|
||||
if (typeof v === 'string') {
|
||||
try { o = JSON.parse(v) } catch (e) { o = { detail: v } }
|
||||
}
|
||||
return {
|
||||
detail: o.detail || o.address || o.full_address || '',
|
||||
name: o.name || o.contact_name || o.recipient_name || '',
|
||||
phone: o.phone || o.mobile || o.contact_phone || ''
|
||||
}
|
||||
}
|
||||
|
||||
const pickup = parseF(taskData.pickup_address)
|
||||
const delivery = parseF(taskData.delivery_address)
|
||||
const pContact = parseF(taskData.pickup_contact)
|
||||
const dContact = parseF(taskData.delivery_contact)
|
||||
|
||||
this.order = Object.assign(this.order, {
|
||||
id: taskData.order_id || taskData.id,
|
||||
order_no: taskData.order_no || taskData.id.substring(0, 8),
|
||||
status: Number(taskData.status) || originalStatus,
|
||||
delivery_address: {
|
||||
name: dContact.name || delivery.name,
|
||||
phone: dContact.phone || delivery.phone,
|
||||
detail: delivery.detail
|
||||
}
|
||||
})
|
||||
|
||||
this.merchant.contact_name = pContact.name || pickup.name
|
||||
this.merchant.contact_phone = pContact.phone || pickup.phone
|
||||
this.pickupAddress = pickup.detail
|
||||
|
||||
this.deliveryInfo.distance = Number(taskData.distance) || 0
|
||||
this.deliveryInfo.estimated_time = Number(taskData.estimated_time) || 0
|
||||
|
||||
uni.showToast({ title: '已回退从任务记录显示', icon: 'none' })
|
||||
} else {
|
||||
console.warn('loadOrderDetail: no order found for id', orderId)
|
||||
uni.showToast({ title: '未找到订单或任务信息', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('loadOrderDetail db error', e)
|
||||
uni.showToast({ title: '加载订单失败', icon: 'none' })
|
||||
} finally {
|
||||
uni.hideLoading()
|
||||
}
|
||||
},
|
||||
|
||||
@@ -530,7 +625,15 @@ export default {
|
||||
.delivery-order-detail {
|
||||
background-color: #f5f5f5;
|
||||
min-height: 100vh;
|
||||
padding-bottom: 160rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-bottom: 0; /* padding moved to .page-content to avoid double spacing */
|
||||
}
|
||||
|
||||
.page-content {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
padding-bottom: 300rpx; /* 留出底部操作区域高度,确保联系商家等内容可滚动到最下 */
|
||||
}
|
||||
|
||||
/* ... 其余样式保持原样 ... */
|
||||
@@ -738,7 +841,8 @@ export default {
|
||||
|
||||
.order-no {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.product-item {
|
||||
@@ -865,30 +969,38 @@ export default {
|
||||
.contact-item {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column; /* 改为垂直排列避免空间不足 */
|
||||
align-items: center;
|
||||
padding: 25rpx;
|
||||
justify-content: center;
|
||||
padding: 20rpx;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 10rpx;
|
||||
min-height: 120rpx;
|
||||
}
|
||||
|
||||
.contact-icon {
|
||||
font-size: 32rpx;
|
||||
margin-right: 15rpx;
|
||||
font-size: 36rpx;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.contact-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.contact-name {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
margin-bottom: 5rpx;
|
||||
}
|
||||
|
||||
.contact-phone {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #007aff;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.bottom-actions {
|
||||
|
||||
Reference in New Issue
Block a user