<template>
	<view>
		<view class="left">
			<view class="item" :class="{ active: index == current }" v-for="(item, index) in list" :key="index" @click="(current = index), (now = -1)">{{ item.name }}</view>
		</view>
		<view class="right">
			<view class="list" v-if="list.length > 0">
				<view class="tags" v-for="(child, i) in list[current].children" :key="child.id" @click="select(child, i)">
					<view class="item" :class="{ active: now == i }">
						<text class="icon" v-if="now == i">&#xe602;</text>
						<text class="icon" v-else>&#xe8f2;</text>
						<text>{{ child.name }}</text>
					</view>
				</view>
				<u-empty v-if="!list[current].children"></u-empty>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [],
			now: -1,
			current: 0
		};
	},
	onLoad(e) {
		if (e.current != 'undefined') {
			this.now = e.now;
			this.current = e.current;
		}
		this.getData();
	},
	methods: {
		getData() {
			this.http.request({
				url: '/level-one-server/app/TbGoodsType/getTree',
				success: res => {
					this.list = res.data.data;
				}
			});
		},
		//选择商品分类
		select(item, index) {
			item.current = this.current;
			item.now = index;
			uni.$emit('productType', item);
			uni.navigateBack();
		}
	},
	onNavigationBarButtonTap() {
		uni.$emit('productType', {});
		uni.navigateBack();
	}
};
</script>

<style lang="scss">
.left {
	position: fixed;
	top: 40px;
	height: 100%;
	width: 35%;
	overflow-y: auto;
	z-index: 2;
	color: $font-c;
	background-color: #f1f1f1;
	.item {
		padding: 10px;
		font-size: 15px;
		&.active {
			color: $main-color;
			background-color: white;
		}
	}
}
.right {
	position: fixed;
	top: 50px;
	height: 100%;
	width: 65%;
	overflow-y: auto;
	left: 35%;
	z-index: 1;
	.list {
		padding: 0px 12px 12px 12px;
		color: $font-c;
		.item {
			padding: 8px 2px 8px 2px;
			border-bottom: 1px solid #efefef;
			&.active {
				color: $main-color;
			}
			.icon {
				float: right;
				padding-top: 3px;
			}
		}
	}
}
</style>
