<template>
	<view>
		<view class="tabBar">
			<view class="gird-tab" v-for="(item,index) in tabData" :key="index" :class="pageIndex==index?'tabOn':''"
				@click="toTab(item, index)">
				<image class="tabIcon" :src="pageIndex==index?item.icon2:item.icon1" mode="" v-if="item.style==0">
				</image>
				<view class="tabIcon" v-if="item.style==1">
					<view class="iconBox">
						<image class="tabIcon" :src="pageIndex==index?item.icon2:item.icon1" mode=""></image>
					</view>
				</view>
				<view class="tabText" v-if="textType==1">{{item.name}}</view>
				<view class="tabDrop" v-if="textType==2" :class="pageIndex==index?'dropOn':''"></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			pageIndex: {
				type: Number,
				default: 0
			},
			textType: {
				type: Number,
				default: 1
			}
		},
		data() {
			return {
				ios: false,
				tabData: [],
				userid: uni.getStorageSync('userType') //假如根据这个判断当前展示那个路由
			}
		},
		mounted() {
			// console.log(this.userid, '666');
		},
		created() {
			const self = this;
			uni.getSystemInfo({
				success: function(res) {
					if (res.osName == 'ios') {
						self.ios = true;
					}
				}
			});


			if (this.userid == 2) {
				this.tabData = [{
					pageUrl: `/pages/home/home?id=0`,
					name: '首页',
					icon1: '/static/tabar/ic_home_def.png', //默认图标
					icon2: '/static/tabar/ic_home.png', //选中图标
					style: 0
				}, {
					pageUrl: `/pages/home/person?id=1`,
					name: '个人中心',
					icon1: '/static/tabar/ic_home_def.png', //默认图标
					icon2: '/static/tabar/ic_my_info.png', //选中图标
					style: 0
				}]
			} else if (this.userid == 0) {
				this.tabData = [{
					pageUrl: `/pages/home/home?id=0`,
					name: '首页',
					icon1: '/static/tabar/ic_home_def.png', //默认图标
					icon2: '/static/tabar/ic_home.png', //选中图标
					style: 0
				}, {
					pageUrl: '/pages/home/qr?id=1',
					name: '扫一扫',
					icon1: '/static/tabar/ic_qr_code_def.png', //默认图标
					icon2: '/static/tabar/ic_qr_code.png', //选中图标
					style: 0
				}, {
					pageUrl: '/pages/home/goods?id=2',
					name: '商品管理',
					icon1: '/static/tabar/ic_goods_def.png', //默认图标
					icon2: '/static/tabar/ic_goods.png', //选中图标
					style: 0
				}, {
					pageUrl: `/pages/home/person?id=3`,
					name: '个人中心',
					icon1: '/static/tabar/ic_my_info_def.png', //默认图标
					icon2: '/static/tabar/ic_my_info.png', //选中图标
					style: 0
				}]
			} else if (this.userid == 2) {
			} else if (this.userid == 1) {
				this.tabData = [{
					pageUrl: '/pages/home/home?id=0',
					name: '首页',
					icon1: '/static/tabar/ic_home_def.png', //默认图标
					icon2: '/static/tabar/ic_home.png', //选中图标
					style: 0
				}, {
					pageUrl: '/pages/home/userManagement?id=1',
					name: '用户管理',
					icon1: '/static/tabar/ic_user_manager_def.png', //默认图标
					icon2: '/static/tabar/ic_user_manager.png', //选中图标
					style: 0
				}, {
					pageUrl: `/pages/home/qr?id=2`,
					name: '扫一扫',
					icon1: '/static/tabar/ic_qr_code_def.png', //默认图标
					icon2: '/static/tabar/ic_qr_code.png', //选中图标
					style: 0
				}, {
					pageUrl: '/pages/home/goods?id=3',
					name: '商品管理',
					icon1: '/static/tabar/ic_goods_def.png', //默认图标
					icon2: '/static/tabar/ic_goods.png', //选中图标
					style: 0
				}, {
					pageUrl: `/pages/home/person?id=4`,
					name: '个人中心',
					icon1: '/static/tabar/ic_home_def.png', //默认图标
					icon2: '/static/tabar/ic_home.png', //选中图标
					style: 0
				}]
			}
		},
		methods: {

			toTab(item, index) {
				if (this.pageIndex != index) {
					this.$emit('toTab', item);
				}
			}

		}
	}
</script>

<style lang="scss">
	.tabBar {
		width: 100%;
		display: flex;
		position: fixed;
		padding: 20rpx 0;
		bottom: 0;
		box-shadow: 0rpx 0rpx 20rpx #e2e2e2;
		background: white;

		.gird-tab {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			position: relative;

			.tabText {
				font-size: 24rpx;
				padding-top: 10rpx;
			}

			.tabIcon {
				width: 50rpx;
				height: 50rpx;
				position: relative;
			}

			.tabDrop {
				width: 8rpx;
				height: 8rpx;
				background-color: #dddddd;
				border-radius: 50%;
				margin-top: 10rpx;
			}

			.dropOn {
				background-color: #DE1F27;
			}

			.iconBox {
				width: 88rpx;
				height: 88rpx;
				background-color: #D6955B;
				position: absolute;
				bottom: 0;
				left: 50%;
				margin-left: -50rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 50%;
				border: 10rpx solid #fff;
				box-shadow: 0rpx -10rpx 20rpx #e2e2e2;
			}
		}

		.tabBadge {
			position: absolute;
			left: 55%;
			top: -20rpx;
		}
	}

	.tabOn .tabText {
		color: #B87A43;
	}
</style>