<script>
import {
		VUE_APP_API_URL
	} from "@/config";
import Vue from 'vue'
export default {
  onLaunch: function (e) {
    var that = this; //获取设备信息
    this.setAppInfo();
    this.autoUpdate();
		// uni.hideTabBar()
  },
  globalData: {
    baseURL: VUE_APP_API_URL+ '/',
    userInfo: null,
    isIphoneX: false,
    inviterId: null,
    //分享码
    systemInfo: null,
		scene: null, //场景码
  },

  onShow(e) {
		this.globalData.scene = e.scene
    //隐藏系统tabbar
    // uni.hideTabBar();
    var query = {};
    if (e.query.q) {
      //通过扫码进来获取二维码上的参数并存入storage
      let urlSpread = e.query.q;

      if (urlSpread) {
        if (urlSpread.indexOf('?') != -1) {
          // 通过扫桌面二维码进来
          urlSpread = urlSpread.split("?")[1].replace(/=/g, ":").replace(/&/g, ",").split(",").map((item, index) => {
            item = item.split(":");
            return `"${item[0]}":"${item[1]}"`;
          }).join(",");
          query = JSON.parse("{" + urlSpread + "}");
        }

        // console.log('query1', query);
        this.globalData.inviterId = query.id;
      }
    } else {
      query = e.query;
      // console.log('query2', query);
      this.globalData.inviterId = query.id;
    }
  },

  methods: {
		autoUpdate: function () {
		  // console.log(new Date());
		  var self = this; // 获取小程序更新机制兼容
		  if (uni.canIUse('getUpdateManager')) {
		    const updateManager = uni.getUpdateManager(); //1. 检查小程序是否有新版本发布
		    updateManager.onCheckForUpdate(function (res) {
		      // 请求完新版本信息的回调
		      if (res.hasUpdate) {
		        //2. 小程序有新版本，则静默下载新版本，做好更新准备
		        updateManager.onUpdateReady(function () {
		          console.log(new Date());
		          uni.showModal({
		            title: '更新提示',
		            content: '新版本已经准备好，是否重启应用？',
		            success: function (res) {
		              if (res.confirm) {
		                //3. 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
		                updateManager.applyUpdate();
		              }
		            }
		          });
		        });
		        updateManager.onUpdateFailed(function () {
		          // 新的版本下载失败
		          uni.showModal({
		            title: '已经有新版本了哟~',
		            content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
		          });
		        });
		      }
		    });
		  } else {
		    // 如果希望用户在最新版本的客户端上体验您的小程序，可以这样子提示
		    uni.showModal({
		      title: '提示',
		      content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
		    });
		  }
		},
		
		// 获取系统栏高度
		async setAppInfo() {
		  let that = this
		  return new Promise((resolve, reject) => {
		    uni.getSystemInfo({
		      success: function (e) {
		        Vue.prototype.StatusBar = e.statusBarHeight
		        // #ifdef H5
		        Vue.prototype.CustomBar = e.statusBarHeight + 45
		        // #endif
		
		        // #ifdef APP-PLUS
		        if (e.platform == 'android') {
		          Vue.prototype.CustomBar = e.statusBarHeight + 50
		        } else {
		          Vue.prototype.CustomBar = e.statusBarHeight + 45
		        }
		        // #endif
		
		        // #ifdef MP-WEIXIN
		        let custom = wx.getMenuButtonBoundingClientRect()
		        Vue.prototype.Custom = custom
		        Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight
		        // #endif
		      },
		    })
		  })
		},
		
		
		http(mathods, url, params) {
		  var that = this;
		  var header = {
		    'content-type': 'application/json',
		    'version': '2.0',
		    'Authorization': 'Bearer ' + uni.getStorageSync('login_status') || ''
		  };
		  return new Promise((resolve, reject) => {
		    uni.showLoading({
		      title: "正在加载中..."
		    });
		    uni.request({
		      url: this.globalData.baseURL + url,
		      //请求地址
		      method: mathods,
		      //请求方法
		      header: header,
		      data: params || {},
		      //请求参数 
		      success: res => {
		        uni.hideLoading(); // console.log(res)
		        //判断token是否过期 res.data.code == 40001
		        if (!res.data.success && res.data.status == 401) {
							var pages = getCurrentPages().pop(); //当前页面
							console.log(pages.$page.fullPath)
							uni.setStorageSync('redirect',pages.$page.fullPath) //当前路由存起来，用于登录后自动跳转
							uni.navigateTo({
							  url: '/pages/authorization/index'
							});
		        }
		        resolve(res); //成功执行方法，参数值为res.data,直接将返回的数据传入
		      },
		      fail: function () {
		        //请求失败
		        uni.hideLoading();
		        uni.showToast({
		          title: '服务器错误，请稍后再试！',
		          icon: 'none'
		        });
		        reject(err);
		      }
		    });
		  });
		},
	}
};
</script>
<style lang="scss" scoped>
	@import "uview-ui/index.scss";
</style>
<style lang="less">
/**app.wxss**/
@import './assets/iconfont/iconfont.css';
@import './assets/css/base.less';
@import './assets/css/reset.less';
@import './assets/css/style.less';

radio .wx-radio-input.wx-radio-input-checked,
checkbox .wx-checkbox-input.wx-checkbox-input-checked
{
  border-color: #1d1d1d;
  background: #1d1d1d;
}
radio .wx-radio-input {
  height: 32rpx;
  width: 32rpx;
  margin-top: -4rpx !important;
  border-radius: 50%;
  border: 2rpx solid #999;
  background: transparent;
}
radio .wx-radio-input.wx-radio-input-checked::before,
checkbox .wx-checkbox-input.wx-checkbox-input-checked::before{
  border-radius: 50%; /* 圆角 */
  width: 32rpx; /* 选中后对勾大小，不要超过背景的尺寸 */
  height: 32rpx; /* 选中后对勾大小，不要超过背景的尺寸 */
  line-height: 32rpx;
  text-align: center;
  font-size: 26rpx; /* 对勾大小 30rpx */
  color: #fff; /* 对勾颜色 白色 */
  background: #1d1d1d;
  border: 2rpx solid #1d1d1d;
  transform: translate(-50%, -50%) scale(1);
  -webkit-transform: translate(-50%, -50%) scale(1);
}
.no-list{
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 46rpx;
  color: #D8D8D8;
  font-weight: 500;
  padding-top: 20%;
}
.no-list image{
  width: 536rpx;
  height: 490rpx;
}
.no-list .to-btn{
  width: 458rpx;
  height: 88rpx;
  line-height: 88rpx;
  text-align: center;
  background: #000;
  border-radius: 44rpx;
  font-size: 40rpx;
  color: #fff;
  margin-top: 160rpx;
}

</style>