coupons.js 3.5 KB
// pages/my/coupons/coupons.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winHeight: "", //窗口高度
    currentTab: 0, //预设当前项的值
    scrollLeft: 0, //tab标题的滚动条位置
    expertList: [{ //假数据
      img: "avatar.png",
      name: "欢顔",
      tag: "知名情感博主",
      answer: 134,
      listen: 2234,
      over:[],
      unuse:[],
      uses:[]
    }],
    use:1
  },
//返回
        get_back(){
                wx.navigateBack({})
        },
//获取数据
fetchCoupons(){
        let url = '/wxapp/user/coupon';
        app.post(url).then(r => {
                this.setData({
                        over: r.over,
                        unuse: r.unuse,
                        used: r.used
                });
               
                let unuse = r.unuse;
                let over=r.over;
                let used=r.used;
                console.log(over);
                unuse.forEach(function (ele,index) {
                        ele.end_time=app.timeFormate(ele.end_time,'YYMMDDHHMM');
                });
                over.forEach(function (ele, index) {
                        ele.end_time = app.timeFormate(ele.end_time, 'YYMMDDHHMM');
                });
                used.forEach(function (ele, index) {
                        ele.end_time = app.timeFormate(ele.end_time, 'YYMMDDHHMM');
                });
        })
},      
  // 滚动切换标签样式
  switchTab: function(e) {
    this.setData({
      currentTab: e.detail.current
    });
    this.checkCor();
  },
  // 点击标题切换当前页时改变样式
  swichNav: function(e) {
    var cur = e.target.dataset.current;
    if (this.data.currentTaB == cur) {
      return false;
    } else {
      this.setData({
        currentTab: cur
      })
    }
  },
  //判断当前滚动超过一屏时,设置tab标题滚动条。
  checkCor: function() {
    if (this.data.currentTab > 4) {
      this.setData({
        scrollLeft: 300
      })
    } else {
      this.setData({
        scrollLeft: 0
      })
    }
  },
//修改use的值
changeUse1(){
        this.setData({
                use:1
        });
},
changeUse2(){ 
        this.setData({
                use: 2
        });
},
changeUse3(){ 
        this.setData({
                use: 3
        });
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    //  高度自适应
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 180;
        console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });
    this.fetchCoupons();               
  },

  footerTap: app.footerTap,

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    
  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }

})