Fix:旅居订单增加轮询

This commit is contained in:
LinCyJang
2026-04-22 19:56:55 +08:00
parent 9c90600c82
commit ef36b27c54
3 changed files with 50 additions and 28 deletions
+48 -26
View File
@@ -241,19 +241,24 @@ export default {
isView: 0,
showExperienceCouponPopup: false,
experienceCouponId: null,
experienceCouponTimer: null
hasCheckedExperienceCoupon: false,
orderStatusTimer: null
}
},
onLoad(otps) {
this.key = otps.id;
this.isView = otps.isView || 0;
this.hasCheckedExperienceCoupon = false;
},
onShow() {
this.getSojoumOrderDetail();
},
onHide() {
this.stopOrderStatusPolling();
},
onUnload() {
uni.setStorageSync('needRefreshMyOrderList', 1)
this.stopExperienceCouponPolling();
this.stopOrderStatusPolling();
},
methods: {
handleDateRangeChange(dates) {
@@ -325,37 +330,55 @@ export default {
/**
* 获取旅居团购订单详情
*/
async getSojoumOrderDetail() {
async getSojoumOrderDetail(options = {}) {
const { showLoading = true } = options;
const params = {
key: this.key
}
uni.showLoading({
title: '加载中...',
mask: true,
})
const res = await fetchSojoumOrderDetail(params);
if (res.status === 200) {
this.orderInfo = res.data;
this.orderInfo.minBookingDays = this.getDaysCount();
this.startExperienceCouponPolling();
uni.hideLoading();
if (showLoading) {
uni.showLoading({
title: '加载中...',
mask: true,
})
}
try {
const res = await fetchSojoumOrderDetail(params);
if (res.status === 200) {
this.orderInfo = res.data;
this.orderInfo.minBookingDays = this.getDaysCount();
this.startOrderStatusPolling();
if (!this.hasCheckedExperienceCoupon) {
this.hasCheckedExperienceCoupon = true;
this.checkExperienceCouponStatus();
}
}
} finally {
if (showLoading) {
uni.hideLoading();
}
}
},
startExperienceCouponPolling() {
this.stopExperienceCouponPolling();
shouldPollOrderStatus() {
const statusType = this.orderInfo && this.orderInfo._status && this.orderInfo._status._type;
// if (![1, 2].includes(Number(statusType))) {
// return;
// }
this.checkExperienceCouponStatus();
this.experienceCouponTimer = setInterval(() => {
this.checkExperienceCouponStatus();
// 入住/核销成功后不再轮询
return !['3', '4'].includes(String(statusType || ''));
},
startOrderStatusPolling() {
if (!this.shouldPollOrderStatus()) {
this.stopOrderStatusPolling();
return;
}
if (this.orderStatusTimer) {
return;
}
this.orderStatusTimer = setInterval(() => {
this.getSojoumOrderDetail({ showLoading: false });
}, 5000);
},
stopExperienceCouponPolling() {
if (this.experienceCouponTimer) {
clearInterval(this.experienceCouponTimer);
this.experienceCouponTimer = null;
stopOrderStatusPolling() {
if (this.orderStatusTimer) {
clearInterval(this.orderStatusTimer);
this.orderStatusTimer = null;
}
},
async checkExperienceCouponStatus() {
@@ -377,7 +400,6 @@ export default {
if (!showPopup) {
return;
}
this.stopExperienceCouponPolling();
this.experienceCouponId = data.couponId || null;
this.showExperienceCouponPopup = true;
} catch (e) {