<template>
  <div class="tree">
    <ul v-if="treeData && treeData.length">
      <li v-for="(column, index) in treeData" :key="index">
        <div class="root-div">
          <span v-for="(item,index) in rootArr" :key="index" class="unify-root" :class="{'root':active==index}" @click="changeIdx(index)">{{item}}</span>
        </div>
        <ul v-if="column.children && column.children.length">
          <li v-for="(childrenColumn, index) in column.children" :key="index">
            <span>{{ childrenColumn.name }}</span>
            <p v-if="childrenColumn.status=='正常'">
              <i class="iconfont icon-zhengchang" style="color:#1492ff"></i>
              正常
            </p>
            <p v-if="childrenColumn.status=='滞后'">
              <i class="iconfont icon-zhihou" style="color:#D81E06"></i>
              滞后
            </p>
          </li>
        </ul>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  name: "transverseTree",
  props: {
    treeData: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {
      rootArr:['深化碧水行动','空气质量巩固提升行动','“无废城市”建设',"美丽河湖库"],
      active:0
    }
  },
  methods: {
    changeIdx(i){
      this.active = i
    }
  },
};
</script>
<style scope>
.tree {
  position: relative;
  margin: -16px auto 0;
  min-height: 450px;
  padding-left: 11px;
  overflow: auto;
}
.tree ul {
  width: 210px;
  height: 100%;
  position: absolute;
}
.tree ul ul {
  left: 176px;
  top: 0;
  width: 360px;
}
.tree ul ul li {
  width: 360px;
  display: flex;
  justify-content: space-between;
  color: #333;
  align-items: center;
}
.tree li {
  float: left;
  list-style-type: none;
  position: relative;
  padding: 16px 5px 0 5px;
}
.tree li .root-div {
  margin: 30px 0 0;
}
.tree li .unify-root {
  width: 150px;
  padding: 8px 0;
  font-size: 18px;
  margin: 12px 0;
  border: 1px solid #ddd;
  cursor: pointer;
}
.tree li .root {
  color: #1492ff;
}
.tree li span {
  position: relative;
  display: inline-block;
  border-radius: 4px;
  text-decoration: none;
  color: #2d2d2d;
  font-size: 16px;
  line-height: 36px;
  text-align: center;
  padding: 0 12px;
}

.tree li::before {
  box-sizing: inherit;
  content: "";
  position: absolute;
  top: 33px;
  left: -7px;
  border-top: 2px solid #1492ff;
  width: 12px;
}
.tree li::after {
  box-sizing: inherit;
  content: "";
  position: absolute;
  top: 8px;
  left: -7px;
  height: 100%;
  border-left: 2px solid #1492ff;
}
.tree li:first-child::after {
  height: 51%;
  border-left: 2px solid #1492ff;
  border-top: 2px solid #1492ff;
  top: 33px;
  width: 1px;
  border-top-left-radius: 4px;
}
.tree li:last-child::after {
  height: 25px;
  border-left: 2px solid #1492ff;
  border-bottom: 2px solid #1492ff;
  top: 8px;
  width: 1px;
  border-bottom-left-radius: 4px;
}
.tree li:only-child::after,
.tree li:only-child::before {
  display: none;
}
.tree ul ul li:only-child::before {
  display: inline-block;
}
.tree ul ul li:only-child span::before {
  display: inline-block;
}
.tree li:only-child span.root::before,
.tree li:only-child span.hasChild::before {
  content: "";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: -14px;
  border-top: 2px solid #1492ff;
  width: 14px;
}
.tree ul ul ul li:only-child span::before {
  content: "";
  position: absolute;
  top: 17px;
  left: -26px;
  border-top: 2px solid #1492ff;
  width: 26px;
}
</style>