<template>
	<view class="container">
		<!-- 顶部选择校区区域 -->
		<view class="top">
			<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text" activeColor="#6FB6B8"></uni-segmented-control>
		</view>

		<view class="gap"></view>

		<!-- 主体内容区域 -->
		<view class="body">
			<!-- 左边区域 -->
			<view class="body_left">
				<view class="body_left_item" :class="{ active: active_left === index }" v-for="(item, index) in leftList" :key="index" @click="handleChange(index)">
					{{ item }}
				</view>
			</view>

			<!-- 右边区域 -->
			<view class="body_right">
				<view class="body_right_item" :class="{ active: active_right === index }" v-for="(item, index) in rightList" :key="index" @click="handleChange2(index)">
					{{ item }}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 顶部分段器选项数组
			items: ['黄家湖校区', '墨轩湖校区'],
			// 分段器当前索引
			current: 0,
			// 左边分类数组
			leftList: ['教学楼', '行政楼', '综合楼', '科技楼', '学生宿舍', '其他'],
			// 左边分类数组当前索引
			active_left: 0,
			// 右边分类数组
			rightList: ['1栋', '2栋', '3栋', '4栋', '5栋', '6栋', '7栋', '8栋', '体育场', '篮球场', '其他'],
			// 右边分类数组当前索引
			active_right: 0
		}
	},
	methods: {
		// 顶部分段器切换选项回调
		onClickItem(e) {
			if (this.current != e.currentIndex) {
				this.current = e.currentIndex
			}
		},
		// 左边数组切换回调
		handleChange(index) {
			this.active_left = index
		},
		// 右边数组切换回调
		handleChange2(index) {
			this.active_right = index
			const repairsArea = this.items[this.current] + this.leftList[this.active_left] + this.rightList[this.active_right]
			uni.$emit('addRepairsArea', {
				data: repairsArea
			})
			uni.navigateBack(1)
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	width: 100vw;
	height: 100vh;

	.top {
		height: 100rpx;
	}

	.gap {
		height: 10rpx;
		background-color: #f2f2f2;
	}

	.body {
		display: flex;
		height: calc(100vh - 110rpx);

		.body_left {
			box-sizing: border-box;
			padding: 15rpx;
			width: 198rpx;
			border-right: 1rpx solid #ccc;
			overflow-y: auto;

			.body_left_item {
				width: 100%;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 28rpx;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}

			.active {
				color: #6fb6b8;
			}
		}

		.body_right {
			box-sizing: border-box;
			padding: 30rpx 40rpx;
			width: 552rpx;
			overflow-y: auto;

			.body_right_item {
				float: left;
				box-sizing: border-box;
				margin: 0 12rpx 28rpx 0;
				padding: 10rpx 30rpx;
				height: 50rpx;
				line-height: 30rpx;
				text-align: center;
				color: #808080;
				font-size: 28rpx;
				border-radius: 53rpx;
				background-color: #e6e6e6;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}

			.active {
				color: #fff;
				background-color: #6fb6b8;
			}
		}
	}
}

::v-deep .segmented-control {
	height: 100rpx;
}
</style>
