
var app = getApp()
var that=null
var sopenFrame=null
Page( {
  data: {
    bonusImg: '../../images/iconfont-dingdan.png',
    tipWords: '亲，暂时没有数据哦！',
    bonusHidden:false,
    nobonusHidden:true,
    loadingHidden:false,
    title:"",
    mybonus:[],
    Start: 0, 
    nav:0,
    addtime:""
  },

  onLoad: function(options) {
      that = this
      that.setData({
           nav: options.t,
           addtime:options.addtime
      })
      wx.setNavigationBarTitle({
           title: options.addtime + "的奖励详情"
      })
      that.clearCache();//清本页缓存
      that.getlist(0)
    }, // 下拉刷新
    onPullDownRefresh: function () {
         //在当前页面显示导航条加载动画
     wx.showNavigationBarLoading(); 
     //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
     wx.showLoading({
         title: '刷新中...',
     })
        that.clearCache();
        that.getlist(1);//第一次加载数据
    },

     // 页面上拉触底事件（上拉加载更多）
    onReachBottom: function () {
      that.setData({
        loadingHidden:false
        }); 
        that.getlist(2);//后台获取新数据并追加渲染
    }, 

 // 清缓存
 clearCache:function(){
    that.setData({
      bonusHidden:false,
      nobonusHidden:true,
      loadingHidden:false,
      Start: 0,
      mybonus:[]
    }); 
},getlist: function(gp) {
      var userId = wx.getStorageSync("userId")
      var LoginId = wx.getStorageSync("LoginId")
      wx.request({
        url: app.globalData.apiurl + "/xapiajax.ashx", 
        data: { 
          action:"getjianjinlist0",
           t:that.data.nav,
           addtime:that.data.addtime,
           Start:that.data.Start,
           userId:(userId==null?"":userId),
           LoginId:(LoginId==null?"":LoginId)
        },
        method:"GET",
        dataType:"json", 
        header: { 
          "content-type": "application/json" // 默认值
        },
        success (res) { 
            if(res.data.status==1){
              var tmpArr = null;
              tmpArr = that.data.mybonus;
              tmpArr.push.apply(tmpArr,res.data.data);
              that.setData({
                  categorys:res.data.categorys,
                  mybonus: tmpArr,
                  Start: that.data.Start+res.data.data.length,
                  loadingHidden:true
              })
              if(gp==0||gp==1){
                var title=res.data.categorys[(that.data.nav-1)].title;
                that.setData({
                    title:title
                })
                wx.setNavigationBarTitle({
                  title: that.data.addtime + title
               })
            if(res.data.data.length>0){
              that.setData({
                  bonusHidden:false, 
                  nobonusHidden:true
                  
              })
            }else{
              that.setData({
                bonusHidden:true,
                nobonusHidden:false
               })
            }
          }
        }
        if(gp==1){
          //隐藏loading 提示框
          wx.hideLoading();
          //隐藏导航条加载动画
          wx.hideNavigationBarLoading();
          //停止下拉刷新
          wx.stopPullDownRefresh();
      }
          }
      }) 
    }
})
