luobisheng
2022-12-09 8561be6f266768316a7866a71d891000e758db32
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<template>
    <div class="mainContent">
      <!-- <div class="aside">
        <department-aside />
      </div> -->
      <div class="grid-content">
        <!-- 数据展示 -->
        <el-table ref="multipleTable"
                  :header-cell-style="{background:'#06122c','font-size':'12px',color:'#4b9bb7','font-weight':'650','line-height':'45px'}"
                  :data="tableData" style="width: 100%" :row-class-name="tableRowClassName"
                  @selection-change="tableChange">
          <el-table-column type="selection" min-width="5">
          </el-table-column>
          <el-table-column label="用户ID" min-width="6">
            <template slot-scope="scope">{{ scope.row.id }}</template>
          </el-table-column>
          <el-table-column prop="nickName" label="用户名称" min-width="10">
          </el-table-column>
          <el-table-column prop="username" label="所属姓名" min-width="8">
          </el-table-column>
          <el-table-column prop="mobile" label="联系方式" min-width="7">
          </el-table-column>
          <el-table-column prop="note" label="所属角色" min-width="8">
            <template slot-scope="scope">
              <span>{{filterRole(scope.row.roles)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="jobTitle" label="所属职务" min-width="8">
          </el-table-column>
          <el-table-column prop="createTime" label="创建时间" min-width="10">
            <template slot-scope="scope">
              <span>{{changeTime(scope.row)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="启用" min-width="5">
            <template slot-scope="scope">
              <!-- @change="handleChangeStatus(scope.row)" -->
              <el-switch class="switchStyle" v-model="scope.row.status"
                         active-color="#3fef9a" inactive-color="#000212" disabled>
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column prop="operation" label="操作" min-width="20">
          </el-table-column>
        </el-table>
        <!-- 查看页面 -->
        <el-dialog :visible.sync="dialogView" width="45%" v-if="dialogView"
                   title="查看用户信息">
          <MyView :userInfo=userInfo></MyView>
        </el-dialog>
        <!-- 修改页面 -->
        <el-dialog :visible.sync="dialogUpdate" width="45%" v-if="dialogUpdate"
                   :title="updateFlag ? flag.role ? '修改用户角色信息' : flag.depart ? '修改用户部门信息': '修改用户密码' :''"
                   :before-close="handleClose">
          <updateUser :updateFlag="updateFlag" :userInfo=userInfo :flag=flag @closeDialog="closeDialog"
                      :getUserList="getUserList" v-if="!flag.password" />
          <MyPwd v-else :userInfo=userInfo @closeDialog="closeDialog"></MyPwd>
        </el-dialog>
        <!-- tools -->
        <div class="tools">
          <div class="funs">
              <el-checkbox v-model="all" @change="selectAll()">全选</el-checkbox>
              <el-checkbox v-model="unsame" @change="disSame(tableData)">反选</el-checkbox>
              <el-select v-model="myIdx" placeholder="批量操作" @change="selectChange">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"
                           :disabled="item.disabled">
                </el-option>
              </el-select>
          </div>
          <el-pagination class="pagination" background :current-page="currentPage" layout="prev, pager, next" :total="totalNum"
                         :page-size="pageSize" @current-change="changeCurrentPage" @prev-click="handlePrev"
                         @next-click="handleNext">
          </el-pagination>
        </div>
      </div>
    </div>
</template>
<script>
import helper from '@/utils/mydate'
import departmentAside from "@/views/operate/fivepack/threepack/components/aside";
export default {
    components: { departmentAside },
    data() {
        return {
            tableData: [],
            search: "",
            dialogUpdate: false,
            dialogView:false,
            updateFlag: false,
            userInfo: '',
            totalNum: 0,
            pageSize: 10,
            currentPage: 1,
            renderFlag: false,
            flag: {
                role: false,
                password: false,
                depart: false,
            },
            all: false,
            unsame: false,
            myIdx: 0,
            preMyIdx: 0,
            options: [
                {
                    value: 0,
                    label: '批量操作',
                    disabled: true,
                },
                {
                    value: 1,
                    label: '批量启用',
                },
                {
                    value: 2,
                    label: '批量禁用',
                },
                {
                    value: 3,
                    label: '批量删除',
                }
            ],
            tempList: []
        }
    },
    created() {
        this.getUserList();
    },
    methods: {
        async selectChange(list) {
            if (this.tempList.length !== 0) {
                this.preMyIdx = list;
                if (list === 3) {
                    await this.mulDelte(this.tempList);
                } else if (list === 2) {
                    await this.mulUpdateStatus(this.tempList, 0);
                } else {
                    await this.mulUpdateStatus(this.tempList, 1);
                }
                this.myIdx = 0;
            } else {
                this.myIdx = this.preMyIdx;
                this.$message({
                    type: 'warning',
                    message: '您还没选中任何数据',
                })
            }
        },
        tableChange(list) {
            this.tempList = [];
            list.forEach(item => {
                this.tempList.push(item.id);
            })
            this.all = list.length === this.tableData.length;
        },
        // 批量删除用户信息
        mulDelte(idArr) {
            this.$confirm("您确定要进行批量删除用户吗?")
                .then(_ => {
                    this.$axios({
                        method: 'post',
                        url: 'sccg/admin/deleteBatch?ids=' + idArr,
                    })
                        .then(res => {
                            if (res.code === 200) {
                                this.$message({
                                    type: 'success',
                                    message: '删除用户信息成功',
                                })
                                this.getUserList();
                            } else {
                                this.$message({
                                    type: 'error',
                                    message: res.message
                                })
                            }
                        })
                })
                .catch(err => {  })
        },
        // 批量修改账号
        mulUpdateStatus(idArr, flag) {
            this.$confirm(flag === 1 ? "您确定要进行批量启用用户吗?" : '您确定要进行批量禁用用户吗?')
                .then(_ => {
                    this.$axios({
                        method: 'post',
                        url: 'sccg/admin/updateStatusBatch?ids=' + idArr + '&status=' + flag,
                    })
                        .then(res => {
                            if (res.code === 200) {
                                this.$message({
                                    type: 'success',
                                    message: '更改用户状态成功',
                                })
                                this.getUserList();
                            } else {
                                this.$message({
                                    type: 'error',
                                    message: res.message
                                })
                            }
                        })
                })
                .catch(err => {  })
        },
        changeTime({ createTime }) {
            return helper(createTime);
        },
        selectAll() {
            this.$refs.multipleTable.toggleAllSelection();
        },
        disSame(list) {
            list.forEach(row => {
                this.$refs.multipleTable.toggleRowSelection(row)
            })
        },
        // 删除用户
        handleDelete({ id }) {
            this.$confirm('确认删除?').then(_ => {
                this.$axios({
                    method: 'post',
                    url: 'sccg/admin/delete/' + id,
                }).then(res => {
                    this.$message({
                        message: res.message,
                        type: 'success'
                    })
                    this.getUserList();
                })
            }).catch(_ => { })
        },
        closeDialog({ flag }) {
            this.dialogUpdate = flag;
            this.getUserList();
        },
        handleClose(done) {
            if (this.updateFlag) {
                this.$confirm('确认关闭?')
                    .then(_ => {
                        this.dialogUpdate = false;
                        this.updateFlag = false;
                        done();
                    })
                    .catch(_ => { });
            }else{
                done();
            }
        },
        // 当前页改变触发事件
        changeCurrentPage(page) {
            this.currentPage = page;
            this.getUserList();
        },
        // 上一页点击事件
        handlePrev(page) {
            this.currentPage = page;
            this.getUserList();
        },
        // 下一页点击事件
        handleNext(page) {
            this.currentPage = page;
            this.getUserList();
        },
        // 修改角色
        handleChangeRole(obj, mykey) {
            this.dialogUpdate = true;
            this.updateFlag = true;
            for (let key in this.flag) {
                if (key === mykey) {
                    this.flag[key] = true;
                } else {
                    this.flag[key] = false;
                }
            }
            this.userInfo = obj;
        },
        // 修改用户状态
        handleChangeStatus(obj) {
            let { id, status } = obj;
            status === true ? status = 1 : status = 0;
            this.$axios.post(`sccg/admin/updateStatus/` + id + '?status=' + status).then(res => {
            })
        },
        // 获取用户列表
        getUserList() {
            const that = this;
            const { currentPage, pageSize, search } = this;
            // 获取所有用户信息、用户查询(暂时支持电话号码)
            this.$axios.get(`sccg/admin/list?keyword=${search}&current=${currentPage}&pageSize=${pageSize}`).then(res => {
                if (res.code === 200) {
                    res.data.records.forEach(item => {
                        item.status === 1 ? item.status = true : item.status = false;
                    })
                    that.totalNum = res.data.total;
                    that.tableData = res.data.records;
                    this.renderFlag = true;
                }
            })
        },
        // 查看用户信息(不可修改)
        handleFind(rowData) {
            this.dialogView = true;
            this.userInfo = rowData;
        },
        // 设置表格斑马纹
        tableRowClassName({ row, rowIndex }) {
            if ((rowIndex + 1) % 2 === 0) {
                return 'warning-row';
            } else {
                return 'success-row';
            }
        },
        // 处理用户所属角色
        filterRole(arr){
            let str = '';
            if(arr.length === 0){
                return;
            }
            arr.forEach((item,index)=>{
                if(item!==null){
                    if(index<arr.length-1){
                        str+=item.name +',';
                    }else{
                        str+=item.name;
                    }
                }
            })
            return str;
        }
    },
    props: ['refresh', 'keyword', 'resetFresh'],
    watch: {
        refresh: {
            handler(newValue, oldValue) {
                if (newValue) {
                    this.search = '';
                    if (this.keyword !== '') {
                        this.search = this.keyword;
                    }
                    this.currentPage = 1;
                    this.getUserList();
                    this.$emit('resetFresh', { flag: false })
                }
            },
            immediate: true
        }
    }
}
</script>
<style lang="scss" scoped>
.mainContent {
  display: flex;
  justify-content: flex-start;
  flex-wrap: nowrap;
 
  .grid-content {
    margin-left: 10px;
    flex: 1;
    .tools {
      display: flex;
      justify-content: space-between;
      flex-wrap: nowrap;
 
      .pagination {
        margin-top: 55px;
      }
 
      .el-pagination {
        &::v-deep li,
        &::v-deep .btn-prev,
        &::v-deep .btn-next {
          background-color: #071f39;
          color: #4b9bb7;
        }
 
        &::v-deep .active {
          background-color: #409eff;
          color: #fff;
        }
      }
    }
  }
}
</style>