|
@@ -8,7 +8,8 @@ Page({
|
|
status: 0,
|
|
status: 0,
|
|
id: '',
|
|
id: '',
|
|
couponInfo: {},
|
|
couponInfo: {},
|
|
- timer: null
|
|
|
|
|
|
+ timer: null,
|
|
|
|
+ loading: true // 增加 loading 状态
|
|
},
|
|
},
|
|
|
|
|
|
onLoad(options) {
|
|
onLoad(options) {
|
|
@@ -19,7 +20,6 @@ Page({
|
|
|
|
|
|
onReady() {
|
|
onReady() {
|
|
this.getCouponDetail();
|
|
this.getCouponDetail();
|
|
- this.startPolling();
|
|
|
|
},
|
|
},
|
|
|
|
|
|
onUnload() {
|
|
onUnload() {
|
|
@@ -27,15 +27,23 @@ Page({
|
|
},
|
|
},
|
|
|
|
|
|
async getCouponDetail() {
|
|
async getCouponDetail() {
|
|
- const res = await couponDetail(this.data.id);
|
|
|
|
- if (res.code === 200) {
|
|
|
|
- this.updateCouponInfo(res.data);
|
|
|
|
- } else {
|
|
|
|
- wx.showToast({
|
|
|
|
- title: res.message || '请求失败',
|
|
|
|
- icon: 'none',
|
|
|
|
- duration: 2000
|
|
|
|
- });
|
|
|
|
|
|
+ this.setData({ loading: true }); // 请求前显示加载
|
|
|
|
+ try {
|
|
|
|
+ const res = await couponDetail(this.data.id);
|
|
|
|
+ if (res.code === 200) {
|
|
|
|
+ this.updateCouponInfo(res.data);
|
|
|
|
+ this.startPolling();
|
|
|
|
+ } else {
|
|
|
|
+ wx.showToast({
|
|
|
|
+ title: res.message || '请求失败',
|
|
|
|
+ icon: 'none',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ } finally{
|
|
|
|
+ this.setData({ loading: false });
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
@@ -72,7 +80,7 @@ Page({
|
|
? '已核销'
|
|
? '已核销'
|
|
: '已过期'
|
|
: '已过期'
|
|
};
|
|
};
|
|
- this.setData({ couponInfo: item,status:data.verify_status});
|
|
|
|
|
|
+ this.setData({ couponInfo: item, status: data.verify_status });
|
|
},
|
|
},
|
|
handleBack() {
|
|
handleBack() {
|
|
this.checkCouponStatus();
|
|
this.checkCouponStatus();
|
|
@@ -86,4 +94,4 @@ Page({
|
|
onChange() {
|
|
onChange() {
|
|
this.getCouponDetail();
|
|
this.getCouponDetail();
|
|
}
|
|
}
|
|
-});
|
|
|
|
|
|
+});
|