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
108
<template>
  <a-spin :spinning="spinning">
    <a-transfer
      class="transfer-container"
      :data-source="dataSource"
      show-search
      :list-style="{flex:1,height: '500px'}"
      :titles="['未分配用户', '已分配用户']"
      :operations="['分配用户', '移除用户']"
      :target-keys="targetKeys"
      :render="item => `${item.realname}`"
      @change="handleChange"
      :rowKey="record => record.id"
    >
      <span slot="notFoundContent">暂无数据</span>
    </a-transfer>
  </a-spin>
</template>
 
<script>
  import dncApi from '@/api/dnc'
 
  export default {
    name: 'UserPermissionTransfer',
    components: {},
    props: {
      currentTreeNodeInfo: {
        type: Object
      },
      dataSource: {
        type: Array
      },
      isAssignSonNode: {
        type: Boolean
      }
    },
    data() {
      return {
        targetKeys: [],
        spinning: false
      }
    },
    methods: {
      getHasPermissionUserByApi() {
        const that = this
        that.spinning = true
        dncApi.getHasPermissionUserApi(this.currentTreeNodeInfo)
          .then(res => {
            if (res.success) this.targetKeys = res.list.map(item => item.id)
          })
          .finally(() => {
            that.spinning = false
          })
      },
 
      handleChange(targetKeys, direction, moveKeys) {
        const { currentTreeNodeInfo: { type, id }, isAssignSonNode, $notification, dataSource } = this
        const that = this
        let method
        const params = {
          treeNodeType: type,
          treeNodeId: id,
          isAssignSonNode: isAssignSonNode ? 1 : 2,
          userIdArray: moveKeys
        }
        console.log('params--------------------------', params)
        console.log(targetKeys, direction, moveKeys)
        if (direction === 'right') {
          method = dncApi.assignPermissionToUser
        } else {
          method = dncApi.removePermissionFromUser
        }
        that.spinning = true
        method(params)
          .then(res => {
            if (res.success) {
              $notification.success({
                message: '消息',
                description: res.message
              })
              this.targetKeys = targetKeys
            } else {
              $notification.error({
                message: '消息',
                description: res.message
              })
            }
          })
          .catch(err => {
            $notification.error({
              message: '消息',
              description: err.message
            })
          })
          .finally(() => {
            that.spinning = false
          })
      }
    }
  }
</script>
 
<style scoped lang="less">
  .transfer-container {
    display: flex;
    align-items: center;
  }
</style>