Quellcode durchsuchen

优惠券详情添加轮询

wkw vor 3 Wochen
Ursprung
Commit
a040315f81

+ 8 - 0
api/other.js

@@ -64,6 +64,14 @@ export function couponDetail(coupon_id) {
     method: 'GET'
   });
 }
+//轮询查询券状态
+export function queryCouponDetail(coupon_id,isloop) {
+  return request({
+    loading: false,
+    url: `/api/coupon/${coupon_id}?isloop=${isloop}`,
+    method: 'GET'
+  });
+}
 //生成分享海报
 export function sharePoster() {
   return request({

+ 1 - 0
components/Header/Header.js

@@ -16,6 +16,7 @@ Component({
   methods: {
     goBack(){
       if(!this.data.url){
+        this.triggerEvent('back');
         wx.navigateBack({
           delta: 1
         })

+ 1 - 1
pages/coupon/coupon.js

@@ -9,7 +9,7 @@ Page({
     refreshing: false
   },
 
-  onLoad() {
+  onShow() {
     this.loadData(true);
   },
   async loadData(isRefresh = false) {

+ 68 - 30
pages/couponDetail/couponDetail.js

@@ -1,52 +1,90 @@
-import { couponDetail } from '../../api/other';
-import {BASE_URL} from '../../utils/request';
+import { couponDetail, queryCouponDetail } from '../../api/other';
+import { BASE_URL } from '../../utils/request';
+
 Page({
   data: {
-    baseUrl:BASE_URL,
+    baseUrl: BASE_URL,
     codeType: 'qr',
-    status:0,
-    id:'',
-    couponInfo:{}
-  },
-  goPage(){
-    wx.navigateTo({
-      url: '/pages/storeIcon/storeIcon'
-    })
+    status: 0,
+    id: '',
+    couponInfo: {},
+    timer: null
   },
+
   onLoad(options) {
     this.setData({
-      status:options.status,
-      id:options.id
-    })
+      status: options.status,
+      id: options.id
+    });
+  },
+
+  onReady() {
+    this.getCouponDetail();
+    this.startPolling();
   },
-  onReady(){
-    this.getcouponDetail();
+
+  onUnload() {
+    this.stopPolling();
   },
-  async getcouponDetail(){
+
+  async getCouponDetail() {
     const res = await couponDetail(this.data.id);
-    if(res.code == 200){
-      let item = {
-        ...res.data,
-        verify_status_text:res.data.verify_status == 0?'未核销':res.data.verify_status == 1?'已核销':'已过期'
-      }
-      this.setData({
-        couponInfo:item
-      })
-    }else{
+    if (res.code === 200) {
+      this.updateCouponInfo(res.data);
+    } else {
       wx.showToast({
         title: res.message || '请求失败',
         icon: 'none',
         duration: 2000
       });
     }
-    console.log(res)
+  },
+
+  // 轮询接口
+  startPolling() {
+    this.stopPolling();
+    this.data.timer = setInterval(() => {
+      this.checkCouponStatus('check');
+    }, 10000);
+  },
+  stopPolling() {
+    if (this.data.timer) {
+      clearInterval(this.data.timer);
+      this.data.timer = null;
+    }
+  },
+  async checkCouponStatus(status) {
+    const res = await queryCouponDetail(this.data.id, 1);
+    if (res.code === 200 && status) {
+      const { verify_status } = res.data;
+      if (verify_status !== 0) {
+        this.updateCouponInfo(res.data);
+        this.stopPolling();
+      }
+    }
+  },
+  updateCouponInfo(data) {
+    let item = {
+      ...data,
+      verify_status_text:
+        data.verify_status == 0
+          ? '未核销'
+          : data.verify_status == 1
+          ? '已核销'
+          : '已过期'
+    };
+    this.setData({ couponInfo: item });
+  },
+  handleBack() {
+    this.checkCouponStatus();
   },
   toggleCode() {
     this.setData({
       codeType: this.data.codeType === 'qr' ? 'bar' : 'qr'
     });
   },
-  onChange(){
-    this.getcouponDetail();
+
+  onChange() {
+    this.getCouponDetail();
   }
-})
+});

+ 1 - 1
pages/couponDetail/couponDetail.wxml

@@ -1,5 +1,5 @@
 <view class="container">
-  <header text="我的优惠券"></header>
+  <header text="我的优惠券" bind:back="handleBack"></header>
   <view class="content">
     <view wx:if="{{status == 0}}">
       <view class="title">{{couponInfo.coupon_name}}</view>

+ 2 - 2
pages/index/index.js

@@ -56,11 +56,11 @@ Page({
     const index = e.currentTarget.dataset.index;
     if(index == 0){
       wx.navigateTo({
-        url: `/pages/rules/rules?type=${index}`
+        url: `/pages/rules/rules?type=1`
       })
     }else if(index == 1){
       wx.navigateTo({
-        url: `/pages/rules/rules?type=${index}`
+        url: `/pages/rules/rules?type=2`
       })
     }
   },

+ 2 - 2
pages/index/index.wxml

@@ -26,12 +26,12 @@
           <view class="rules-bg">
             <view class="rules-item" bindtap="goPage" data-index="0">
               <image class="rules-img" src="/static/image/rules.png" mode="aspectFit"></image>
-              <text>活动规则</text>
+              <text>活动须知</text>
             </view>
             <view class="line"></view>
             <view class="rules-item" bindtap="goPage" data-index="1">
               <image class="rules-img" src="/static/image/rules.png" mode="aspectFit"></image>
-              <text>免责申明</text>
+              <text>隐私政策</text>
             </view>
           </view>
           <!-- 日历 -->

+ 2 - 2
pages/rules/rules.js

@@ -7,8 +7,8 @@ Page({
   onLoad(options) {
     const dataInfo = app.globalData.programConfig;
     this.setData({
-      headerText: options.type == 0?'活动规则':'活动须知',
-      rulesText:options.type == 0?dataInfo.rules:dataInfo.disclaimer
+      headerText: options.type == 1?'活动规则':'隐私政策',
+      rulesText:options.type == 1?dataInfo.disclaimer:dataInfo.privacy_policy
     })
   },
 

+ 2 - 0
pages/setting/setting.js

@@ -1,9 +1,11 @@
 import {userModify,logout} from '../../api/user';
 import { uploadImage } from '../../utils/upload.js';
+import {BASE_URL} from '../../utils/request';
 const app = getApp();
 Page({
   data: {
     userInfo:{},
+    baseUrl:BASE_URL,
     pathUrl:'',//保存接口需要传的值
   },
   onReady() {

+ 2 - 2
pages/setting/setting.wxml

@@ -35,10 +35,10 @@
     </view>
     <view class="btn">
       <view bindtap="onExit" hover-class="btn-hover" hover-start-time="10">
-        <image  class="set-btn m20" src="/static/image/exit.png" mode="aspectFit"/>
+        <image  class="set-btn m20" src="{{baseUrl + '/static/image/exit.png'}}" mode="aspectFit"/>
       </view>
       <view bindtap="onSave" hover-class="btn-hover" hover-start-time="10">
-        <image class="set-btn" src="/static/image/save.png" mode="aspectFit"/>
+        <image class="set-btn" src="{{baseUrl + '/static/image/save.png'}}" mode="aspectFit"/>
       </view>
     </view>
   </view>

BIN
static/image/exit.png


BIN
static/image/hdjs.png


BIN
static/image/save.png


BIN
static/image/store.png


BIN
static/image/wdss.png