// shoppingGuid/page/pages/welcomGuider/welcomGuider.js
const wxService = require('../../../../utils/wxService')
const app = getApp();
wxService.page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  //授权获取用户信息之后
  getGuidUserInfo(e){
    console.log(e)
    let userInfo  = e.detail;
    
    const currentEnv = wx.getStorageSync('_qyWeChat');
    console.log(currentEnv)
    //判断是在企业微信中登录
    if (currentEnv) {
      wx.qy.login({
        success: res => {
          let code = res.code;
          let param = {
            code: code,
            wechatInfo: userInfo,
            brandId: app.globalData.brandId,
          };
          console.log('调用企业微信登录接口参数----------', param)
          wxService.post('/member/qiyeweixin/minaLogin', param).then(r => {
            console.log(r)
            wx.setStorageSync('guidInfo', userInfo);
            let qiyeLoginUserInfo = r.data.data;
            wx.setStorageSync('guidBaseInfo', qiyeLoginUserInfo);
        
            wx.redirectTo({
              url: '/shoppingGuid/page/pages/home/home',
            });
          })
        },
        fail: res => {
          console.log('fail -----', res)
        }
      })
    }
    else {
      //不是在企业微信内打开的 提示信息
      wx.showToast({
        title: '请在企业微信内打开!',
        icon: 'none'
      });
    }

  },

  //进入商城
  onTapToMall(e){
    wx.redirectTo({
      url: '/pages/userCenter/userCenter',
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

})