<template>
	<view class="tabbar-container">
		<!-- :style="['width: calc(100% /' + tabbar.length + ')']" -->
		<view class="tabbar-item" :class="[item.centerItem ? ' center-item' : '']" v-for="(item, i) in tabbar" :key="i"
			@click="goPage(item)" v-if="'01'==nowUserType ||('02'==nowUserType && 'fabu'!=item.code)">
			<view class="item-top">
				<view style="position: relative;margin: auto;">
					<image class="dl-image" :src="menuCode === item.code ? item.selectedIconPath : item.iconPath" />
					<image v-if="1==i" class="dl-vip" src="@/static/index/vip.png" mode="aspectFit"></image>
				</view>
			</view>
			<view class="item-bottom" :class="[menuCode === item.code ? 'item-active' : '']">{{ item.text }}</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			menuCode: {
				Type: 'String',
				default: 'home'
			},
			nowUserType: {
				Type: 'String',
				default: ''
			}
		},
		data() {
			return {
				tabbar: [{
						id: 0,
						code: "home",
						text: "首页",
						iconPath: '/static/images/tabbar/home.png',
						selectedIconPath: '/static/images/tabbar/home_.png',
						centerItem: false
					},
					{
						id: 1,
						code: "dingyue",
						text: "订阅",
						iconPath: '/static/images/tabbar/dingyue.png',
						selectedIconPath: '/static/images/tabbar/dingyue_.png',
						centerItem: false
					},
					{
						id: 4,
						code: "fabu",
						text: "发布",
						iconPath: '/static/images/tabbar/new_notice.png',
						selectedIconPath: '/static/images/tabbar/new_notice.png',
						centerItem: true
					},
					{
						id: 2,
						code: "myNotice",
						text: "我的通告",
						iconPath: '/static/images/tabbar/my_notice.png',
						selectedIconPath: '/static/images/tabbar/my_notice_.png',
						centerItem: false
					},
					{
						id: 3,
						code: "my",
						text: "我的",
						iconPath: '/static/images/tabbar/my.png',
						selectedIconPath: '/static/images/tabbar/my_.png',
						centerItem: false
					}
				]
			}
		},
		onLoad() {

		},
		onUnload() {

		},
		methods: {
			/**
			 * 页面跳转
			 * @param {Object} item
			 */
			goPage(item) {
				this.$emit("changeMenu", item.code)
			}
		}
	}
</script>

<style scoped lang="scss">
	$textDefaultColor: #9B9B9B; // 文字默认颜色
	$textSelectedColor: #FC1F3E; // 文字选中颜色
	$centerItemBg: #fff; // 中间凸起按钮背景

	.tabbar-container {
		bottom: 0;
		position: fixed;
		left: 0;
		display: flex;
		width: 100%;
		height: 125rpx;
		color: $textDefaultColor;
		background-color: #F7F7F7;
		background-size: 100% 100%;
		box-shadow: 0 -3px 3px -3px rgba(0, 0, 0, 0.3);
	}

	.tabbar-item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		text-align: center;
		width: 150rpx;
		height: 120rpx;
		flex-grow: 1;
		position: relative;

		.item-top {
			padding-top: 13rpx;
			flex-shrink: 0;
			width: 150rpx;
			height: 130rpx;

			.dl-image {
				height: 53rpx;
				width: 53rpx;
			}

			.dl-vip {
				position: absolute;
				height: 20rpx;
				top: 0rpx;
				right: -21px;
			}
		}

		.item-bottom {
			width: 100%;
			font-size: 26rpx;
			position: absolute;
			bottom: 30rpx;
		}

		.item-active {
			color: $textSelectedColor;
		}
	}

	.center-item {
		position: relative;

		.item-top {
			padding-top: 0rpx !important;
			position: absolute;
			top: -55rpx;
			left: 50%;
			transform: translateX(-50%);
			width: 105rpx;
			height: 105rpx;
			background-color: $centerItemBg;
			border-radius: 50%;
		}

		.item-bottom {
			position: absolute;
			bottom: 20rpx;
		}

		image {
			width: 105rpx !important;
			height: 105rpx !important;
		}
	}
</style>