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

  /**
   * 页面的初始数据
   */
  data: {
    codeImg : '',
    avator: 'https://bigaka-xie.oss-cn-shanghai.aliyuncs.com/biaka_default_u_logo.png',
    name :''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const currentEnv = wx.getStorageSync('_qyWeChat');
    if (currentEnv) {
      this.getEnterpriseQrcode();
      this.getAvator();
      this.getName();
    }
    else {
      //不是在企业微信内打开的 提示信息
      wx.showToast({
        title: '请在企业微信内打开!',
        icon: 'none'
      });
    }
  },
  //获取员工名称
  getName(){
    let currentUserInfo = wx.getStorageSync('guidBaseInfo');
    if (!currentUserInfo) { //未登录成功
      wx.redirectTo({
        url: '/shoppingGuid/page/pages/welcomGuider/welcomGuider',
      });
      return;
    }

    let userInfo = wx.getStorageSync('guidInfo');
    let name = '';
    if (currentUserInfo.member) {
      if (!currentUserInfo.member.qiyeInfo.name) {
        name = userInfo.nickName;
      }
      else {
        name = currentUserInfo.member.qiyeInfo.name;
      }
    }

    this.setData({
      name: name
    })

  },
  //获取企业二维码
  getEnterpriseQrcode(){
    wx.qy.getQrCode({
      success: res => {
        console.log('获取员工二维码---', res)
        this.setData({
          codeImg: res.qrCode
        });
      },
      fail: res => {
        console.log('获取员工二维码失败---', res)
      }
    });
  },

  //获取头像
  getAvator(){
    wx.qy.getAvatar({
      success: res => {
        console.log('获取员工二头像---', res)
        this.setData({
          avator: res.avatar
        });
      },
      fail: res => {
        console.log('获取员工头像失败---', res)
      }
    });
  },

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

  },
  


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})