Blame view

src/components/NCC-userBox/index.vue 2.52 KB
be009217   monkeyhouyi   处理,通知公告,任务中心
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
  <template>
    <el-dialog :title="'选择'+title" :close-on-click-modal="false" :visible.sync="visible"
      class="NCC-dialog NCC-dialog_center NCC-dialog-tree" lock-scroll append-to-body
      width='450px'>
      <el-input placeholder="输入姓名或者编号进行过滤" v-model="keyword" clearable @keyup.enter.native="getList">
        <el-button slot="append" icon="el-icon-search" @click="getList"></el-button>
      </el-input>
      <el-tree :data="treeData" :props="props" highlight-current :expand-on-click-node="false"
        check-on-click-node @node-click="handleNodeClick" class="NCC-common-el-tree" node-key="id"
        v-loading="loading" lazy :load="loadNode">
        <span class="custom-tree-node" slot-scope="{ node, data }">
          <i :class="data.icon"></i>
          <span class="text">{{node.label}}</span>
        </span>
      </el-tree>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{$t('common.cancelButton')}}</el-button>
        <el-button type="primary" @click="dataFormSubmit()">{{$t('common.confirmButton')}}</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { getImUserSelector } from '@/api/permission/user'
  export default {
    name: 'UserBox',
    props: {
      title: {
        type: String,
        default: '审批人'
      }
    },
    data() {
      return {
        visible: false,
        id: '',
        nodeId: '0',
        props: {
          children: 'children',
          label: 'fullName',
          value: 'id',
          isLeaf: 'isLeaf'
        },
        treeData: [],
        loading: false,
        keyword: ''
      }
    },
    methods: {
      init() {
        this.visible = true
        this.keyword = ''
        this.nodeId = '0'
        this.getList()
      },
      getList() {
        this.loading = true
        if (this.keyword) this.nodeId = '0'
        getImUserSelector(this.nodeId, this.keyword).then(res => {
          this.treeData = res.data.list
          this.loading = false
        })
      },
      loadNode(node, resolve) {
        if (node.level === 0) {
          this.nodeId = '0'
          return resolve(this.treeData)
        }
        this.nodeId = node.data.id
        getImUserSelector(this.nodeId).then(res => {
          resolve(res.data.list)
        })
      },
      handleNodeClick(data) {
        if (data.type !== 'user') return
        this.id = data.id
      },
      dataFormSubmit() {
        if (!this.id) {
          this.$message({
            message: `请选择${this.title}`,
            type: 'error',
            duration: 1000,
          })
          return
        }
        this.visible = false
        this.$emit('submit', this.id)
      },
    }
  }
  </script>