<template>
	<view class="tab_bar">
		<view class="tabbarBox">
			<view class="handleBox" v-for="(item,index) in tabBarList" :key="index">
				<view class="menuBox" @click="goPages(item.pageIndex)">
					<view class="menuIcon">
						<image v-if="item.indexName!=selectIndex" class="img" :src="item.iconPath"></image>
						<image v-else class="img" :src="item.selectIconPath"></image>
					</view>
					<view class="menuName">
						<text class="Text">{{item.tabbarName}}</text>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		props: {
			page: {
				type: String,
				default: "homeIndex"
			}
		},
		watch: {
			page: {
				handler(value) {
					this.selectIndex = value;
				},
				immediate: true,
				deep: true
			}
		},
		data() {
			return {
				selectIndex: "",
				tabBarList: [{
						"flag": 'icon',
						"pageIndex": "pages/tabbar/homePage",
						"iconPath": "/static/menu_imgs/home.png",
						"selectIconPath": "/static/menu_imgs/home-default.png",
						"tabbarName": "首页"
					},
					{
						"flag": 'icon',
						"pageIndex": "pages/tabbar/workBranch",
						"iconPath": "/static/menu_imgs/home.png",
						"selectIconPath": "/static/menu_imgs/home-default.png",
						"tabbarName": "工作台"
					},
					{
						"flag": 'icon',
						"pageIndex": "pages/tabbar/personCenter",
						"iconPath": "/static/menu_imgs/home.png",
						"selectIconPath": "/static/menu_imgs/home-default.png",
						"tabbarName": "个人中心"
					}
				]
			}

		},

		//uniapp子组件不支持应用生命周期，所以只能用vue生命周期
		mounted() {

		},
		methods: {
			//进入tabble页
			goPages(pageIndex) {
				uni.switchTab({
					url: pageIndex
				})
			},

		},
	}
</script>
<style lang="scss">
	.tab_bar {
		width: 100vw;
		height: 150rpx;
		position: fixed;
		bottom: 0rpx;
		background: #ffffff;

		.tabbarBox {
			display: flex;
			margin-top: 5rpx;
			justify-content: space-evenly;

			.handleBox {
				width: 20vw;
				height: 120rpx;


				.menuBox {
					padding: 0rpx 20rpx;
					width: 120rpx;
					height: 98%;
					text-align: center;

					.img {
						width: 50rpx;
						height: 50rpx;
					}
				}
			}
		}
	}


	.Text {
		font-size: 25rpx;
	}
</style>