communityTree.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <div class="organ-tree">
  3. <el-input v-model="filterText" placeholder="请输入关键字" suffix-icon="el-icon-search"></el-input>
  4. <div class="tree-style-box no-scrollbar">
  5. <el-tree
  6. class="tree-style"
  7. :data="organList"
  8. ref="tree"
  9. node-key="id"
  10. :highlight-current="true"
  11. :props="defaultProps"
  12. :expand-on-click-node="false"
  13. @node-click="treeClick"
  14. default-expand-all
  15. :filter-node-method="filterNode"
  16. >
  17. </el-tree>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'organTree',
  24. data() {
  25. return {
  26. filterText: '',
  27. organList: [],
  28. defaultProps: {
  29. label: 'communityName'
  30. }
  31. };
  32. },
  33. watch: {
  34. filterText(val) {
  35. this.$refs.tree.filter(val);
  36. }
  37. },
  38. methods: {
  39. getOrgTreeList() {
  40. this.$http.get('/sc-community-web/assets/community/list').then(({ status, data, msg }) => {
  41. if (status === 0 && data) {
  42. this.organList = data;
  43. this.$nextTick().then(() => {
  44. const firstNode = document.querySelector('.el-tree-node');
  45. firstNode.click();
  46. });
  47. }
  48. });
  49. },
  50. filterNode(value, data) {
  51. if (!value) return true;
  52. return data.communityName.indexOf(value) !== -1;
  53. },
  54. treeClick(e) {
  55. this.$emit('organId', e.id);
  56. }
  57. },
  58. created() {
  59. this.getOrgTreeList();
  60. }
  61. };
  62. </script>
  63. <style lang="scss" scoped>
  64. .organ-tree {
  65. width: 260px;
  66. background: #ffffff;
  67. padding: 20px;
  68. box-sizing: border-box;
  69. float: left;
  70. height: 100%;
  71. overflow: auto;
  72. &::before {
  73. clear: both;
  74. }
  75. .tree-style-box {
  76. margin-top: 20px;
  77. max-height: calc(100vh - 200px);
  78. overflow: scroll;
  79. }
  80. }
  81. </style>