<template>
	<view class="MenuTab">
		<!-- 第一层tab -->
		<view class="menuBox">
			<u-tabs :list="typeList" lineWidth="30" lineColor="#f1f1f1"
				:activeStyle="{color: '#000',fontWeight: 'bold',fontSize:'40rpx'}"
				itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;" :current="activeId"
				@change="changeFirstTab">
				<view slot="right" style="padding-left: 4px;" @tap="handleShowAll">
					<i class="custom-icon custom-icon-all"></i>
				</view>
			</u-tabs>
		</view>

		<!-- 第二层tab -->
		<view class="subMenuBox" v-show="show">
			<view class="subTitle">所有分类</view>
			<view class="subMenu">
				<u-tag :text="item.name" type="warning" shape="circle" v-for="(item,index) in typeList" :key="item.id"
					@click="changeSecondTab(item,index)"></u-tag>
			</view>
		</view>
		<!-- 遮罩层 -->
		<view class="overlay" v-show="show"></view>
	</view>

</template>

<script>
	export default {
		props: {
			typeList: {
				type: Array,
				default: () => [{id:1,name:'111',},{id:2,name:'222'}]
			}
		},
		data() {
			return {
				activeId: 0,
				show: false,
			}
		},
		methods: {
			// 切换选择第一层tab
			changeFirstTab(val) {
				console.log(val)
				this.show = false
				this.$emit('changeTab', val)
			},
			// 切换选择第二层tab
			changeSecondTab(item, index) {
				console.log('index',item, index)
				this.activeId = index
				this.show = false
				this.$emit('changeTab', item)
			},
			// 展开第二层tab
			handleShowAll() {
				this.show = !this.show
			},
		}
	}
</script>

<style lang="scss">
	.MenuTab {
		position: relative;
		height: 80rpx;
		line-height: 80rpx;
		z-index: 2;

		.menuBox {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0 40rpx;

			.u-tabs {
				width: 100%;
			}
		}

		.active {
			font-size: 40rpx;
			font-weight: bold;
		}

		.subMenuBox {
			width: 100%;
			position: absolute;
			left: 0;
			top: 100%;
			z-index: 10;
			background-color: #fff;
			box-shadow: 0 12rpx 24rpx rgba(0, 0, 0, 0.175);
			border-radius: 0 0 20rpx 20rpx;
			padding: 50rpx 40rpx;

			.subTitle {
				font-size: 40rpx;
				margin-bottom: 20rpx;
				font-weight: 600;
			}

			.subMenu {
				display: flex;
				flex-wrap: wrap;
				// justify-content: space-between;
				align-items: center;
				.u-transition{
					margin: 10rpx;
				}
			}
		}

		.overlay {
			width: 100%;
			// 高度是减去了页面 头部100 搜索88和上下margin40 tab80
			height: calc(100vh - 100rpx - (88rpx + 40rpx) - 80rpx);
			background-color: rgba(0, 0, 0, 0.5);
		}
	}
</style>