|
|
@@ -10,11 +10,13 @@
|
|
|
<view class="problem-link" @click="showProblem">遇到问题?(如门没开)</view>
|
|
|
</view>
|
|
|
|
|
|
- <!-- 阶段二:结算中 (门已关) -->
|
|
|
+ <!-- 阶段二:购物完成 (门已关) -->
|
|
|
<view v-else-if="doorStatus === 'closing'" class="shopping-section">
|
|
|
- <view class="loading-icon">⏳</view>
|
|
|
- <view class="status-title">AI正在识别商品,请稍候...</view>
|
|
|
- <view class="status-tip">预计需要5-15秒</view>
|
|
|
+ <view class="success-icon">✅</view>
|
|
|
+ <view class="status-title">购物已完成</view>
|
|
|
+ <view class="status-tip">订单稍后自动扣款,如有疑问请联系客服</view>
|
|
|
+ <view class="countdown" v-if="returnCountdown > 0">{{ returnCountdown }}秒后返回首页</view>
|
|
|
+ <button class="home-button" @click="goHome">回到首页</button>
|
|
|
</view>
|
|
|
|
|
|
<!-- 阶段三:结算完成 -->
|
|
|
@@ -53,6 +55,7 @@ import type { RecognizeResultResponse } from '../../api/status';
|
|
|
|
|
|
const doorStatus = ref<'opened' | 'closing' | 'closed' | 'error'>('opened');
|
|
|
const countdown = ref(60);
|
|
|
+const returnCountdown = ref(5); // 返回首页倒计时
|
|
|
const purchasedProducts = ref<any[]>([]);
|
|
|
const totalPrice = ref(0);
|
|
|
const errorMessage = ref('');
|
|
|
@@ -61,6 +64,7 @@ const currentActivityId = ref('');
|
|
|
const currentOrderNo = ref('');
|
|
|
|
|
|
let countdownTimer: number | null = null;
|
|
|
+let returnCountdownTimer: number | null = null; // 返回首页倒计时定时器
|
|
|
let statusCheckTimer: number | null = null;
|
|
|
let isComponentActive = true; // 组件活跃状态标志
|
|
|
|
|
|
@@ -70,6 +74,10 @@ const cleanupTimers = () => {
|
|
|
clearInterval(countdownTimer);
|
|
|
countdownTimer = null;
|
|
|
}
|
|
|
+ if (returnCountdownTimer) {
|
|
|
+ clearInterval(returnCountdownTimer);
|
|
|
+ returnCountdownTimer = null;
|
|
|
+ }
|
|
|
if (statusCheckTimer) {
|
|
|
clearTimeout(statusCheckTimer);
|
|
|
statusCheckTimer = null;
|
|
|
@@ -129,6 +137,20 @@ const startCountdown = () => {
|
|
|
}, 1000);
|
|
|
};
|
|
|
|
|
|
+// 开始返回首页倒计时
|
|
|
+const startReturnCountdown = () => {
|
|
|
+ returnCountdown.value = 5; // 重置为5秒
|
|
|
+ returnCountdownTimer = setInterval(() => {
|
|
|
+ if (returnCountdown.value > 0) {
|
|
|
+ returnCountdown.value--;
|
|
|
+ if (returnCountdown.value === 0) {
|
|
|
+ // 倒计时结束,自动返回首页
|
|
|
+ goHome();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 1000);
|
|
|
+};
|
|
|
+
|
|
|
const startStatusPolling = async () => {
|
|
|
// 检查组件是否仍然活跃
|
|
|
if (!isComponentActive) {
|
|
|
@@ -148,55 +170,20 @@ const startStatusPolling = async () => {
|
|
|
|
|
|
// 检查门是否关闭
|
|
|
if (status.doorStatus === 'close') {
|
|
|
- // 门已关,进入识别阶段
|
|
|
+ // 门已关,显示购物完成
|
|
|
doorStatus.value = 'closing';
|
|
|
currentActivityId.value = status.activityId;
|
|
|
|
|
|
- // 开始轮询识别结果
|
|
|
- const recognizeResult = await pollRecognizeResult(status.activityId, 60000, 1000);
|
|
|
+ console.log('门已关,购物完成,活动ID:', status.activityId);
|
|
|
|
|
|
- // 再次检查组件是否仍然活跃
|
|
|
- if (!isComponentActive) {
|
|
|
- return;
|
|
|
+ // 停止选购倒计时
|
|
|
+ if (countdownTimer) {
|
|
|
+ clearInterval(countdownTimer);
|
|
|
+ countdownTimer = null;
|
|
|
}
|
|
|
|
|
|
- if (recognizeResult) {
|
|
|
- console.log('识别结果:', recognizeResult);
|
|
|
-
|
|
|
- // 开始轮询订单信息
|
|
|
- const orderInfo = await pollOrderInfo(currentActivityId.value, 30000, 1000);
|
|
|
-
|
|
|
- // 再次检查组件是否仍然活跃
|
|
|
- if (!isComponentActive) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (orderInfo) {
|
|
|
- console.log('订单信息:', orderInfo);
|
|
|
-
|
|
|
- // 解析商品列表
|
|
|
- if (orderInfo.products) {
|
|
|
- try {
|
|
|
- purchasedProducts.value = JSON.parse(orderInfo.products);
|
|
|
- } catch (e) {
|
|
|
- console.error('解析商品列表失败:', e);
|
|
|
- purchasedProducts.value = [];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 设置总价
|
|
|
- totalPrice.value = parseFloat(orderInfo.totalAmount) || 0;
|
|
|
-
|
|
|
- // 进入结算完成阶段
|
|
|
- doorStatus.value = 'closed';
|
|
|
-
|
|
|
- // 停止倒计时
|
|
|
- if (countdownTimer) {
|
|
|
- clearInterval(countdownTimer);
|
|
|
- countdownTimer = null;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // 开始返回首页倒计时
|
|
|
+ startReturnCountdown();
|
|
|
} else {
|
|
|
// 继续等待关门,设置延迟后重新轮询
|
|
|
if (isComponentActive && doorStatus.value === 'opened') {
|
|
|
@@ -382,7 +369,7 @@ const goHome = () => {
|
|
|
color: #FF6B6B;
|
|
|
}
|
|
|
|
|
|
-.view-order-button, .retry-button {
|
|
|
+.view-order-button, .retry-button, .home-button {
|
|
|
background-color: #FFD700;
|
|
|
color: #333;
|
|
|
border: none;
|