| 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', | 
|     }); | 
|      | 
|    | 
|   }, | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
| }) |