<template>
	<view class="page-wrap">
		<view class="main">
			<view class="logo">
				<image src="@/static/logo-chang.jpg" mode="widthFix"></image>
				<!-- <image src="https://oss.jimeigroup.cn/static/flash-logo-text.png" mode="widthFix"></image> -->
				<!-- <text class="logo-name">
					爱尚家找房
				</text> -->
			</view>
			<view class="btn" @click="onSkip">
				<text>立即跳过({{ times }})</text>
			</view>
		</view>
		<view class="bg"></view>
	</view>
</template>

<script>
	import storage from '@/utils/storage'
	import {
		ACCESS_TOKEN,
		USER_ID,
		USER_INFO
	} from '@/store/mutation-types'
	import {
		getToken
	} from '@/api/login.js'

	// 倒计时时长(秒)
	const times = 5

	export default {
		data() {
			return {
				times,
				smsState: false
			}
		},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options = {}) {
			const refereeId = options.user_id
			if(refereeId){
				uni.setStorageSync('refereeId',refereeId)
			}
			this.checkLogin()
			this.timer()
		},
		onShow() {
		},
		methods: {

			// 执行定时器
			timer() {
				const app = this
				app.smsState = false
				if(uni.getStorageSync('skip')){
					app.onLogin()
					return;
				}
				const inter = setInterval(() => {
					app.times = app.times - 1
					if (app.times <= 0) {
						app.smsState = true
						app.times = 0
						app.onLogin()
						clearInterval(inter)
					}
				}, 1000)

			},
			checkLogin() {
				const token = storage.get(ACCESS_TOKEN)
				if (token) {
					this.$navTo('pages/index/index')
				}
			},
			// 1. 未登录则使用免密登录方式登录(游客身份)
			onLogin() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
				// const token = storage.get(ACCESS_TOKEN)
				// if (!token) {
				// 	getToken().then(res => {
						
				// 	})
				// }

			},
			onSkip(){
				uni.setStorageSync('skip',true)
				this.onLogin()
			}
		}
	}
</script>
<style>
	page{
		background-color: #ffffff;
	}
</style>
<style lang="scss" scoped>
	.page{
		min-height: 100vh;
		background: linear-gradient(#47076b, #8d1a50);
	}
	.bg {
		width: 750rpx;
		height: 78vh;
		// background: url('https://oss.jimeigroup.cn/static/login-bg01.png');
		padding: 180rpx 0;
		position: relative;
		z-index: 0;
	}

	.main {
		margin-top: 25vh;
		position: fixed;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		width: 750rpx;
		height: 900rpx;
		z-index: 100;

		.logo {
			width: 750rpx;
			margin: auto;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			align-items: center;
			image {
				width: 300rpx;
			}

			.logo-name {
				color: #ffffff;
				font-size: 40rpx;
			}
		}

		.btn {
			width: 230rpx;
			margin: auto;
			padding: 20rpx 40rpx;
			color: #ffffff;
			font-size: 28rpx;
			border-radius: 50rpx;
			background: linear-gradient(#27b0fd, #3f72f4);
			display: flex;
			justify-content: center;
		}
	}
</style>
