fix:修复bug;新增订单列表页面订单监控
This commit is contained in:
+150
-15
@@ -80,8 +80,25 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 转为自用提示 - 在使用中状态时显示 -->
|
||||
<view v-if="orderInfo.orderStatus === 'in_used'" class="convert-tip" @click="handleConvertToOwned">
|
||||
{{ $t('order.convertToOwn') }}
|
||||
</view>
|
||||
|
||||
<!-- 底部操作栏 -->
|
||||
<view class="bottom-bar">
|
||||
<!-- 支付成功状态 -->
|
||||
<template v-if="orderInfo.orderStatus === 'payment_successful'">
|
||||
<view class="bottom-icon-btn" @click="contactService">
|
||||
<image src="/static/customer-service.png" class="icon" mode="aspectFit"></image>
|
||||
<text>{{ $t('user.customerService') }}</text>
|
||||
</view>
|
||||
<view class="bottom-icon-btn" @click="handleDeviceNoEject">
|
||||
<image src="/static/complaint.png" class="icon" mode="aspectFit"></image>
|
||||
<text>{{ $t('order.deviceNoEject') }}</text>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<!-- 使用中状态 -->
|
||||
<template v-if="orderInfo.orderStatus === 'in_used'">
|
||||
<view class="bottom-icon-btn" @click="contactService">
|
||||
@@ -104,6 +121,11 @@
|
||||
<view v-else class="action-btn primary" @click="quickReturn">
|
||||
{{ $t('order.quickReturn') }}
|
||||
</view>
|
||||
<!-- 宝未弹出按钮 - 放在最后 -->
|
||||
<view class="bottom-icon-btn" @click="handleDeviceNoEject">
|
||||
<image src="/static/complaint.png" class="icon" mode="aspectFit"></image>
|
||||
<text>{{ $t('order.deviceNoEject') }}</text>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<!-- 已完成状态 -->
|
||||
@@ -140,8 +162,13 @@
|
||||
import { onLoad, onShow, onHide, onUnload } from '@dcloudio/uni-app'
|
||||
import {
|
||||
queryById,
|
||||
cancelOrder
|
||||
cancelOrder,
|
||||
reportDeviceNoEject,
|
||||
convertToOwned
|
||||
} from '@/config/api/order.js'
|
||||
import {
|
||||
addUserFeedback
|
||||
} from '@/config/api/feedback.js'
|
||||
import {
|
||||
getSystemConfig
|
||||
} from '@/config/api/system.js'
|
||||
@@ -497,18 +524,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 从订单监控服务中移除当前订单
|
||||
// 从订单详情页角度不再主动移除订单监控
|
||||
// 订单监控的生命周期完全交给全局 orderMonitor,在订单真正完成时自动移除
|
||||
const removeFromOrderMonitor = () => {
|
||||
if (orderInfo.value.orderId && $orderMonitor) {
|
||||
try {
|
||||
$orderMonitor.removeOrder({
|
||||
orderId: orderInfo.value.orderId
|
||||
})
|
||||
console.log('订单已从监控队列移除:', orderInfo.value.orderId)
|
||||
} catch (error) {
|
||||
console.error('从监控队列移除订单失败:', error)
|
||||
}
|
||||
}
|
||||
// 保留函数以兼容已有调用,但不再从全局监控中删除订单
|
||||
console.log('removeFromOrderMonitor 调用:已不再从全局监控中移除订单,交由 orderMonitor 在订单完成时处理')
|
||||
}
|
||||
|
||||
// 处理订单完成事件
|
||||
@@ -691,7 +711,7 @@
|
||||
// 更新订单信息
|
||||
updateOrderInfo(orderData)
|
||||
|
||||
// 只有使用中的订单才启动定时器和监控
|
||||
// 只有使用中的订单才启动本页的计时器逻辑
|
||||
if (orderInfo.value.orderStatus === 'in_used') {
|
||||
startTimer()
|
||||
startStatusCheckTimer()
|
||||
@@ -699,10 +719,13 @@
|
||||
if (orderInfo.value.isSupportExpressReturn !== 'no') {
|
||||
startExpressCountdown()
|
||||
}
|
||||
}
|
||||
|
||||
// 无论当前订单状态如何,只要进入订单详情页,就把当前订单交给全局订单监控
|
||||
if (orderInfo.value.orderId) {
|
||||
uni.setStorageSync('activeOrderId', orderInfo.value.orderId)
|
||||
|
||||
// 添加到监控队列
|
||||
// 添加/更新到监控队列
|
||||
try {
|
||||
if ($orderMonitor) {
|
||||
$orderMonitor.removeOrder({
|
||||
@@ -711,7 +734,9 @@
|
||||
$orderMonitor.addOrder({
|
||||
orderId: orderInfo.value.orderId
|
||||
}, 'detail')
|
||||
console.log('订单已添加到监控队列:', orderInfo.value.orderId)
|
||||
console.log('订单已添加到监控队列(无论当前状态):', orderInfo.value.orderId, '当前状态:', orderInfo.value.orderStatus)
|
||||
} else {
|
||||
console.warn('$orderMonitor 未定义,无法添加订单到监控队列')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('添加订单到监控队列失败:', error)
|
||||
@@ -880,6 +905,98 @@
|
||||
})
|
||||
}
|
||||
|
||||
// 处理"宝未弹出"反馈
|
||||
const handleDeviceNoEject = () => {
|
||||
uni.showModal({
|
||||
title: $t('order.deviceNoEjectTitle'),
|
||||
content: $t('order.deviceNoEjectConfirm'),
|
||||
confirmText: $t('common.confirm'),
|
||||
cancelText: $t('common.cancel'),
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: $t('common.submitting')
|
||||
})
|
||||
|
||||
// 调用反馈API提交工单
|
||||
const feedbackData = {
|
||||
type: 'device_issue',
|
||||
content: `订单号:${orderInfo.value.orderNo}\n设备号:${deviceId.value}\n问题:充电宝未弹出`,
|
||||
phone: orderInfo.value.phone || '',
|
||||
orderId: orderInfo.value.orderId,
|
||||
orderNo: orderInfo.value.orderNo
|
||||
}
|
||||
|
||||
const result = await addUserFeedback(feedbackData)
|
||||
|
||||
if (result.code === 200) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: $t('order.deviceNoEjectSuccess'),
|
||||
icon: 'success',
|
||||
duration: 3000
|
||||
})
|
||||
} else {
|
||||
throw new Error(result.msg || $t('order.deviceNoEjectFailed'))
|
||||
}
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: error.message || $t('order.deviceNoEjectFailed'),
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 处理"转为自用"
|
||||
const handleConvertToOwned = () => {
|
||||
uni.showModal({
|
||||
title: $t('order.convertToOwnTitle'),
|
||||
content: $t('order.convertToOwnConfirm'),
|
||||
confirmText: $t('common.confirm'),
|
||||
cancelText: $t('common.cancel'),
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: $t('common.processing')
|
||||
})
|
||||
|
||||
const result = await convertToOwned(orderInfo.value.orderId)
|
||||
|
||||
if (result.code === 200) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: $t('order.convertToOwnSuccess'),
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
|
||||
// 刷新订单详情
|
||||
setTimeout(() => {
|
||||
getOrderDetails()
|
||||
}, 2000)
|
||||
} else {
|
||||
throw new Error(result.msg || $t('order.convertToOwnFailed'))
|
||||
}
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: error.message || $t('order.convertToOwnFailed'),
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 生命周期钩子
|
||||
onLoad((options) => {
|
||||
console.log('订单详情页加载,参数:', JSON.stringify(options))
|
||||
@@ -1029,6 +1146,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 转为自用提示
|
||||
.convert-tip {
|
||||
position: fixed;
|
||||
left: 30rpx;
|
||||
right: 30rpx;
|
||||
bottom: calc(120rpx + env(safe-area-inset-bottom));
|
||||
color: #000;
|
||||
text-align: center;
|
||||
padding: 20rpx 30rpx;
|
||||
border-radius: 12rpx;
|
||||
font-size: 26rpx;
|
||||
z-index: 9;
|
||||
|
||||
&:active {
|
||||
opacity: 0.85;
|
||||
}
|
||||
}
|
||||
|
||||
// 租借信息卡片
|
||||
.rent-card {
|
||||
background: #fff;
|
||||
|
||||
+25
-8
@@ -35,7 +35,8 @@
|
||||
import {
|
||||
ref,
|
||||
reactive,
|
||||
onMounted
|
||||
onMounted,
|
||||
onUnmounted
|
||||
} from 'vue';
|
||||
import OrderItemCard from '../../components/OrderItemCard.vue';
|
||||
import {
|
||||
@@ -60,13 +61,6 @@
|
||||
|
||||
const { t: $t } = useI18n()
|
||||
|
||||
// 设置页面标题
|
||||
onMounted(() => {
|
||||
uni.setNavigationBarTitle({
|
||||
title: $t('order.myOrders')
|
||||
})
|
||||
})
|
||||
|
||||
// 初始化状态
|
||||
const currentTab = ref(0);
|
||||
const orderList = ref([]);
|
||||
@@ -228,6 +222,29 @@
|
||||
}
|
||||
};
|
||||
|
||||
// 处理订单完成事件
|
||||
const handleOrderCompleted = (orderData) => {
|
||||
console.log('订单列表页收到订单完成事件:', orderData)
|
||||
// 刷新订单列表,根据当前选中的标签刷新对应状态的订单
|
||||
const statusList = orderStatusTabs[currentTab.value].status[0]
|
||||
loadOrderList(statusList)
|
||||
}
|
||||
|
||||
// 设置页面标题并监听订单完成事件
|
||||
onMounted(() => {
|
||||
uni.setNavigationBarTitle({
|
||||
title: $t('order.myOrders')
|
||||
})
|
||||
|
||||
// 监听订单完成事件
|
||||
uni.$on('orderCompleted', handleOrderCompleted)
|
||||
})
|
||||
|
||||
// 页面卸载时移除事件监听
|
||||
onUnmounted(() => {
|
||||
uni.$off('orderCompleted', handleOrderCompleted)
|
||||
})
|
||||
|
||||
// 同步订单状态
|
||||
const getOrderStatus = async (order) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user