添加对应逻辑并修改样式
This commit is contained in:
@@ -81,10 +81,17 @@ import { ref, onMounted } from 'vue'
|
||||
// 响应式数据
|
||||
const task = ref(null)
|
||||
|
||||
// 生命周期
|
||||
// ✅ 关键:在 setup 中无法直接访问 onLoad,所以改用以下方式
|
||||
// 方案:通过 getCurrentPages() 获取当前页面参数
|
||||
function getQueryParams() {
|
||||
const pages = getCurrentPages()
|
||||
const currentPage = pages[pages.length - 1]
|
||||
return currentPage.options || {}
|
||||
}
|
||||
|
||||
// 在 onMounted 中获取参数
|
||||
onMounted(() => {
|
||||
// 获取 URL 参数
|
||||
const query = uni.getLaunchOptionsSync().query
|
||||
const query = getQueryParams()
|
||||
const taskId = query.id
|
||||
|
||||
if (!taskId) {
|
||||
@@ -92,80 +99,42 @@ onMounted(() => {
|
||||
title: '任务ID不能为空',
|
||||
icon: 'none'
|
||||
})
|
||||
console.error('❌ 未获取到 taskId,query:', query)
|
||||
return
|
||||
}
|
||||
|
||||
loadTaskDetail(taskId)
|
||||
})
|
||||
|
||||
// 方法
|
||||
// 其他方法保持不变...
|
||||
function loadTaskDetail(taskId: string) {
|
||||
// 模拟加载任务详情
|
||||
const mockTasks = [
|
||||
{
|
||||
id: 'task001',
|
||||
order_id: 'ORD20250122001',
|
||||
driver_id: 'driver001',
|
||||
pickup_address: { address: '深圳市南山区科技园南区深圳湾科技生态园' },
|
||||
delivery_address: { address: '深圳市南山区蛇口海上世界广场' },
|
||||
distance: 8.2,
|
||||
estimated_time: 25,
|
||||
delivery_fee: 12.0,
|
||||
status: 3, // 配送中
|
||||
pickup_time: '2025-01-22 14:30:00',
|
||||
delivered_time: null,
|
||||
delivery_code: 'DEL001',
|
||||
status: 3,
|
||||
remark: '联系电话: 13800138000',
|
||||
created_at: '2025-01-22 14:00:00',
|
||||
updated_at: '2025-01-22 14:35:00'
|
||||
created_at: '2025-01-22 14:00:00'
|
||||
},
|
||||
{
|
||||
id: 'task002',
|
||||
order_id: 'ORD20250122002',
|
||||
driver_id: 'driver001',
|
||||
pickup_address: { address: '深圳市南山区海岸城' },
|
||||
delivery_address: { address: '深圳市南山区欢乐颂广场' },
|
||||
distance: 3.5,
|
||||
estimated_time: 12,
|
||||
delivery_fee: 8.0,
|
||||
status: 4, // 已完成
|
||||
pickup_time: '2025-01-22 13:00:00',
|
||||
delivered_time: '2025-01-22 13:15:00',
|
||||
delivery_code: 'DEL002',
|
||||
remark: '',
|
||||
created_at: '2025-01-22 12:45:00',
|
||||
updated_at: '2025-01-22 13:15:00'
|
||||
},
|
||||
{
|
||||
id: 'task003',
|
||||
order_id: 'ORD20250122003',
|
||||
driver_id: 'driver001',
|
||||
pickup_address: { address: '深圳市南山区世界之窗' },
|
||||
delivery_address: { address: '深圳市南山区欢乐谷' },
|
||||
distance: 2.1,
|
||||
estimated_time: 8,
|
||||
delivery_fee: 6.5,
|
||||
status: 1, // 待接单
|
||||
pickup_time: null,
|
||||
delivered_time: null,
|
||||
delivery_code: 'DEL003',
|
||||
remark: '',
|
||||
created_at: '2025-01-22 11:15:00',
|
||||
updated_at: '2025-01-22 11:15:00'
|
||||
}
|
||||
// 更多模拟数据...
|
||||
]
|
||||
|
||||
const foundTask = mockTasks.find(t => t.id === taskId)
|
||||
if (foundTask) {
|
||||
task.value = foundTask
|
||||
console.log('✅ 加载任务成功:', task.value)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '未找到该任务',
|
||||
icon: 'none'
|
||||
})
|
||||
uni.showToast({ title: '未找到该任务', icon: 'none' })
|
||||
console.warn('⚠️ 任务ID不存在:', taskId)
|
||||
}
|
||||
}
|
||||
|
||||
// 其他方法...
|
||||
function getTaskStatusText(status: number): string {
|
||||
const statusMap = {
|
||||
1: '待接单',
|
||||
@@ -178,22 +147,19 @@ function getTaskStatusText(status: number): string {
|
||||
}
|
||||
|
||||
function getAddressText(address: UTSJSONObject): string {
|
||||
return address['address'] as string || '地址信息'
|
||||
return address?.['address'] as string || '地址信息'
|
||||
}
|
||||
|
||||
function formatTime(dateStr: string): string {
|
||||
if (!dateStr) return '未知时间'
|
||||
const date = new Date(dateStr)
|
||||
const now = new Date()
|
||||
const diff = now.getTime() - date.getTime()
|
||||
const hours = Math.floor(diff / (1000 * 60 * 60))
|
||||
|
||||
if (hours < 1) {
|
||||
return '刚刚'
|
||||
} else if (hours < 24) {
|
||||
return `${hours}小时前`
|
||||
} else {
|
||||
return `${Math.floor(hours / 24)}天前`
|
||||
}
|
||||
if (hours < 1) return '刚刚'
|
||||
if (hours < 24) return `${hours}小时前`
|
||||
return `${Math.floor(hours / 24)}天前`
|
||||
}
|
||||
|
||||
function contactCustomer() {
|
||||
@@ -201,9 +167,7 @@ function contactCustomer() {
|
||||
itemList: ['拨打电话', '发送短信'],
|
||||
success: (res) => {
|
||||
if (res.tapIndex === 0) {
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: '13800138000'
|
||||
})
|
||||
uni.makePhoneCall({ phoneNumber: '13800138000' })
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -211,32 +175,16 @@ function contactCustomer() {
|
||||
|
||||
function completeTask() {
|
||||
if (task.value?.status !== 3) {
|
||||
uni.showToast({
|
||||
title: '当前任务不是“配送中”状态',
|
||||
icon: 'none'
|
||||
})
|
||||
uni.showToast({ title: '当前任务不是“配送中”状态', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 模拟完成配送
|
||||
task.value.status = 4
|
||||
uni.showToast({
|
||||
title: '任务已完成',
|
||||
icon: 'success'
|
||||
})
|
||||
uni.showToast({ title: '任务已完成', icon: 'success' })
|
||||
}
|
||||
|
||||
// 返回上一页
|
||||
function goBack() {
|
||||
uni.navigateBack()
|
||||
}
|
||||
|
||||
// 如果你希望在左上角也返回主页(可选)
|
||||
function goBackToHome() {
|
||||
uni.reLaunch({
|
||||
url: '/pages/mall/delivery/index'
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user