| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 | 
							- // pages/couponCenter/couponCenter.js
 
- var http = require("../../utils/http.js");
 
- var config = require("../../utils/config.js");
 
- var util = require('../../utils/util.js');
 
- Page({
 
-   /**
 
-    * 页面的初始数据
 
-    */
 
-   data: {
 
-     couponList: [], // 通用券列表
 
-     prodCouponList: [], // 商品券列表
 
-     selectedCouponId:0, // 要领取的优惠券id
 
-     current: 1, // 当前页数
 
-     pages: 1, // 总页数
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面加载
 
-    */
 
-   onLoad: function(options) {
 
-     //获取通用列表
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面初次渲染完成
 
-    */
 
-   onReady: function() {
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面显示
 
-    */
 
-   onShow: function() {
 
-     this.getCouponList();
 
-     this.getProdCouponList(1);
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面隐藏
 
-    */
 
-   onHide: function() {
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面卸载
 
-    */
 
-   onUnload: function() {
 
-   },
 
-   /**
 
-    * 页面相关事件处理函数--监听用户下拉动作
 
-    */
 
-   onPullDownRefresh: function() {
 
-   },
 
-   /**
 
-    * 页面上拉触底事件的处理函数
 
-    */
 
-   onReachBottom: function() {
 
-   },
 
-   /**
 
-    * 用户点击右上角分享
 
-    */
 
-   onShareAppMessage: function() {
 
-   },
 
-   /**
 
-    * 获取通用列表
 
-    */
 
-   getCouponList() {
 
-     var params = {
 
-       url: "/p/myCoupon/generalCouponList",
 
-       method: "GET",
 
-       callBack: (res) => {
 
-         this.initCouponCanGoUseFlag(res)
 
-         this.setData({
 
-           couponList: res
 
-         });
 
-       }
 
-     };
 
-     http.request(params);
 
-   },
 
-   /**
 
-    * 获取指定商品券
 
-    */
 
-   getProdCouponList(cur) {
 
-     var params = {
 
-       url: "/p/myCoupon/getCouponPage",
 
-       method: "GET",
 
-       data: {
 
-         current: cur,
 
-         size: 20,
 
-       },
 
-       callBack: (res) => {
 
-         this.initCouponCanGoUseFlag(res.records)
 
-         let list = []
 
-         if (res.current == 1) {
 
-           list = res.records
 
-         } else {
 
-           list = this.data.prodCouponList
 
-           list = list.concat(res.records)
 
-         }
 
-         this.setData({
 
-           prodCouponList: list,
 
-           pages: res.pages,
 
-           current: res.current
 
-         });
 
-       }
 
-     };
 
-     http.request(params);
 
-   },
 
-   /**
 
-    * 初始化优惠券去可以使用的标记
 
-    */
 
-   initCouponCanGoUseFlag(couponList){
 
-     couponList.forEach(coupon => {
 
-       coupon.canGoUse = (coupon.curUserReceiveCount >= coupon.limitNum)
 
-     });
 
-   },
 
-   /**
 
-    * 设置优惠券去可以使用的标记
 
-    */
 
-   setCouponCanGoUseFlag(index, couponType) {
 
-     if (couponType == 1) {
 
-       var tempCouponList = this.data.couponList
 
-       tempCouponList[index].canGoUse = true
 
-       tempCouponList[index].stocks -= 1
 
-       this.setData({
 
-         couponList: tempCouponList
 
-       })
 
-     } else if (couponType == 2) {
 
-       var tempCouponList = this.data.prodCouponList
 
-       tempCouponList[index].canGoUse = true
 
-       tempCouponList[index].stocks -= 1
 
-       this.setData({
 
-         prodCouponList: tempCouponList
 
-       })
 
-     }
 
-   },
 
-   /**
 
-    * 立即领取
 
-    */
 
-   receiveCoupon(e) {
 
-     this.setData({
 
-       selectedCouponId: e.currentTarget.dataset.couponid
 
-     })
 
-     util.checkAuthInfo(()=>{
 
-       var ths = this
 
-       if (ths.data.selectedCouponId) {
 
-         wx.showLoading();
 
-         http.request({
 
-           url: "/p/myCoupon/receive",
 
-           method: "POST",
 
-           data: ths.data.selectedCouponId,
 
-           callBack: (data) => {
 
-             wx.hideLoading();
 
-             wx.showToast({
 
-               title: '领券成功',
 
-               icon: 'success',
 
-               duration: 2000
 
-             })
 
-             this.setCouponCanGoUseFlag(e.currentTarget.dataset.couponindex,e.currentTarget.dataset.coupontype)
 
-           }
 
-         })
 
-       }
 
-     })
 
-   },
 
-   /**
 
-    * 立即使用
 
-    */
 
-   useCoupon(e) {
 
-     let url = '/pages/prod-classify/prod-classify?sts=4';
 
-     let couponId = e.currentTarget.dataset.couponid;
 
-     var title = "优惠券活动商品";
 
-     var prodList = e.currentTarget.dataset.prodlist
 
-     if (prodList && prodList.length == 1) {
 
-       wx.navigateTo({
 
-         url: '/pages/prod/prod?prodid=' + prodList[0].prodId
 
-       })
 
-     }else {
 
-       if (couponId) {
 
-         url += "&tagid=" + couponId + "&title=" + title;
 
-       }
 
-       wx.navigateTo({
 
-         url: url
 
-       })
 
-     }
 
-   },
 
-     /**
 
-    * 页面上拉触底事件的处理函数
 
-    */
 
-   onReachBottom: function () {
 
-     if (this.data.current < this.data.pages) {
 
-       this.getProdCouponList(this.data.current + 1);
 
-     }
 
-   },
 
- })
 
 
  |