<!-- 底部导航组件 -->
<template>
	<view class="tabBar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
		<view class="tab-bar-box">
			<view class="null-box"></view>
			<view class="tba-bar-min-box" @click="tabBarGoPage(1)">
				<img :src="imagesUrl('commonality/icon_sy_xz@1x.png')" v-if="currentRoute == 'pages/views/home/home'">
				<img :src="imagesUrl('commonality/icon_sy_zc@1x.png')" v-else>
				<view :class="currentRoute == 'pages/home'?'primary':''">首页</view>
			</view>
			<view class="null-box"></view>
			<view class="tba-bar-min-box" @click="tabBarGoPage(2)">
				<img :src="imagesUrl('commonality/icon_sys_xz@1x.png')" v-if="currentRoute == 'pages/views/teacherPage/laboratoryList'">
				<img :src="imagesUrl('commonality/icon_sys_zc@1x.png')" v-else>
				<view :class="currentRoute == 'pages/information/information'?'primary':''">实验室</view>
			</view>
			<!-- <view class="null-box"></view>
			<view class="tba-bar-min-box" @click="tabBarGoPage(3)">
				<img :src="imagesUrl('commonality/icon_xx_xz@1x.png')" v-if="currentRoute == 'pages/views/information/information'">
				<img :src="imagesUrl('commonality/icon_xx_zc@1x.png')" v-else>
				<view :class="currentRoute == 'pages/information/information'?'primary':''">消息</view>
				<view class="tips-box" v-if="totalCount>0"></view>
			</view> -->
			<!-- <view class="null-box"></view>
			<view class="tba-bar-min-box" @click="tabBarGoPage(4)">
				<img :src="imagesUrl('commonality/icon_wd_xz@1x.png')" v-if="currentRoute == 'pages/views/mine/mine'">
				<img :src="imagesUrl('commonality/icon_wd_zc@1x.png')" v-else>
				<view :class="currentRoute == 'pages/mine'?'primary':''">我的</view>
			</view> -->
			<view class="null-box"></view>
		</view>
	</view>
</template>

<script>
	import { pageRestrictVerify } from '@/utils/index'
	import {
		systemNoticeGetNoticeCount
	} from '@/pages/api/index.js'
	export default {
		name: 'tabBar',
		data() {
			return {
				paddingBottomHeight: 0, //苹果X以上手机底部适配高度
				currentRoute: "",
				userType: "",
				totalCount: 0,
			}
		},
		created() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
					model.forEach(item => {
						//适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
						if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
							that.paddingBottomHeight = 40;
						}
					})
				}
			});
		},

		onShow() {
		},
		mounted() {
			// 获取当前路由
			let pages = getCurrentPages();
			let page = pages[pages.length - 1];
			this.currentRoute = page.route;
			// 获取当前角色
			this.userType = uni.getStorageSync('userType');
			this.systemNoticeGetNoticeCount();
		},
		methods: {

			tabBarGoPage(type) {
				if (type === 1) {
					if (this.currentRoute !== 'pages/views/home/home') {
						uni.redirectTo({
							url: '/pages/views/home/home',
						});
					}
				} else if (type === 2) {
					// if (!pageRestrictVerify('laboratoryManagement')) {
					// 	uni.showToast({
					// 		title: '没有相关权限,请联系管理员',
					// 		icon: "none",
					// 		mask: true,
					// 		duration: 2000
					// 	});
					// 	return
					// }
					if (this.currentRoute !== 'pages/views/teacherPage/laboratoryList') {
						uni.redirectTo({
							url: '/pages/views/teacherPage/laboratoryList',
						});
					}
				} else if (type === 3) {
					if (this.currentRoute !== 'pages/views/information/information') {
						uni.redirectTo({
							url: '/pages/views/information/information',
						});
					}
				} else if (type === 4) {
					if (this.currentRoute !== 'pages/views/mine/mine') {
						uni.redirectTo({
							url: '/pages/views/mine/mine',
						});
					}
				}

			},
			async systemNoticeGetNoticeCount(){
					const {
						data
					} = await systemNoticeGetNoticeCount();
					if(data.code == 200){
						this.$set(this,'totalCount',data.data);
					}
			},
		}
	}
</script>

<style lang="stylus" scoped>
	.tabBar {
		z-index: 9999;
		width: 100%;
		height: 98rpx;
		background: #ffffff;
		position fixed ;
		bottom: 0;
		left: 0;
		box-shadow: 0 -3rpx 13rpx 0 rgba(0, 0, 0, 0.1);
		.tab-bar-box {
			display flex;

			.null-box {
				flex: 1;
			}

			.tba-bar-min-box {
				width: 64rpx;
				position: relative;

				img {
					width: 42rpx;
					height: 42rpx;
					margin: 15rpx auto 0;
				}

				view {
					line-height: 37rpx;
					font-size: 19rpx;
					text-align center;
					color: #666666;
				}

				.tips-box {
					position: absolute;
					top: 10rpx;
					left: 44rpx;
					display inline-block;
					background: #fa5151;
					border-radius 50%;
					width:20rpx;
					height:20rpx;
				}
			}
		}
	}
</style>
