wkw 3 týždňov pred
rodič
commit
3e1a6131a1

+ 21 - 13
pages/couponDetail/couponDetail.js

@@ -8,7 +8,8 @@ Page({
     status: 0,
     id: '',
     couponInfo: {},
-    timer: null
+    timer: null,
+    loading: true // 增加 loading 状态
   },
 
   onLoad(options) {
@@ -19,7 +20,6 @@ Page({
 
   onReady() {
     this.getCouponDetail();
-    this.startPolling();
   },
 
   onUnload() {
@@ -27,15 +27,23 @@ Page({
   },
 
   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() {
     this.checkCouponStatus();
@@ -86,4 +94,4 @@ Page({
   onChange() {
     this.getCouponDetail();
   }
-});
+});

+ 2 - 1
pages/couponDetail/couponDetail.wxml

@@ -1,10 +1,11 @@
 <view class="container">
   <header text="我的优惠券" bind:back="handleBack"></header>
-  <view class="content">
+  <view class="content" wx:if="{{!loading}}">
     <view wx:if="{{status == 0}}">
       <view class="title">{{couponInfo.coupon_name}}</view>
       <view class="time">{{couponInfo.end_time}}到期</view>
     </view>
+
     <view class="code-box" wx:if="{{status == 0}}">
       <!-- 显示二维码 -->
       <block wx:if="{{codeType === 'qr'}}">