<template>
	<view class="MenuTab">
		<!-- 第一层tab -->
		<view class="menuBox">
			<!-- <view v-for="item in firstList" :key="item.id" :class="{active:activeId ===item.id}"
				@click="handleSelect(item.id)">
				{{item.name}}
			</view>
			<i :class="['custom-icon', 'custom-icon-all', {active:activeId ===-1}]" @click="handleSelect(-1)"></i> -->
			<u-tabs :list="firstList">
				<view slot="right" style="padding-left: 4px;" @tap="$u.toast('插槽被点击')">
					<i class="custom-icon custom-icon-all" @click="handleSelect(-1)"></i>
				</view>
			</u-tabs>
		</view>


		<!-- 第二层tab -->
		<view class="subMenuBox" v-show="show">
			<view class="subTitle">所有分类</view>
			<view class="subMenu">
				<view v-for="item in secondList" :key="item.id" @click="handleSelectTab(item.id)">
					{{item.name}}
				</view>
			</view>
			<!-- <u-tabs :list="secondList" @click="handleSelectTab" :activeStyle="{color: '#303133',fontWeight: 'bold',transform: 'scale(1.05)'}"></u-tabs> -->
		</view>
		<!-- 遮罩层 -->
		<view class="overlay" v-show="show"></view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				// 第一层tab
				firstList: [{
						id: 1,
						name: "全部"
					},
					{
						id: 2,
						name: "推荐"
					},
					{
						id: 3,
						name: "泰兴"
					},
					{
						id: 4,
						name: "科技"
					},
					{
						id: 5,
						name: "生活"
					},{
						id: 5,
						name: "生活"
					},{
						id: 5,
						name: "生活"
					},{
						id: 5,
						name: "生活"
					},{
						id: 5,
						name: "生活"
					},
				],
				secondList: [{
						id: 1,
						name: "全部"
					},
					{
						id: 2,
						name: "推荐"
					},
					{
						id: 3,
						name: "泰兴"
					},
					{
						id: 4,
						name: "科技"
					},
					{
						id: 5,
						name: "生活"
					},
					{
						id: 6,
						name: "金融"
					},
					{
						id: 7,
						name: "其他"
					}
				],
				activeId: 1,
				show: false,
			}
		},
		methods: {
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			},
			change(index) {
				this.current = index;
			},
			// 选中第一层的tab
			handleSelect(id) {
				console.log(id)
				this.activeId = id
				if (id === -1) {
					this.show = !this.show
				} else {
					this.show = false
				}

			},
			// 选中第二层tab
			handleSelectTab() {
				this.show = false
			}
		}
	}
</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;
		}

		.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: 50rpx;
				font-weight: 600;
			}

			.subMenu {
				display: flex;
				justify-content: space-between;
				align-items: center;
			}
		}

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