index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div class="page-container">
  3. <div class="left-panel">
  4. <el-input v-model="filterText" size="default" placeholder="搜索区域" />
  5. <el-tree
  6. :data="treeList"
  7. node-key="id"
  8. default-expand-all
  9. :props="{
  10. children: 'children'
  11. }"
  12. @node-click="onNodeClick"
  13. :expand-on-click-node="false"
  14. >
  15. <template #default="{ node, data }">
  16. <span class="custom-tree-node" :class="{ active: data.id === curNode.id }">
  17. <span>{{ data.orgName }}</span>
  18. </span>
  19. </template>
  20. </el-tree>
  21. </div>
  22. <div class="right-panel">
  23. <!-- 小区 -->
  24. <Regional v-if="curNode.orgType === 'org'" :organizationId="curNode.id"/>
  25. <!-- 楼宇 -->
  26. <Floor v-else-if="curNode.orgType === 'plot'" :organizationId="curNode.organizationId" :plotId="curNode.id"/>
  27. <!-- 单元 -->
  28. <Unit v-else-if="curNode.orgType === 'floor'" :organizationId="curNode.organizationId" :floorId="curNode.id"/>
  29. <!-- 住户 -->
  30. <Resident v-else-if="curNode.orgType === 'unit'" :organizationId="curNode.organizationId" :plotId="curNode.id"/>
  31. </div>
  32. </div>
  33. </template>
  34. <script lang="ts">
  35. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  36. import api from '/@/api/heatingDistrict';
  37. import Regional from './children/regional/index.vue'
  38. import Floor from './children/floor/index.vue'
  39. import Unit from './children/unit/index.vue'
  40. import Resident from './children/resident/index.vue'
  41. export default defineComponent({
  42. name: '',
  43. components: {
  44. Regional,
  45. Floor,
  46. Unit,
  47. Resident
  48. },
  49. setup() {
  50. const treeList = ref([])
  51. const state = reactive({
  52. filterText: '',
  53. curNode: {}
  54. });
  55. // 获取区域树
  56. const getTreeData = () => {
  57. api.heatingDistrict.getTree({})
  58. .then((res: any) => {
  59. treeList.value = res || []
  60. state.curNode = treeList.value[0]
  61. })
  62. }
  63. const onNodeClick = (data: any, node: any) => {
  64. console.log(data)
  65. state.curNode = data
  66. // console.log(node)
  67. }
  68. // 页面加载时
  69. onMounted(() => {
  70. getTreeData()
  71. });
  72. return {
  73. treeList,
  74. onNodeClick,
  75. ...toRefs(state),
  76. };
  77. },
  78. });
  79. </script>
  80. <style lang="scss" scoped>
  81. .page-container {
  82. display: grid;
  83. grid-template-columns: 250px 1fr;
  84. background-color: #fff;
  85. border: 1px solid #ddd;
  86. .left-panel {
  87. padding: 20px;
  88. }
  89. .right-panel {
  90. display: flex;
  91. flex-direction: column;
  92. padding: 20px;
  93. border-left: 1px solid #ddd;
  94. }
  95. }
  96. .custom-tree-node {
  97. &.active {
  98. color: var(--el-color-primary);
  99. // background: var(--el-color-primary-light-9);
  100. }
  101. }
  102. </style>