
var app = getApp()
var that=null
var sopenFrame=null
Page( {
  data: {
    orderImg: '../../images/iconfont-dingdan.png',
    tipWords: '亲，您还没有推荐会员哦！',
    dataHidden:false,
    nodataHidden:true,  
    loadingHidden:false,
    jrskcount:0,
    zrskcount:0,
    zskcount:0,
    datas:[],
    Start: 0,
    t:0
  },

  onLoad: function() {
      that = this
      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({
      dataHidden:false,
      nodataHidden:true,
      loadingHidden:false,
      Start: 0,
      datas:[]
    }); 
},getlist: function(gp) {
      var userId = wx.getStorageSync("userId")
      var LoginId = wx.getStorageSync("LoginId")
      
      wx.request({
        url: app.globalData.apiurl + "/xapiajax.ashx", 
        data: { 
          action:"getmyfriendlist",
           Start:that.data.Start,
           t:that.data.t,
           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.datas;
              tmpArr.push.apply(tmpArr,res.data.data);
             
              that.setData({
                  jrskcount:res.data.tjcount,
                  zrskcount:res.data.temcount,
                  zskcount:res.data.atemcount,
                  datas: tmpArr,
                  Start: that.data.Start+res.data.data.length,
                  loadingHidden:true
              })
              if(gp==0||gp==1){
               
            if(res.data.data.length>0){
              that.setData({
                  dataHidden:false, 
                  nodataHidden:true
                  
              })
              
            }else{
              that.setData({
                dataHidden:true,
                nodataHidden:false
               })
            }
            that.setData({
               tipWords: '亲，您还没有锁客哦！'
             })
          }else{
            that.setData({
              tipWords: '亲，找不到锁客哦！'
             })
          }
        }
        if(gp==1){
          //隐藏loading 提示框
          wx.hideLoading();
          //隐藏导航条加载动画
          wx.hideNavigationBarLoading();
          //停止下拉刷新
          wx.stopPullDownRefresh();
      }
          }
      })
    },getkeyword:function(e) {
       that.setData({
           keyword:e.detail.value
       })
    },onskusers:function() {
      wx.navigateTo({  
        url: "../myskusers/index"
       })
   },onsearch:function() {
       that.clearCache();
       that.getlist(1);//第一次加载数据
    },onyj:function(e) {
      var tjcount = e.currentTarget.dataset.tjcount
      var temcount = e.currentTarget.dataset.temcount
      var zyj = e.currentTarget.dataset.zyj
      wx.showModal({
        title: "会员情况",
        content: "推荐人数："+tjcount+"\r\n团队人数："+temcount+"\r\n总业绩："+zyj+"",
        showCancel:false,
        success (res0) {
          if (res0.confirm) {
          }
        }
      });
      
   }
})
