// pages/demo/demo.js
Page({
  data: {
    isHidden: true,
  },

  onShow() {
    let userInfo = wx.getAccountInfoSync('userinfo')
    if (userInfo && userInfo.uickName) {
      this.setData({
        userInfo: userInfo
      })
    } else {

    }
  },

  //获取用户头像
  getAvatar(e) {
    console.log(e);
    this.setData({
      avatarUrl: e.detail.avatarUrl
    })
  },

  //获取用户名称
  getName(e) {
    console.log("昵称获取:", e.detail.value);
    this.setData({
      nickName: e.detail.value
    })
  },
  gologin() {
    this.setData({
      isHidden: false
    })
  },
  //退出登录
  tuichu() {
    this.setData({
      userInfo:null,
    })
    wx.setStorageSync('userInfo', null)
  },
  potNo() { 
    this.setData({
      isHidden: true
    })
  },
  popYes() {
    console.log("头像:", this.data.avatarUrl);
    console.log("昵称:", this.data.nickName);
    let avatarUrl=this.data.avatarUrl
    let nickName =this.data.nickName
    if (!avatarUrl){
      wx .showToast({
        icon:'error',
        title:'请获取头像',
      })
      return
    }
    if (!nickName){
      wx .showToast({
        icon:'error',
        title:'请获取昵称',
      })
      return
    }

    let userInfo ={}
    userInfo.avatarUrl = avatarUrl
    userInfo.nickName = nickName
    wx.setStorageSync('userinfo', userInfo)
    this.setData({
      isHidden: true,
      userInfo: userInfo
    })
  }
})