// pages/user/personalSettle/personalSettle.js
const app = getApp();
const api = app.api;
import regeneratorRuntime from '../../..//utils/runtime'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:undefined,
    isLogin:false,
    isShowPop:false,
    isAdmin: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   // this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    this.getData();
  },
  async hasLogins(){
    if(!this.data.isLogin){
      if(await app.authorization()){
        this.notLoginGo();
      }
      this.setData({
        isLogin:true
      });
      return
    }else {
      this.notLoginGo();
    }
  },
  getData(){
    app.post(api.getBaseInfo,{},{noLogin:true,showLoading:false, needToken:false}).then(res=>{
      this.setData({
        userInfo:res.data
      })
    })
  },
  notLoginGo: async function(){
    const userInfo = await app.getToken();
    if (!userInfo.auth) {
      wx.switchTab({
        url:"/pages/index/index",
        success:(res)=>{
          this.setData({
            isLogin:false
          });
        }
      })
      return false
    }else{
      this.getData();
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

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

  },
  artUpload: function(){
    const that = this;
    app.post(api.getUserSettleInfo,{},{
      needToken:false
    }).then(res => {
      const settleInfo = res.data;
      if(settleInfo.isVerification==0){
        that.showPop()
      }else{
        wx.navigateTo({
          url: '/pages/user/artUpload/artUpload'
        })
      }
    })
  },

  goMall(){
    wx.navigateToMiniProgram({
      appId: 'wx7e1594d8fd280a80'
    });
    // wx.showToast({
    //   title: '敬请期待',
    //   icon: 'none',
    //   duration: 2000
    // })
  },
  showPop(){
    this.setData({
      isShowPop:true
    });
  },
  hidePop(){
    this.setData({
      isShowPop:false
    });
  },
  // 邀请码核销
  openScan(){
    wx.scanCode({
      onlyFromCamera: true, // 仅允许从相机扫码
      scanType: ['qrCode'], // 仅支持二维码 
      success (res) {
        wx.navigateTo({
          url: '../../invitation/verify/index?id=' + res.result,
        })
      },
      fail () {
        wx.showToast({
          title: '相机调用失败,请检查微信是否开启相机的使用权限'
        })
      }
    })
  }
})