Blame view

src/components/oa/chooseOrgTree.vue 2.29 KB
d4a6b78f   wuxw   OA 中考勤功能开发完成
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  <template>
    <el-dialog
      :title="$t('staffAttendance.chooseOrg')"
      :visible.sync="visible"
      width="60%"
      @close="handleClose"
    >
      <el-tree
        ref="orgTree"
        :data="orgs"
        node-key="id"
        :props="defaultProps"
        :highlight-current="true"
        @node-click="handleNodeClick"
      ></el-tree>
      
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{ $t('common.cancel') }}</el-button>
        <el-button type="primary" @click="handleConfirm">{{ $t('common.confirm') }}</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { getCommunityId } from '@/api/community/communityApi'
  import { listOrgTree } from '@/api/oa/staffAttendanceManageApi'
  
  export default {
    name: 'ChooseOrgTree',
    data() {
      return {
        visible: false,
        orgs: [],
        currentOrg: {},
        defaultProps: {
          children: 'children',
          label: 'name'
        }
      }
    },
    methods: {
      open() {
        this.visible = true
        this.loadOrgs()
      },
      
      async loadOrgs() {
        try {
          const params = {
            communityId: getCommunityId()
          }
          const { data } = await listOrgTree(params)
          this.orgs = data || []
        } catch (error) {
          console.error('Failed to load orgs:', error)
          this.$message.error(this.$t('staffAttendance.loadOrgFailed'))
        }
      },
      
      handleNodeClick(data) {
        this.currentOrg = data
      },
      
      handleConfirm() {
        if (!this.currentOrg || !this.currentOrg.id) {
          this.$message.warning(this.$t('staffAttendance.selectOrgFirst'))
          return
        }
        
        this.$emit('switchOrg', {
          orgId: this.currentOrg.id,
          allOrgName: this.getOrgFullName(this.currentOrg)
        })
        this.visible = false
      },
      
      getOrgFullName(node) {
        if (!node) return ''
        
        let names = []
        let currentNode = node
        
        while (currentNode) {
          names.unshift(currentNode.name)
          currentNode = this.$parent ? this.$parent.getNode(currentNode.parentId) : null
        }
        
        return names.join('/')
      },
      
      handleClose() {
        this.currentOrg = {}
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .el-tree {
    max-height: 500px;
    overflow-y: auto;
  }
  
  .dialog-footer {
    text-align: right;
  }
  </style>