MrShi
2025-04-11 3a45da15c947c2d478a44a51bd0f926647b1b841
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<template>
    <GlobalWindow
        :title="title"
        width="100%"
        :withFooter="false"
        :visible.sync="visible"
    >
      <TableLayout :permissions="['system:user:query']">
        <!-- 搜索表单 -->
        <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="80px" inline>
          <el-form-item label="姓名" prop="realname">
            <el-input v-model="searchForm.realname" 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>
          <ul class="toolbar" v-permissions="['system:user:create', 'system:user:delete']">
            <li v-permissions="['system:user:create']"><el-button type="primary" @click="$refs.operaUserWindow.open('新增账号',null,{company:company})">新增账号</el-button></li>
            <!--        <li v-permissions="['system:user:delete']"><el-button icon="el-icon-delete" @click="deleteByIdInBatch">删除</el-button></li>-->
          </ul>
          <!--      @selection-change="handleSelectionChange"-->
          <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="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
                v-if="containPermissions(['system:user:update', 'system:user:createUserRole', 'system:user:resetPwd', 'system:user:delete'])"
                label="操作"
                width="270"
                fixed="right"
            >
              <!--          row.id !== userInfo.id &&-->
              <template v-if="isAdmin || (row.roles.findIndex(r => r.code === adminCode) === -1)" slot-scope="{row}">
                <el-button type="text" icon="el-icon-edit" @click="$refs.operaUserWindow.open('编辑用户', row)" v-permissions="['system:user:update']">编辑</el-button>
                <el-button type="text" icon="el-icon-s-custom" @click="$refs.roleConfigWindow.open(row)" v-permissions="['system:user:createUserRole']">配置角色</el-button>
                <el-button type="text" @click="$refs.resetPwdWindow.open(row)" v-permissions="['system:user:resetPwd']">重置密码</el-button>
                <!--            <el-button v-if="!row.fixed" type="text" icon="el-icon-delete" @click="deleteById(row)" v-permissions="['system:user:delete']">删除</el-button>-->
              </template>
            </el-table-column>
          </el-table>
          <pagination
              @size-change="handleSizeChange"
              @current-change="handlePageChange"
              :pagination="tableData.pagination"
          ></pagination>
        </template>
        <!-- 新建/修改 -->
        <OperaUserWindow ref="operaUserWindow" @success="handlePageChange(tableData.pagination.pageIndex)"/>
        <!-- 配置角色 -->
        <RoleConfigWindow ref="roleConfigWindow" @success="handlePageChange(tableData.pagination.pageIndex)"/>
        <!-- 重置密码 -->
        <ResetPwdWindow ref="resetPwdWindow"/>
        <!--  分配企业  -->
        <allocationEnterprises ref="allocationEnterprises" @success="handlePageChange(tableData.pagination.pageIndex)"/>
      </TableLayout>
    </GlobalWindow>
</template>
 
<script>
import Pagination from '@/components/common/Pagination'
import TableLayout from '@/layouts/TableLayout'
import BaseTable from '@/components/base/BaseTable'
import GlobalWindow from '@/components/common/GlobalWindow'
import OperaUserWindow from '@/components/system/user/OperaUserWindow'
import allocationEnterprises from '@/components/system/user/allocationEnterprises'
import RoleConfigWindow from '@/components/system/user/RoleConfigWindow'
import ResetPwdWindow from '@/components/system/user/ResetPwdWindow'
import { updUserStatus } from '@/api/system/companyUser'
 
export default {
  name: 'OperaCompanyUserWindow',
  extends: BaseTable,
  components: { allocationEnterprises, ResetPwdWindow, RoleConfigWindow,GlobalWindow, OperaUserWindow, TableLayout, Pagination },
  data () {
    return {
      // 搜索
      visible:false,
      title:'用户管理',
      company:null,
      searchForm: {
        username: '', // 名字
        realname: '', // 姓名
        companyId: null, // 部门ID
        mobile: '' // 手机号码
      }
    }
  },
  created () {
  },
  methods: {
    open(title, row){
      this.config({
        module: '用户',
        api: '/system/companyUser',
        'field.main': 'realname',
        sorts: [{
          property: 'CREATE_TIME',
          direction: 'DESC'
        }]
      })
      this.company=row
      this.title = title
      this.visible = true
      this.searchForm.companyId=row.id
      this.search()
    },
    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>