var app = getApp()
var that=null
var sopenFrame=null
var wait=120
Page( {
  data: {
    loadingHidden:false,
    szjg:0,
    jrjg:0,
    zzjfye:0,
    jrjg:0,
    jrjg:0,
    Start: 0,
    mybalance:[]
  },

  onLoad: function(options) {
      that = this 
      that.rdata(0)
      sopenFrame=setInterval(function (){
        if(app.globalData.IFRefreshzzjf==1){
            app.globalData.IFRefreshzzjf=0
            that.clearCache();
            that.rdata(0)
        }
   }, 1000);
    }, // 下拉刷新
    onPullDownRefresh: function () {
       //在当前页面显示导航条加载动画
     wx.showNavigationBarLoading(); 
     //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
     wx.showLoading({
         title: '刷新中...',
     })
     that.clearCache();
        that.rdata(1);//第一次加载数据
    },// 清缓存
   clearCache:function(){
      that.setData({
        loadingHidden:false,
        Start: 0,
        mybalance:[]
      }); 
  } // 页面上拉触底事件（上拉加载更多）
  ,onReachBottom: function () {
    if(that.data.loadingHidden){
     that.setData({
         loadingHidden:false
      }); 
      that.rdata(2);;//后台获取新数据并追加渲染
    }else{
      wx.hideLoading();
    }
  },rdata: function(gp) {
      var userId = wx.getStorageSync("userId")
      var LoginId = wx.getStorageSync("LoginId")
      var userInfodata = wx.getStorageSync("userInfo")
      var userInfo = JSON.parse(userInfodata)
     
      wx.request({
        url: app.globalData.apiurl + "/xapiajax.ashx?timestamp=" + (new Date().getTime() / 1000), 
        data: { 
          action:"getzzjfdata",
          Start: that.data.Start,
           userId:(!userId?"":userId),
           LoginId:(!LoginId?"":LoginId)
        },
        method:"GET",
        dataType:"json", 
        success (res) { 
          if(res.data.status==1){
            var tmpArr = null;
            tmpArr = that.data.mybalance;
            if(res.data.data.length>0){
                tmpArr.push.apply(tmpArr,res.data.data);
            }
              that.setData({
                szjg:res.data.szjg,
                jrjg:res.data.jrjg,
                zzjfye:res.data.zzjfye,
                ygsy:res.data.ygsy,
                zsy:res.data.zsy,
                mybalance: tmpArr,
                Start: that.data.Start+res.data.data.length,
                loadingHidden:true
               })
          }else{
            that.setData({
              loadingHidden:true
             })
            wx.showToast({
              title: res.data.msg,
              icon: "none",
              duration: 3000
             })
          }
         
          if(gp==1){
             //隐藏loading 提示框
            wx.hideLoading();
            //隐藏导航条加载动画
            wx.hideNavigationBarLoading();
            //停止下拉刷新
            wx.stopPullDownRefresh();
        }
          }
      })
      
    },onqwlog:function(e) {
      var userId = wx.getStorageSync("userId")
      var LoginId = wx.getStorageSync("LoginId")
      if(!userId||!LoginId){
            wx.navigateTo({  
              url: "../login/index"
             })
      }else{
              wx.navigateTo({  
                  url: "../zzjf_qwlog/index"
              }) 
      }
    },onzzlog:function(e) {
      var userId = wx.getStorageSync("userId")
      var LoginId = wx.getStorageSync("LoginId")
      if(!userId||!LoginId){
            wx.navigateTo({  
              url: "../login/index"
             })
      }else{
              wx.navigateTo({  
                  url: "../zzjf_log/index"
              }) 
      }
    },onlog:function(e) {
      var userId = wx.getStorageSync("userId")
      var LoginId = wx.getStorageSync("LoginId")
      if(!userId||!LoginId){
            wx.navigateTo({  
              url: "../login/index"
             })
      }else{
              wx.navigateTo({  
                  url: "../mybalance/index?t=19"
              }) 
      }
    },ontx:function(e) {
      var userId = wx.getStorageSync("userId")
      var LoginId = wx.getStorageSync("LoginId")
      if(!userId||!LoginId){
            wx.navigateTo({  
              url: "../login/index"
             })
      }else{
              wx.navigateTo({  
                  url: "../withdrawal/index?t=4"
              }) 
      }
    }
})
