organTree.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. children: 'children',
  30. label: 'name'
  31. }
  32. };
  33. },
  34. watch: {
  35. filterText(val) {
  36. this.$refs.tree.filter(val);
  37. }
  38. },
  39. methods: {
  40. getOrgTreeList() {
  41. this.$http.get('/sc-community/assets/tree/community/find').then(({ status, data, msg }) => {
  42. if (status === 0 && data) {
  43. this.dimension(data);
  44. this.organList = data;
  45. this.$nextTick().then(() => {
  46. const firstNode = document.querySelector('.el-tree-node');
  47. firstNode.click();
  48. });
  49. }
  50. });
  51. },
  52. dimension(arr) {
  53. arr.map((item, index) => {
  54. if (!!item.children & (item.type !== 'unit')) {
  55. this.dimension(item.children);
  56. } else {
  57. if (item.name.indexOf('单元') === -1) {
  58. item.name = item.name + '单元';
  59. }
  60. }
  61. });
  62. },
  63. filterNode(value, data) {
  64. if (!value) return true;
  65. return data.name.indexOf(value) !== -1;
  66. },
  67. treeClick(e) {
  68. // let unitPa = {};
  69. // if (e.value == 0) return;
  70. // debugger;
  71. // if (e.type == 'unit') {
  72. // let parentV = this.$refs.tree.getNode(e).parent.data;
  73. // unitPa = {
  74. // parentValue: parentV.value,
  75. // type: e.type,
  76. // value: e.value
  77. // };
  78. // this.$emit('organId', unitPa);
  79. // } else {
  80. // this.$emit('organId', e);
  81. // }
  82. let unitPa = {
  83. communityId: '',
  84. buildingId: '',
  85. unitId: '',
  86. roomId: '',
  87. type: '',
  88. name: ''
  89. };
  90. if (e.type == 'building') {
  91. unitPa.communityId = this.$refs.tree.getNode(e).parent.data.value;
  92. unitPa.buildingId = e.value;
  93. unitPa.type = e.type;
  94. unitPa.name = e.name;
  95. } else if (e.type == 'unit') {
  96. unitPa.communityId = this.$refs.tree.getNode(e).parent.parent.data.value;
  97. unitPa.buildingId = this.$refs.tree.getNode(e).parent.data.value;
  98. unitPa.unitId = e.value;
  99. unitPa.type = e.type;
  100. unitPa.name = this.$refs.tree.getNode(e).parent.data.name + ' ' + e.name;
  101. } else if (e.type == 'room') {
  102. unitPa.communityId = this.$refs.tree.getNode(e).parent.parent.parent.data.value;
  103. unitPa.buildingId = this.$refs.tree.getNode(e).parent.parent.data.value;
  104. unitPa.unitId = this.$refs.tree.getNode(e).parent.data.value;
  105. unitPa.roomId = e.value;
  106. unitPa.type = e.type;
  107. unitPa.name =
  108. this.$refs.tree.getNode(e).parent.parent.data.name + ' ' + this.$refs.tree.getNode(e).parent.data.name + ' ' + e.name;
  109. } else {
  110. unitPa = e;
  111. }
  112. this.$emit('organId', unitPa);
  113. }
  114. },
  115. created() {
  116. this.getOrgTreeList();
  117. }
  118. };
  119. </script>
  120. <style lang="scss" scoped>
  121. .organ-tree {
  122. width: 260px;
  123. background: #ffffff;
  124. padding: 20px;
  125. box-sizing: border-box;
  126. float: left;
  127. height: 100%;
  128. overflow: auto;
  129. &::before {
  130. clear: both;
  131. }
  132. .tree-style-box {
  133. margin-top: 20px;
  134. max-height: calc(100vh - 200px);
  135. overflow: scroll;
  136. }
  137. }
  138. </style>