fix
wzy
2021-11-11 23c3bc31f574ee9573c8045edad0233b55a0ffa6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
var util = require('../../utils/util.js');
const app=getApp();
Page({
  data: {
    couponsList:['待使用','已使用','已失效'],
    key:0,
    status: 2,  //1=已使用 2=未使用 3=过期
    text: [   ], 
    isUsedCoupon:[],  // 已使用
    unUsedCoupon: [], // 待使用
    loseCoupon: [],  // 已失效
 
    couponShow:false,
    limit : 6,
    offset: 0,
    check:0 // 用来判断选择的下标
    
  },
  onLoad: function (options) {
    this.getCouponsList(1)
    this.getCouponsList(2)
    this.getCouponsList(3)
    this.goTap();
  },
  //一键回到顶部
  goTap() {
    util.goTap();
  },
  //获取滚动条当前位置
  onPageScroll: function (e) {
    // console.log(e)
    if (e.scrollTop > 400) {
      this.setData({
        floorstatus: true
      });
    } else {
      this.setData({
        floorstatus: false
      });
    }
  },
  // 选择优惠券类型
  coupons(e){
    var index = e.currentTarget.dataset.index;
 
    var status = 0;
    console.log(index);
    if (index == 0){
      status = 2
    } else if(index == 1){
      status = 1
    }else if (index == 2) {
      status = 3
    }
    this.setData({
      offset:0,
      key:index,
      status: status
    })
  },
 
  // 获取优惠券列表
  getCouponsList:function(status){
    var _this = this;
    var limit = _this.data.limit
    var offset = _this.data.offset
    util.request({
      method:"POST", 
      api:"/wxapi/shopCoupon/getMyCouponInfoByStatus/"+app.shopInfo.id+"/"+status,
      data: {"limit":limit, "offset":offset},
      callback: function (data) {
      if (data.status == '200') {
        for (var i = 0; i < data.rows.length; i++){
          data.rows[i].endTimeWx = data.rows[i].endTimeWx.substring(0, 10);
        }
        if (status == 2){
          _this.setData({
            unUsedCoupon: data.rows
          })
        } else if (status == 1) {
          _this.setData({
            isUsedCoupon: data.rows
          })
        } else {
          _this.setData({
            loseCoupon: data.rows
          })
        }
      }
    }});
  },
 
  // 上拉加载
  onReachBottom: function () {
    var _this = this;
    var offset = _this.data.offset;
    var limit = _this.data.limit;
    var couponList = _this.data.unUsedCoupon;
    var status = _this.data.status
    if (status == 2) {
      couponList = _this.data.unUsedCoupon;
    } else if (status == 1) {
      couponList = _this.data.isUsedCoupon;
    } else {
      couponList = _this.data.loseCoupon;
    }
    _this.setData({
      offset: offset + limit
    });
    offset = _this.data.offset;
 
    util.request({
      method:"POST",
      api: "/wxapi/shopCoupon/getMyCouponInfoByStatus/" + status, 
      data:{ "limit": limit, "offset": offset }, 
      callback:function (data) {
      for (var i = 0; i < data.rows.length; i++) {
        data.rows[i].endTimeWx = data.rows[i].endTimeWx.substring(0, 10);
        
        couponList.push(data.rows[i])
      }
 
 
      if (status == 2) {
        _this.setData({
          unUsedCoupon: couponList
        })
      } else if (status == 1) {
        _this.setData({
          isUsedCoupon: couponList
        })
      } else {
        _this.setData({
          loseCoupon: couponList
        })
      }
   
 
    }});
  },
 
 
 
 
//使用优惠券
  useCoupon(e){
    var coupon = e.currentTarget.dataset.coupon;
    wx.setStorageSync("queryKey", coupon);
    wx.switchTab({
      url: '/pages/service/service2',
    });
    
  
  },
 
 
 
 
 
 
 
 
 
 
})