<template>
	<view class="uni-tabbar">
		<view class="uni-tabbar__item" v-for="(item,index) in tabbar" :key="index" @tap="changeTab(item)">
			<view class="uni-tabbar__bd">
				<view class="uni-tabbar__icon">
					<image v-if="item.pagePath == pagePath" class="icon-img" mode="aspectFit" :src="item.selectedIconPath"></image>
					<image v-else class="icon-img" mode="aspectFit" :src="item.iconPath"></image>
				</view>
			</view>
			<view class="uni-tabbar__label" :class="{'active': item.pagePath == pagePath}">
				{{item.text}}
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		props: {
			pagePath: String
		},
		data() {
			return {
				page: 'contact',
				showPage: false,
				containerHeight: 400,
				tabbar: [
					//动态切换的菜单，先隐藏，动态插入
					{
						pagePath: "/pages/index/index",
						iconPath: "/static/img/index_active.png",
						selectedIconPath: "/static/img/index.png",
						text: "活动详情"
					},
					{
						pagePath: "/pages/index/guide",
						iconPath: "/static/img/guide_active.png",
						selectedIconPath: "/static/img/guide.png",
						text: "操作指南"
					},
					{
						pagePath: "/pages/index/calendar",
						iconPath: "/static/img/calendar_acitve.png",
						selectedIconPath: "/static/img/calendar.png",
						text: " "
					},
					{
						pagePath: "/pages/index/my",
						iconPath: "/static/img/my_acitve.png",
						selectedIconPath: "/static/img/my.png",
						text: "个人中心"
					}
				]
			};
		},
		watch: {
			pagePath: {
				handler(val) {
					console.log('pagePath监听===val', val)
				},
				immediate: true
			}
		},
		mounted() {
			if(uni.getStorageSync('doctorAndSpecialist')==2){
				this.tabbar.splice(2, 1, 
				{
					pagePath: "/pages/index/calendarExpert",
					iconPath: "/static/img/calendar_acitve.png",
					selectedIconPath: "/static/img/calendar.png",
					text: "病历审核"
				})
			}else{
				this.tabbar.splice(2, 1,
				{
					pagePath: "/pages/index/calendar",
					iconPath: "/static/img/calendar_acitve.png",
					selectedIconPath: "/static/img/calendar.png",
					text: "数据中心"
				},)
			}
		},
		methods: {
			changeTab(item) {
				this.page = item.pagePath;
				// 使用reLaunch关闭所有的页面，打开新的栏目页面
				uni.reLaunch({
					url: this.page
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.uni-tabbar {
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 999;
		width: 100%;
		display: flex;
		justify-content: space-around;
		padding: 16rpx 0;
		box-sizing: border-box;
		background-color: #fff;
		// box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
		padding-bottom: 20rpx;

		.uni-tabbar__item {
			display: block;
			line-height: 24rpx;
			font-size: 20rpx;
			text-align: center;
			width: 25%;
		}

		.uni-tabbar__icon {
			height: 24px;
			line-height: 24px;
			text-align: center;
		}

		.icon {
			display: inline-block;
		}

		.uni-tabbar__label {
			margin-top: 14rpx;
			line-height: 24rpx;
			font-size: 24rpx;
			color: #999;

			&.active {
				color: #1ca6ec;
			}
		}

		.icon-img {
			height: 24px;
			width: 24px;
		}
	}
</style>