<template>
	<div v-if="useMenuList">
		<div v-for="(item, index) in menuList" :key="index" class="classifyButtonList">
			<div flex="cross:center" flex-wrap>
				<div class="title" @click="menuclick(item)">
					<i :class="item.type?'el-icon-star-on':'el-icon-star-off'"></i>
					<span :class="{'active':item.type}">{{item.label}}</span>
				</div>

			</div>
			<menu-tree v-if="item.children" :use-menu-list="true" :parent-tree-data="item.children" ></menu-tree>
		</div>
	</div>
</template>

<script>
	export default {
		name: "menuTree",
		props: {
			useMenuList: {
				type: Boolean,
				default: false,
			},
			parentTreeData: {
				type: Array,
				default: () => {
					return []
				}
			},
		},
		data() {
			return {
				menuList: [],
				menuPopedom: []
			}
		},
		created() {
			this.menuList = Object.assign([], this.parentTreeData)
		},

		methods: {
			menuclick(item) {
				item.type = !item.type
				// if (item.children != null && item.children && item.children.length) {
				// 	this.allClick(item.children,item.type )
				// }
				this.menuPopedom.push(item.id)
				this.setMenuPopedom(this.menuPopedom)
				this.$forceUpdate()
			},
			setMenuPopedom(arr) {
				 let newArr = []
				   arr.forEach((val)=>{
				         if(newArr.indexOf(val) == -1){
				              newArr.push(val)
				          }
				})
				this.menuPopedom = newArr
			},
			allClick(data, type) {
				data.forEach(el => {
					el.type = type
					if (el.children != null && el.children && el.children.length) {
						this.allClick(el.children, type)
					}
				})
			},
			changeMenu(data, num) {
				let level = num
				level = level + 1
				data.forEach(el => {
					el.buttonList = []
					// el.isShow = true
					el.level = level
					if (el.children != null && el.children && el.children.length) {
						this.changeMenu(el.children, level)
					}
				})
			},
		}
	}
</script>
<style lang="scss">
	$activeColor: var(--bg-color, "#00aaff");

	.el-icon-star-on {
		/* color: #00aa00; */
		color: $activeColor;
	}

	.classifyButtonList {
		s .active {
			color: $activeColor;
		}
	}

	// .recordText {
	// 	border: 1px solid #fff;
	// 	padding: 3px 10px;
	// 	text-align: center;
	// 	font-size: 14px;
	// 	cursor: pointer;
	// 	background: #f2f2f2;
	// 	color: #4e4e4e;
	// 	margin:5px;
	// 	border-radius: 5px;
	// }

	// .recordText.active {
	// 	background-color: $activeColor;
	// 	color: white;
	// }
</style>
<style scoped lang="scss">
	.tree-div {}

	.classifyButtonList {
		// margin-bottom: 10px;
		padding: 0 0 0 10px;
		// cursor: pointer;
		line-height: 25px;

		.title {
			// text-align: right;
			cursor: pointer;
			width: 100%;
			border-bottom: 1px solid #ccc;
		}

	}
</style>
