//index.js
//获取应用实例
const app = getApp()
var abouturl = '';

Page({
  data: {
    realName: '',
    count: '',
    program: '',
    code: '',
    userInfo:{},
    appVersion: app.globalData.appVersion
  },
  onLoad: function () {
    this.getCode();
    this.getStaticurl();
    this.getUserInfo();
  },

  getCode(){
    let that = this;
    wx.login({
      success: function (ret) {
        that.code = ret.code;
      }
    });
  },

  getStatic: function(){
    
  },
  
  onShow:function(){
    var that = this;
    app.ajaxReadyCallback = res => { 
      var apiname = res.data.apiname;
      if (apiname == 'logout'){
        app.globalData.isTourist = false;
        app.globalData.userinfo = {};
        wx.clearStorageSync();
        wx.reLaunch({ //关闭所有页面，打开到应用内的某个页面
          url: '/pages/splash/splash'
        })
      } else if (apiname == 'staticurl'){
        abouturl = res.data.data.aboutUrl;
      }else if (apiname == 'userInfo'){
          that.setData({
              userInfo:res.data.data
          })
      }else{
        that.setData({
          count: res.data.data
        });
      }
    }
    // this.getUnreadCount();
  },

  logout:function(e){
    app.globalData.userinfo = {};
    app.logout();
    setTimeout(function(){
      wx.reLaunch({ //关闭所有页面，打开到应用内的某个页面
        url: '/pages/splash/splash'
      })
    },2000);
  },

  getUserInfo(){
      app.ajax({
          url: app.globalData.serverUrl + '/User/info',
          type: 'POST',
          apiname:'userInfo',
          data: {

          }
      });
  },

    getStaticurl:function(){
        var org = app.globalData.userinfo.org;
        app.ajax({
            url: app.globalData.serverUrl + '/Login/staticUrl',
            type: 'POST',
            apiname:'staticurl',
            data: {

            }
        });
    },
  getUnreadCount:function(){
    var org = app.globalData.userinfo.org;
  
    app.ajax({
      url: app.globalData.serverUrl + 'server/notice/queryNoticeCount',
      type: 'POST',
      data: {
        orgId: org.orgId
      }
    });
  },

  about: function(e){
    console.log(abouturl)
    if (!abouturl){
      return false;
    }
    app.gotopage('/pages/webview/index', { url: abouturl });
    return false;
  }
  
})
