<template>
	<view class="main">
		<!-- 一级循环 -->
		<view class="one" v-for="(item,index) in menuList" :key="index" :class="item.oneStare?'oneshow':'onehide'">
			<view class="one-label" @tap="oneList(index,item)">
				<view class="left">
					<uni-icons v-if="item.icon" :type="item.icon" size="20" color="#07C4A8"></uni-icons>
					<text>{{item.name}}</text>
				</view>
				<view class="right">
					<uni-icons v-if="item.children&&item.children.length>0" :type="item.oneStare?'bottom':'forward'"
						size="20" color="#07C4A8"></uni-icons>
				</view>
			</view>
			<!-- 二级循环 -->
			<view class="two" v-for="(item2,index2) in item.children" :key="index2"
				:class="item2.twoStare?'twoshow':'twohide'">
				<view class="two-label" @tap="twoList(index,index2,item2)">
					<view class="left">
						<uni-icons v-if="item2.icon" :type="item2.icon" size="20"></uni-icons>
						<text>{{item2.name}}</text>
					</view>
					<view class="right">
						<uni-icons v-if="item2.children&&item2.children.length>0"
							:type="item2.twoStare?'bottom':'forward'" size="20"></uni-icons>
					</view>
				</view>
				<view class="three">
					<!-- 三级循环 -->
					<view class="three-label" v-for="(item3,index3) in item2.children" :key="index3"
						@tap="thrList(item3)">
						<view class="left">
							<uni-icons v-if="item3.icon" :type="item3.icon" size="20" color="#858585"></uni-icons>
							<text>{{item3.name}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		menu
	} from '@/common/site.js';
	export default {
		data() {
			return {
				id: '',
				user: {},
				menuList: menu
			}
		},
		onLoad: async function(e) {
			const that = this;
			that.$set(that, `id`, e && e.id || '');
			that.searchToken();
		},
		methods: {
			searchToken() {
				const that = this;
				try {
					const res = uni.getStorageSync('token');
					if (res) {
						const user = that.$jwt(res);
						that.$set(that, `user`, user);
					} else {
						uni.navigateTo({
							url: `/pages/login/index`
						})
					}
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			// 一级菜单展开
			oneList(index, item) {
				const that = this;
				let menuList = that.menuList;
				menuList[index]['oneStare'] = !menuList[index]['oneStare'];
				if (item && item.route) {
					uni.navigateTo({
						url: `/${item.route}?id=${that.id}`
					})
				}
			},
			// 二级菜单展开
			twoList(index, index2, item2) {
				const that = this;
				let menuList = that.menuList;
				menuList[index].children[index2]['twoStare'] = !menuList[index].children[index2]['twoStare'];
				if (item2 && item2.route) {
					uni.navigateTo({
						url: `/${item2.route}?id=${that.id}`
					})
				}
			},
			// 三级菜单
			thrList(item3) {
				const that = this;
				if (item3 && item3.route) {
					uni.navigateTo({
						url: `/${item3.route}?id=${that.id}`
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {

		/* 一级 */
		.one {
			transition: all 0.5s;

			.one-label {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 4vw;
				border-bottom: 1px var(--feColor) solid;

				.left {
					display: flex;
					align-items: center;
					font-size: var(--font16Size);
					font-weight: bold;
					color: var(--f07CColor);

					text {
						margin: 0 0 0 1vw;
					}
				}
			}
		}

		/* 二级 */
		.two {
			transition: all 0.5s;

			.two-label {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 4vw;
				border-bottom: 1px var(--feColor) solid;

				.left {
					display: flex;
					align-items: center;
					font-size: var(--font15Size);

					text {
						margin: 0 0 0 1vw;
					}
				}
			}
		}


		/* 三级 */
		.three {
			.three-label {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 4vw;
				border-bottom: 1px var(--feColor) solid;

				.left {
					display: flex;
					align-items: center;
					font-size: var(--font14Size);
					color: var(--f85Color);

					text {
						margin: 0 0 0 1vw;
					}
				}
			}
		}

		/* 展开收起效果 start */

		.oneshow {}

		.oneshow .two {
			display: block;
		}

		.onehide {}

		.onehide .two {
			display: none;
		}

		/* 展开收起效果 end */

		.twoshow {}

		.twoshow .three {
			display: block;
		}

		.twohide {}

		.twohide .three {
			display: none;
		}
	}
</style>