MrShi
2024-11-11 0da56b9186b6c63a587c36c2f3a1b30329281d28
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
137
138
139
140
141
<template>
    <TableLayout :permissions="['system:user:query']">
        <!-- 搜索表单 -->
        <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="80px" inline>
            <el-form-item label="账号" prop="username">
                <el-input v-model="searchForm.username" v-trim placeholder="请输入" @keypress.enter.native="search"/>
            </el-form-item>
            <el-form-item label="姓名" prop="realname">
                <el-input v-model="searchForm.realname" v-trim placeholder="请输入" @keypress.enter.native="search"/>
            </el-form-item>
            <el-form-item label="联系方式" prop="mobile">
                <el-input v-model="searchForm.mobile" v-trim placeholder="请输入" @keypress.enter.native="search"/>
            </el-form-item>
            <el-form-item label="企业名称" prop="companyName">
                <el-input v-model="searchForm.companyName" v-trim placeholder="请输入" @keypress.enter.native="search"/>
            </el-form-item>
            <section>
                <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
                <el-button @click="reset">重置</el-button>
            </section>
        </el-form>
        <!-- 表格和分页 -->
        <template v-slot:table-wrap>
            <el-table
                v-loading="isWorking.search"
                :data="tableData.list"
                :default-sort = "{prop: 'createTime', order: 'descending'}"
                stripe
                @sort-change="handleSortChange"
            >
                <el-table-column label="序号" width="80px">
                    <template slot-scope="scope">
                        <span>{{scope.$index + 1}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="username" label="账号" min-width="120px"></el-table-column>
                <el-table-column prop="realname" label="姓名" min-width="100px"></el-table-column>
                <el-table-column prop="mobile" label="联系方式" min-width="100px"></el-table-column>
                <el-table-column prop="companyDepartmentPathName" label="归属公司" min-width="100px"></el-table-column>
                <el-table-column label="授权企业" min-width="100px">
                    <template slot-scope="{row}">
                        <span>{{row.authNum}}家</span>
                    </template>
                </el-table-column>
                <el-table-column prop="roles" label="角色" min-width="160px" class-name="table-column-strings">
                    <template slot-scope="{row}">
                        <ul>
                            <li v-for="role in row.roles" :key="role.id">{{role.name}}</li>
                        </ul>
                    </template>
                </el-table-column>
                <el-table-column label="启用状态" min-width="100px">
                    <template slot-scope="{row}">
                        <el-switch
                            v-if="!row.fixed"
                            @change="changeStatus($event, row)"
                            v-model="row.status"
                            active-color="#13ce66"
                            inactive-color="#ff4949"
                            :active-value="0"
                            :inactive-value="1">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column
                    label="操作"
                    width="100"
                    fixed="right"
                >
                    <template slot-scope="{row}">
                        <el-button type="text" @click="$refs.authorizedEnterprise.open('授权企业记录', row.id)">授权企业</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination
                @size-change="handleSizeChange"
                @current-change="handlePageChange"
                :pagination="tableData.pagination"
            ></pagination>
        </template>
        <authorizedEnterprise ref="authorizedEnterprise" />
    </TableLayout>
</template>
 
<script>
  import Pagination from '@/components/common/Pagination'
  import TableLayout from '@/layouts/TableLayout'
  import BaseTable from '@/components/base/BaseTable'
  import { updUserStatus } from '@/api/system/user'
  import authorizedEnterprise from '@/components/business/authorizedEnterprise'
  export default {
    name: 'userManagement',
    extends: BaseTable,
    components: { TableLayout, Pagination, authorizedEnterprise },
    data () {
      return {
        // 搜索
        searchForm: {
          username: '',
          realname: '',
          mobile: '',
          companyName: ''
        }
      }
    },
    created () {
      this.config({
        module: '用户',
        api: '/system/user',
        'field.main': 'realname',
        sorts: [{
          property: 'CREATE_TIME',
          direction: 'DESC'
        }]
      })
      this.search()
    },
    methods: {
      changeStatus(status, row) {
        updUserStatus({
          id: row.id,
          status
        }).then(res => {
          this.search()
        }).catch(err => {
          row.status = row.status === 0 ? 1 : 0
        })
      }
    }
  }
</script>
 
<style scoped lang="scss">
    @import "@/assets/style/variables.scss";
    // 列表头像处理
    .table-column-avatar {
        img {
            width: 48px;
        }
    }
</style>