projectItemTree.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div class="hui-left-tree">
  3. <div class="hui-left-tree-title">
  4. <svg-icon name="zhuangshi" width="16" height="20"></svg-icon>
  5. <span class="hui-left-tree-sub">{{title}}</span>
  6. </div>
  7. <div class="hui-left-tree-content">
  8. <el-collapse>
  9. <el-collapse-item v-for="item in treeData" :key="item.id">
  10. <template slot="title">
  11. <i class="iconfont huifont-shuzhuangcaidantubiao"></i>
  12. <span class="el-collapse-name">{{item.name}}</span>
  13. </template>
  14. <div>
  15. <el-tree :data="item.projectItemTargetList" :props="defaultProps">
  16. <div class="custom-tree-node" slot-scope="{ node, data }">
  17. <div class="label">{{node.label}}</div>
  18. <div :class="nowData.id === data.id ? 'active':''" @click.stop="nodeClick(data)"
  19. v-if="hasRoom ? data.roomId : true">
  20. <i :class="iconfontClass"></i>
  21. </div>
  22. </div>
  23. </el-tree>
  24. </div>
  25. </el-collapse-item>
  26. </el-collapse>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import {
  32. getHouseTree,
  33. } from '@/httpApi/space'
  34. import {
  35. roomList
  36. } from '@/uitls'
  37. export default {
  38. props: {
  39. title: {
  40. type: String,
  41. default: '空间列表'
  42. },
  43. iconfontClass: {
  44. type: String,
  45. default: 'iconfont huifont-shexiangtou'
  46. },
  47. type: {
  48. type: String,
  49. default: ''
  50. },
  51. hasRoom: {
  52. type: Boolean,
  53. default: false
  54. },
  55. isCancel: {
  56. type: Boolean,
  57. default: true
  58. }
  59. },
  60. data() {
  61. return {
  62. treeData: [],
  63. defaultProps: {
  64. children: 'children',
  65. label: 'name'
  66. },
  67. nowData: {}
  68. }
  69. },
  70. mounted() {
  71. this.init();
  72. },
  73. methods: {
  74. init() {
  75. getHouseTree(this.$store.getters.project.id).then(res => {
  76. if (res.state) {
  77. if (!this.hasRoom) {
  78. this.defaultProps['label'] = 'name';
  79. this.treeData = res.data.projectItemList.map(node => {
  80. node.projectItemTargetList = node.projectItemTargetList.map(target => {
  81. target['bimIntegrateId'] = node.bimIntegrateId;
  82. target['projectItemName'] = node.name;
  83. if (this.type === 'isInit' && !this.nowData.id) {
  84. this.nodeClick(target, 'isInit');
  85. }
  86. return target;
  87. })
  88. return node;
  89. });
  90. if (this.treeData.length === 0) this.nodeClick({}, 'isInit');
  91. } else {
  92. this.defaultProps['label'] = 'optionName';
  93. this.treeData = roomList(res.data.projectItemList || []);
  94. let roomData = [];
  95. for (let i = 0; i < this.treeData.length; i++) {
  96. if (this.treeData[i].projectItemTargetList) {
  97. for (let k = 0; k < this.treeData[i].projectItemTargetList.length; k++) {
  98. if (this.treeData[i].projectItemTargetList[k].projectItemTargetRoomList) {
  99. roomData = roomData.concat(this.treeData[i].projectItemTargetList[k]
  100. .projectItemTargetRoomList);
  101. }
  102. }
  103. }
  104. }
  105. if (this.type === 'isInit' && !this.nowData.id) this.nodeClick(roomData[0], 'isInit');
  106. }
  107. }
  108. })
  109. },
  110. nodeClick(item, type) {
  111. if (this.isCancel) {
  112. this.nowData = this.nowData.id === item.id ? {} : item;
  113. this.$emit('treeclick', this.nowData, type);
  114. } else {
  115. if (this.nowData.id === item.id) return;
  116. this.nowData = item;
  117. this.$emit('treeclick', this.nowData, type);
  118. }
  119. }
  120. }
  121. }
  122. </script>
  123. <style></style>