<template>
  <div class='list-group system-left-tree' style="overflow-x: auto">

    <div class="chi">
      <tree :model='functions'  :is-click="isClick === false ? isClick : true"  style="display: inline-block" v-ref:resourcetree>
      <span partial>

        <span  :class="{ 'tree-img': isFolder(row), 'tree-span': !isFolder(row) }" v-if="!isClick" >
          <img v-if="isFolder(row)" :src="$parent.$parent.imgSrc" alt="">{{row.data.name}}
        </span>
        <!--节点图标-->
        <img v-if="row.data.name === '组织管理' " src="../../../static/ldaplefticon/organization.png" style="margin-right: 5px">
        <img v-if="row.data.name === '功能管理' " src="../../../static/ldaplefticon/功能模块.png" style="margin-right: 5px">
        <img v-if="row.data.name === '部门管理'" src="../../../static/ldaplefticon/department1.png" style="margin-right: 5px">
        <img v-if="row.data.name === '角色管理'" src="../../../static/ldaplefticon/role1.png" style="margin-right: 5px">
        <img v-if="row.data.name === '人员管理'" src="../../../static/ldaplefticon/renyuan1.png" style="margin-right: 5px">
        <img v-if="row.data.name === '资源调配'" src="../../../static/ldaplefticon/renyuan1.png" style="margin-right: 5px">
        <!--节点名称-->
        <span v-if="isClick">{{row.data.name}}</span>
        <img v-if="row.data.haslicense && row.data.haslicense !== 'false'" src="../../../static/ldaplefticon/qx.png" style="margin:0 0 0 5px; height: 1em; width: 0.8em ">
      </span>
    </tree>
    </div>
  </div>
</template>

<script>
export default {
  props: ['functions', 'userid', 'isClick'],
  title: '左侧树菜单',
  data () {
    return {
      imgSrc: './static/treeset.png'
    }
  },
  ready(){

  },
  methods: {
    open (row) {
      if (row.data.name === '资源管理') {
        this.$parent.changeMain(row.data.id)
        return
      }
      if (this.$parent.routeName === 'main') {
        if (row.data.link) {
          this.$goto(row.data.link, {data: row.data, userid: this.userid}, 'main')
        }
      }else {
        if (row.data.resourcetype) {
          //为修改用户传值
          if(row.data.hasright){
            let parent = this.functions
            delete parent.children
            //针对于资源服务的组件来处理
            this.$goto(row.data.link, {data: row.data,parent: parent,userid: this.userid,compid:row.data.id}, 'resmain')
          }
        }
      }
    }
  },
  events: {
    'select-changed': function (data) {
      // 事件回调内的 `this` 自动绑定到注册它的实例上
      console.log('发生变化 树。。')
      this.open(data.val)
    },
    'toggle' () {
      this.$refs.resourcetree.$el.scrollLeft = this.$refs.resourcetree.$el.scrollWidth - this.$refs.resourcetree.$el.clientWidth
    }
  }
}
</script>
