liuxiaolong
2019-05-06 2418a2d61feea858e9e63aa52fd64ddfe17e392a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<template>
  <div
    id="tree-container"
    class="clearfix"
    style="padding: 8px;"
  >
    <div class="d-flex py-2">
      <b-input
        autocomplete="off"
        v-model="searchValue"
        placeholder="输入机构名称"
        @change.native="handleSearch"
        class="mr10"
      />
      <b-button variant="primary" class="pl-4 pr-4" @click="handleSearch">搜索</b-button>
      <b-button variant="link" class="tree-btn" @click="$emit('toggleOpen')">
        <i class="ion ion-md-swap f20"></i>
      </b-button>
 
    </div>
      <hr class="m-0 mt-2 mb-1" />
      <!-- style="background: rgb(243, 243, 243) bg-white" -->
      <div class="flex-box">
        <h5 class="py-2 mb-0">组织架构</h5>
        <b-button variant="link" class="p-0 pl-2 pr-2">
          <i class="far fa-edit f18 text-primary"></i>
        </b-button>
      </div>
      <div class="overflow-auto pb-2 px-2  bg-" style="height:38vh">
        <Tree
          :data="data"
          :props="option"
          :default-expand-all="isOpenAll"
          @node-click="handleNodeClick"
          highlight-current
          id="tree"
          ref="tree2"
          node-key="id"
          :filter-node-method="filterNode"
          class="float-left"
          style="width: 100%"
        />
      </div>
  </div>
</template>
 
<script>
import { Tree } from 'element-ui'
export default {
  data: () => ({
    searchValue: ''
  }),
  props: {
    data: {
      type: Array,
      default: () => [],
      required: true
    },
    option: {
      type: Object,
      default: () => ({
        children: 'child',
        label: 'name'
      })
    },
    isOpenAll: {
      default: true,
      type: Boolean
    }
  },
  methods: {
    handleNodeClick(node) {
      this.$emit('currentNode', node)
    },
    // * 设置选中状态
    setCurrentKey(id) {
      this.$nextTick(() => {
        this.$refs.tree2.setCurrentKey(id)
      })
    },
    // 清空选中状态
    removeCurrentNode() {
      this.$refs.tree2.setCurrentKey(null)
    },
    // * 过滤
    handleSearch() {
      this.$refs.tree2.filter(this.searchValue)
    },
    // * 过滤
    filterNode(value, data) {
      if (!value) return true
      return data.name.indexOf(value) !== -1
    },
    // * 获取被选中节点
    getCurrentNode() {
      return this.$refs.tree2.getCurrentNode()
    }
  },
  components: {
    Tree
  }
}
</script>
 
<style lang="scss" >
#tree-container .el-tree {
  overflow: auto;
}
 
#tree-container .el-tree-node > .el-tree-node__children {
  overflow: visible;
}
.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
  // background: rgb(38, 180, 255);
  // color: #fff;
  color: #35bde7;
  position: relative;
  border-radius: 5px;
  overflow: hidden;
  .el-tree-node__expand-icon {
    color: #35bde7;
  }
  .el-tree-node__expand-icon.is-leaf {
    color: transparent;
    cursor: default;
  }
}
.el-tree-node__content:hover {
  border-radius: 5px;
  overflow: hidden;
}
.tree-btn{
  padding:6px 8px;
}
 
/* .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content:after{
  content:'';
  display: block;
  position: absolute;
  width: 100%;
  height: 100%;
  right: 100%;
  background: rgb(38, 180, 255);
}
.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content .el-tree-node__label{
  position: relative;
  z-index: 9;
} */
</style>