干燥机配套车间生产管理系统/云平台服务端
baoshiwei
2023-03-10 1fb197352b6a263646e4ccd3ed1c7854ede031dd
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<template>
  <a-row>
    <a-col :span="12">
      <div :style="containerStyle">
        <a-tree v-if="treeData.length > 0" showIcon :treeData="treeData" :selectedKeys="selectedKeys" @select="onSelect"> </a-tree>
      </div>
    </a-col>
    <a-col :span="12" style="padding-left: 10px">
      <div :style="containerStyle">
        <user-list :excludeUserIdList="excludeUserIdList" :dataList="userDataList" :selectedIdList="selectedIdList" @selected="onSelectUser" @unSelect="unSelectUser" />
      </div>
    </a-col>
  </a-row>
</template>
 
<script lang="ts">
  import { computed, ref, watch } from 'vue';
  import { defHttp } from '/@/utils/http/axios';
  import UserList from './UserList.vue';
 
  export default {
    name: 'RoleUserList',
    components: {
      UserList,
    },
    props: {
      searchText: {
        type: String,
        default: '',
      },
      selectedIdList: {
        type: Array,
        default: () => [],
      },
      excludeUserIdList:{
        type: Array,
        default: () => [],
      }
    },
    emits: ['selected', 'unSelect'],
    setup(props, { emit }) {
      const treeData = ref<any[]>([]);
      async function loadRoleList() {
        const url = '/sys/role/listByTenant';
        let params = {
          order: 'desc',
          column: 'createTime',
          pageSize: 200,
        };
        let arr = [];
        const data = await defHttp.get({ url, params }, { isTransformResponse: false });
        if (data.success) {
          const { records } = data.result;
          arr = records.map((k) => {
            return {
              title: k.roleName,
              id: k.id,
              key: k.id,
            };
          });
        }
        console.log('loadRoleList', data);
        treeData.value = arr;
      }
      loadRoleList();
 
      const selectedKeys = ref<any[]>([]);
      const selectedRoleId = ref('');
      function onSelect(ids, e) {
        let record = e.node.dataRef;
        selectedKeys.value = [record.key];
 
        let id = ids[0];
        selectedRoleId.value = id;
        loadUserList();
      }
 
      const userDataList = ref<any[]>([]);
      async function loadUserList() {
        const url = '/sys/user/selectUserList';
        let params = {
          pageNo: 1,
          pageSize: 10,
        };
        if (props.searchText) {
          params['keyword'] = props.searchText;
        }
        if (selectedRoleId.value) {
          params['roleId'] = selectedRoleId.value;
        }
        const data = await defHttp.get({ url, params }, { isTransformResponse: false });
        if (data.success) {
          const { records } = data.result;
          userDataList.value = records;
        } else {
          console.error(data.message);
        }
        console.log('role-loadUserList', data);
      }
      watch(
        () => props.searchText,
        () => {
          loadUserList();
        }
      );
 
      function onSelectUser(info) {
        emit('selected', info);
      }
      function unSelectUser(id) {
        emit('unSelect', id);
      }
 
      const maxHeight = ref(300);
      maxHeight.value = window.innerHeight - 300;
      const containerStyle = computed(() => {
        return {
          'overflow-y': 'auto',
          'max-height': maxHeight.value + 'px',
        };
      });
 
      return {
        containerStyle,
        treeData,
        selectedKeys,
        onSelect,
        onSelectUser,
        unSelectUser,
        userDataList,
      };
    },
  };
</script>
 
<style scoped></style>