<template>
  <view class="lottie-bg">
    <view id="lottie">
			<image src="https://download.cyjyyjy.com/sysxh-logo.png"></image>
      <!-- <image src="@/static/live-logo.gif" rel="preload" mode="widthFix" style="width: 100%" /> -->
			<!-- <image src="../../static/images/loading.gif" class="loading" mode=""></image> -->
    </view>
  </view>
</template>

<script>
import { mapState, mapMutations, mapActions, mapGetters } from 'vuex'
// 组件
// import request from "@//api/request";
import { wxappAuth } from '@/api/user'
import dayjs from 'dayjs'
import store from '@/store'
import cookie from '@/utils/store/cookie'
import { parseQuery, login, handleQrCode, getCurrentPageUrl, handleUrlParam, getCurrentPageUrlWithArgs } from '@/utils'

export default {
	computed: mapGetters(['userInfo']),
  name: 'Loading',
  data() {
    return {}
  },
	onLoad() {
		
	},
  onShow() {
    // console.log('getUser',this.userInfo)
    var url = handleQrCode()
    if (!url) {
      url = handleUrlParam(getCurrentPageUrlWithArgs())
    }
    // console.log(url)
    // console.log('判断是否是分销')
    // 判断是否是分销
    if (url) {
      let urlSpread = parseInt(url.spread)
      if (urlSpread) {
        cookie.set('spread', urlSpread)
      }
    }
    if (this.$deviceType == 'app' || this.$deviceType == 'weixinh5') {
      this.$yrouter.switchTab({
        path: '/pages/home/index',
      })
      return
    }
    if (this.$store.getters.token) {
      // 如果token存在，直接进行进页面
      console.log('登录状态存在，直接进页面')
      // this.toLaunch()
			this.$yrouter.switchTab({
			  path: '/pages/home/index',
			})
      return
    }
    console.log('进行登录操作')
    login().finally(() => {
			this.$yrouter.switchTab({
			  path: '/pages/home/index',
			})
    })
  },
  methods: {
    ...mapActions(['changeAuthorization', 'setUserInfo', 'getUser']),
    toLaunch() {
      console.log('loading home')
      this.changeAuthorization(false)
      let redirect = cookie.get('redirect').replace(/\ /g, '')
      cookie.remove('redirect')
      if (redirect && redirect.indexOf('/pages') != -1) {
        this.$yrouter.replace({
          path: '/pages' + redirect.split('/pages')[1],
        })
      } else {
				login().finally(() => {
					this.$yrouter.switchTab({
					  path: '/pages/home/index',
					})
				})
      }
    },
  },
}
</script>

<style scoped lang="less">
.lottie-bg {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 999;
}

#lottie {
	width: 100%;
	height: 100%;
	background: url('https://download.cyjyyjy.com/sysxh-loading-bg.png') no-repeat;
	background-size: 100% 100%;
	color: #fff;
	font-size: 32rpx;
	text-align: center;
	position: relative;
	image{
		width: 440rpx;
		height: 440rpx;
		display: block;
		position: absolute;
		top: 250rpx;
		left: 50%;
		margin-left: -220rpx;
	}
	.loading{
		width: 68rpx;
		height: 68rpx;
		margin: 60rpx auto;
	}
}
</style>
