const util = require('../../../utils/util.js');
const app = getApp();
Page({
  data: {
    isRecomClick: 1,
    userInfo: app.globalData.userInfo
  },
  onShow() {
    this.setData({ userInfo: app.globalData.userInfo });
    this.isRecomCode();
  },
  isRecomCode() {
    let that = this, userInfo = app.globalData.userInfo;
    util.ajax({
      func: "user/inviter/code",
      load: false
    }, function (res) {
      if (res.code == 0) {
        userInfo.recomCode = !util.isEmpty(res.data.inviterCode) ? res.data.inviterCode : userInfo.recomCode;
        wx.setStorageSync("WXuserInfo", userInfo);
        that.setData({ isRecomClick: (res.data.show == 0 && util.isEmpty(res.data.inviterCode) ? 0 : 1) });
      }
    });
  },
  logout() {
    let self = this;
    wx.showModal({
      content: '确定登出吗？',
      success: function (res) {
        if (res.confirm) {
          util.ajax({
            func: "login_out"
          }, function (res) {
            if (res.code == 0) {
              wx.removeStorageSync("WXuserInfo");
              app.globalData.userInfo = null;
              wx.redirectTo({
                url: '/pages/home/login?quitLogin=true'
              })
            } else
              util.showTips(res.reason);
          });
        }
      }
    });
  },
  navigatorURl(e) {
    util.navigator(e.currentTarget.dataset.url);
  },
})