<template>
	<view id="home">
		<teacherHome class="flex-box-page" v-if="userType==1"></teacherHome>
		<pupilHome class="flex-box-page" v-if="userType==2"></pupilHome>
	</view>
</template>
<script>
	import {
		teacherHome
	} from '@/pages/views/teacherPage/teacherHome'
	import {
		pupilHome
	} from '@/pages/views/pupilPage/pupilHome'
	export default {
		name: "home",
		components: {
			teacherHome,
			pupilHome,
		},
		data() {
			return {
				userType: 0,
			}
		},
		onLoad() {

		},
		onShow() {
			uni.removeStorageSync('planSensorList');
			if (uni.getStorageSync('token') && uni.getStorageSync('userId') && uni.getStorageSync('userType')) {
				this.userType = uni.getStorageSync('userType')
				console.log('检查用户个人信息/初始密码');
				this.passwrodTips();
			} else {
				uni.removeStorageSync('token');
				uni.removeStorageSync('userId');
				uni.removeStorageSync('userType');
				uni.redirectTo({
					url: '/pages/views/login/login',
				});
			}
		},
		methods: {
			//初始密码修改提示
			passwrodTips(){
				uni.showModal({
					title: '提示',
					cancelColor: '#999999',
					confirmColor: '#0183FA',
					content: '为了保证信息安全，是否修改默认密码',
					cancelText:'稍后修改',
					confirmText:'修改密码',
					success(res) {
						if (res.confirm) {
							console.log('确定')
							uni.navigateTo({
								url: '/pages_basics/views/editPassword/editPassword',
							});
						} else if (res.cancel) {
							console.log('取消')
						}
					}
				})
			},
		},
		onHide() {
			this.userType = 0;
		},
		onUnload() {
			this.userType = 0;
		}
	}
</script>

<style lang="stylus" scoped>
	#home {
		height: 100%;
		display: flex;
		flex-direction: column;
		.flex-box-page{
			flex:1;
			display: flex;
			flex-direction: column;
		}
	}
</style>
