Blame view

src/components/resource/CommunityMachineTypeTree.vue 1.51 KB
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
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
  <template>
    <div class="tree-container">
      <el-card class="box-card">
        <el-tree
          ref="machineTypeTree"
          :data="treeData"
          node-key="id"
          :props="defaultProps"
          :highlight-current="true"
          :expand-on-click-node="false"
          @node-click="handleNodeClick"
        />
      </el-card>
    </div>
  </template>
  
  <script>
  import { queryCommunityMachineTypeTree } from '@/api/resource/adminEquipmentApi'
  
  export default {
    name: 'CommunityMachineTypeTree',
    data() {
      return {
        treeData: [],
        defaultProps: {
          children: 'children',
          label: 'text'
        },
        callName: ''
      }
    },
    mounted() {
      this.initTree()
    },
    methods: {
      async initTree() {
        await this.loadCommunityMachineTypes()
      },
      async loadCommunityMachineTypes() {
        try {
          const { data } = await queryCommunityMachineTypeTree()
          this.treeData = data
        } catch (error) {
          console.error('Failed to load machine types:', error)
        }
      },
      handleNodeClick(data, node) {
        console.log(node)
        if (data.id.startsWith('c_')) {
          this.$emit('selectMachineType', {
            communityId: data.communityId,
            typeId: ''
          })
        } else if (data.id.startsWith('m_')) {
          this.$emit('selectMachineType', {
            communityId: data.communityId,
            typeId: data.typeId
          })
        }
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .tree-container {
    height: 100%;
  
    .box-card {
      height: 100%;
    }
  }
  </style>