<script setup>
	/**
	 * name：
	 * user：sa0ChunLuyu
	 * date：2022-04-19 14:58:23
	 */
	import {
		ref
	} from 'vue'
	import {
		getUserInfoAction,
		getConfigAction
	} from '@/api/index.js'
	const is_login = ref(false)
	const login_show = ref(true)
	const phone_show = ref(true)

	const props = defineProps({
		type: {
			type: String,
			default: 'fixed'
		}
	});

	import {
		onShow,
	} from '@dcloudio/uni-app'

	onShow(() => {
		getUserInfo()
	})

	const toLogin = () => {
		let routes = getCurrentPages();
		let curRoute = routes[routes.length - 1].route
		uni.setStorageSync('JUMP_PATH', '/' + curRoute)
		uni.navigateTo({
			url: '/pages/main/login/login'
		})
	}
	const getConfigPhone = () => {
		getConfigAction("'设置手机号'", (list) => {
			if (Number(list["设置手机号"].content) === 2) {
				login_show.value = false
				phone_show.value = false
			}
		})
	}
	const getUserInfo = () => {
		login_show.value = true
		phone_show.value = true
		is_login.value = false
		getUserInfoAction((info) => {
			is_login.value = true
			if (info.phone) {
				login_show.value = false
			} else {
				getConfigPhone()
			}
		}, false)
	}

	const toUserSetInfo = () => {
		uni.navigateTo({
			url: '/pages/user/set_info/set_info'
		})
	}

	defineExpose({
		getUserInfo
	})
</script>
<template>
	<view v-if="login_show">
		<view class="login_wrapper" v-if="!is_login" :style="{
			position: props.type
		}" @click="toLogin()"></view>
		<view class="phone_wrapper" v-if="phone_show" :style="{
			position: props.type
		}" @click="toUserSetInfo()"></view>
	</view>
</template>
<style scoped>
	.phone_wrapper {
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		background: #000000;
		opacity: 0;
		z-index: 9998;
	}

	.login_wrapper {
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		background: #000000;
		opacity: 0;
		z-index: 9999;
	}
</style>
