<template>
	<view class="container">
			<swiper class="main"  :autoplay="false" :current="currentPage" :duration="duration" easing-function="linear" @change="changeSwiper">
				<swiper-item>
					<index @changeTab="getChangeTab"></index>
				</swiper-item>
				<swiper-item>
					<mine></mine>
				</swiper-item>
			</swiper>
		<tabBar :current="currentPage" @change="changePage"></tabBar>
	</view>
</template>

<script>
	import tabBar from "@/components/tabBar/tabBar.vue"
	import index from "@/pages/homePage/index/index.vue"
	import mine from "@/pages/homePage/mine/mine.vue"

	import {
		getUserInfo
	} from '@/common/js/api/homePage/login.js'

	import {
		mapState,
		mapActions
	} from 'vuex';
	export default {
		components: {
			tabBar,
			index,
			mine,
		},
		data() {
			return {
				currentPage: 1,
				duration: 200
			}
		},
		computed: {
			...mapState([
				'userInfo'
			]),
		},
		onLoad(op) {
			this.currentPage = op.current ?  op.current : 0;
			if (!uni.getStorageSync('userToken')) {
				getApp().globalData.isLogin = false;
				console.log('== 当前登录状态 ==', getApp().globalData.isLogin)
			} else {
				this.getUserInfo();
			}
		},
		methods: {
			...mapActions([
				'setUserInfo'
			]),
			changePage(index) {
				// if(index == 1 && !getApp().globalData.isLogin){
				// 	this.$util.Tips({
				// 		title: "请您登录/注册",
				// 		success: () => {
				// 			uni.navigateTo({
				// 				url: '/pages/homePage/login/login'
				// 			})
				// 		}
				// 	});
				// 	return false
				// }
				this.currentPage = index;
			},
			getUserInfo() {
				getUserInfo().then(res => {
					if(res.code == 200){
						this.setUserInfo(res.data);
					}
				})
			},
			getChangeTab(type) {
				this.currentPage = type;
			},

			changeSwiper(e){
				this.currentPage = e.detail.current;
			}
		}
	}
</script>

<style lang="less">
	.container {
		height: 100vh;
		display: flex;
		flex-direction: column;
		overflow: hidden;
		box-sizing: border-box;
		.main {
			flex: 1;
		}
	}
</style>
