<template>
  <div>
    <div class="flex-start">
      <div v-for="item in data" :key="item.index" @click.stop="classClick(item)">
        <p class="classItem" v-if="item.index === 1"  :class="class_act === item.itemclassnum?'act':''">{{item.itemclassname}}</p>
        <p class="classItem"  v-else   :class="class_act === item.itemclassnum?'act':''">{{item.itemclassname}}</p>
        <Tree v-if="item.subdep && class_act === item.itemclassnum" :data="item.subdep"></Tree>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Tree",
  props:['data'],
  inject:['selectThis'],
  data () {
    return {
      activeClass:{},
      class_act:0,
    }
  },
  methods:{
    classClick (item) {
      console.log(item)
      this.activeClass = item
      this.class_act = item.itemclassnum
      this.selectThis().change(item)
    },
  }
}
</script>
<style scoped>
.class-item{
  margin:0 15px;
  color: #333;
  cursor: pointer;
  transition: .2s all linear;
  font-size: 14px;
  
}
.act{
  color:#3874f6;
  font-weight: bold;
}
.classIndex{
  margin-bottom: 0px
  !important;
}
.classItem{
  flex: 0 1 auto;
  width:110px ;
  margin:10px 0px 10px 0;
  font-size:14px !important;
  cursor: pointer;
}
.flex-start{
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  position: relative;
  width: 80px;
}
</style>