永康嘉持电器有限公司前端
小小儁爺
2024-12-30 ff2f7d7bad0132c130c305364a863ff446e926b2
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
<template>
  <div>
    <div class="body" :style="{height:mainHeight+'px'}">
      <div class="bodyTopButtonGroup">
        <el-button v-waves type="primary" icon="el-icon-circle-plus-outline" @click="add('add')">新增</el-button>
        <el-button v-waves type="danger" icon="el-icon-error" @click="batchCancel">批量取消授权</el-button>
        <!--        <el-button v-waves type="warning" icon="el-icon-close">关闭</el-button>-->
      </div>
 
      <div class="bodyTopFormGroup">
        <el-form
          ref="form"
          :model="form"
          label-width="100px"
          inline
          style="display: flex;"
        >
          <div class="elForm">
            <el-form-item label="角色编码" style=" display: flex;">
              <el-select
                v-model="form.role_code"
                style="width:200px"
                placeholder="请选择"
                @change="roleChange"
              >
                <el-option
                  v-for="item in roleArr"
                  :key="item.rolecode"
                  :label="item.rolename"
                  :value="item.rolecode"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="用户编码" style=" display: flex;">
              <el-input v-model="form.usercode" placeholder="请输入" style="width: 200px" />
            </el-form-item>
            <el-form-item label="用户名称" style=" display: flex;">
              <el-input v-model="form.username" placeholder="请输入" style="width: 200px" />
            </el-form-item>
 
            <el-form-item label="组织编码" style=" display: flex;">
              <el-cascader
                ref="cascader"
                v-model="form.storg_code"
                :options="cascaderOptions"
                filterable
                :props="defaultProps"
                :show-all-levels="false"
              />
            </el-form-item>
            <el-form-item v-show="isExpandForm" label="岗位名称" style=" display: flex;">
              <el-select
                v-model="form.post_code"
                style="width:200px"
                multiple
                collapse-tags
                placeholder="请选择"
              >
                <el-option
                  v-for="item in postArr"
                  :key="item.postcode"
                  :label="item.postname"
                  :value="item.postcode"
                />
              </el-select>
            </el-form-item>
            <el-form-item v-show="isExpandForm" label="班组编码" style=" display: flex;">
              <el-select
                v-model="form.group_code"
                style="width:200px"
                multiple
                collapse-tags
                placeholder="请选择"
              >
                <el-option
                  v-for="item in groupArr"
                  :key="item.usergroupcode"
                  :label="item.usergroupname"
                  :value="item.usergroupcode"
                />
              </el-select>
            </el-form-item>
          </div>
          <div
            class="bodySearchReset"
            :style="{marginLeft:$store.state.app.sidebar.opened? $store.state.settings.menuIsHorizontal?'15%':'3%':'10%'}"
          >
            <el-button v-waves type="primary" icon="el-icon-search" @click="getRoleAssignedUserData">查询</el-button>
            <el-button v-waves type="info" icon="el-icon-refresh" @click="reset">重置</el-button>
          </div>
        </el-form>
        <div
          class="bodyTopFormExpand"
        >
          <svg-icon
            v-show="mouseHoverType==='mouseout'"
            style="cursor: pointer"
            :icon-class="!isExpandForm?'doubleDown3':'doubleUp3'"
            @mouseenter="mouseHoverType=$event.type"
          />
          <svg-icon
            v-show="mouseHoverType==='mouseenter'"
            style="cursor: pointer"
            :icon-class="!isExpandForm?'doubleDown':'doubleUp'"
            @click="isExpandForm=!isExpandForm"
            @mouseout="mouseHoverType=$event.type"
          />
        </div>
      </div>
 
      <div class="elTableDiv">
        <el-table
          ref="tableDataRef"
          class="tableFixed"
          :data="tableData"
          :height="isExpandForm?tableHeight:(tableHeight+40)+'px'"
          border
          row-class-name="custom-row"
          :style="{width: 100+'%',height:isExpandForm?tableHeight:(tableHeight+40)+'px',}"
          highlight-current-row
          :row-key="getRowKey"
          :header-cell-style="this.$headerCellStyle"
          :cell-style="this.$cellStyle"
          @selection-change="handleSelectionChange"
          @sort-change="sortChange"
        >
          <el-table-column
            type="selection"
            width="50"
            :reserve-selection="true"
            fixed
          />
          <el-table-column
            prop="rowNum"
            width="50"
            fixed
            label="序号"
          />
          <el-table-column
            prop="usercode"
            label="用户编码"
            sortable="custom"
          />
          <el-table-column
            prop="username"
            label="用户名称"
            sortable="custom"
          />
          <el-table-column
            prop="storg_name"
            label="所属组织"
            sortable="custom"
          />
          <el-table-column
            prop="rolename"
            label="角色"
            show-overflow-tooltip
            sortable="custom"
          >
            <template slot-scope="{row}">
              {{ row.rolename ? row.rolename : '/' }}
            </template>
          </el-table-column>
          <el-table-column
            prop="postname"
            label="岗位"
            sortable="custom"
            show-overflow-tooltip
          >
            <template slot-scope="{row}">
              {{ row.postname ? row.postname : '/' }}
            </template>
          </el-table-column>
          <el-table-column
            prop="group_name"
            label="班组"
            show-overflow-tooltip
            sortable="custom"
          >
            <template slot-scope="{row}">
              {{ row.group_name ? row.group_name : '/' }}
            </template>
          </el-table-column>
 
          <el-table-column
            label="操作"
            width="200"
            fixed="right"
          >
            <template slot-scope="{row}">
              <div class="operationClass">
                <el-button
                  type="text"
                  style="cursor: pointer;font-size: 14px"
                  @click="cancel(row.usercode)"
                >取消授权
                </el-button>
 
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--分页-->
      <pagination
        :total="total"
        :page.sync="form.page"
        :limit.sync="form.rows"
        align="right"
        layout="total,prev, pager, next,sizes,jumper"
        popper-class="select_bottom"
        @pagination="getRoleAssignedUserData"
      />
    </div>
 
    <el-dialog
      v-el-drag-dialog
      title="新增"
      :visible.sync="dialogVisible"
      width="1200px"
      :close-on-click-modal="false"
      top="15vh"
      @closed="handleClose"
      @close="handleClose"
    >
      <div>
        <el-table
          ref="tableDataDialogRef"
          class="tableFixed"
          :data="tableDataDialog"
          row-class-name="custom-row"
 
          height="400"
          border
          :style="{width: 100+'%',height:'400px',}"
          highlight-current-row
          :row-key="getRowKey"
          :header-cell-style="this.$headerCellStyle"
          :cell-style="this.$cellStyle"
          @selection-change="handleDialogSelectionChange"
        >
          <el-table-column
            type="selection"
            width="50"
            :reserve-selection="true"
            fixed
          />
          <el-table-column
            prop="rowNum"
            width="50"
            fixed
            label="序号"
          />
          <el-table-column
            prop="usercode"
            label="用户编码"
          />
          <el-table-column
            prop="username"
            label="用户名称"
          />
          <el-table-column
            prop="storg_name"
            label="所属组织"
          />
          <el-table-column
            prop="rolename"
            show-overflow-tooltip
            label="角色"
          >
            <template slot-scope="{row}">
              {{ row.rolename?row.rolename:'/' }}
            </template>
          </el-table-column>
          <el-table-column
            prop="postname"
            label="岗位"
            show-overflow-tooltip
          >
            <template slot-scope="{row}">
              {{ row.postname?row.postname:'/' }}
            </template>
          </el-table-column>
          <el-table-column
            prop="group_name"
            show-overflow-tooltip
            label="班组"
          >
            <template slot-scope="{row}">
              {{ row.group_name?row.group_name:'/' }}
            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <pagination
          :total="totalDialog"
          :page.sync="dialogForm.page"
          :limit.sync="dialogForm.rows"
          align="right"
          style="margin-top: 10px;"
          layout="total,prev, pager, next,sizes,jumper"
          popper-class="select_bottom"
          @pagination="add"
        />
      </div>
      <span slot="footer" class="dialog-footer">
        <div class="footerButton">
          <el-button
            v-waves
            @click="dialogVisibleCancel"
          >取 消</el-button>
          <el-button
            v-waves
            type="primary"
            :loading="$store.state.app.buttonIsDisabled"
            :disabled="$store.state.app.buttonIsDisabled"
            @click="dialogVisibleConfirm"
          >确 定</el-button>
        </div>
      </span>
    </el-dialog>
 
  </div>
</template>
 
<script>
import Pagination from '@/components/Pagination'
import {
  RoleAssignedUserBatchAdd,
  RoleAssignedUserBatchCancel,
  RoleAssignedUserData
} from '@/api/basicSettings'
import elDragDialog from '@/directive/el-drag-dialog'
import waves from '@/directive/waves'
import arrayToTree from 'array-to-tree'
import { GroupsPermissions, PostPermissions, PrentOrganization, RolePermissions } from '@/api/GeneralBasicData'
 
export default {
  name: 'RoleDivider',
  components: {
    Pagination
  },
  directives: { elDragDialog, waves },
  data() {
    return {
      mouseHoverType: 'mouseout',
      isExpandForm: false,
      mainHeight: 0,
      tableHeight: 0,
      form: {
        flag: 'TRUE', // TRUE(已关联) FALSE(未关联)
        role_code: '', // 角色编码
        usercode: '', // 用户编码
        username: '', // 用户名称
        storg_code: [], //
        post_code: [], //
        group_code: [], //
        prop: 'lm_date', // 排序字段
        order: 'desc', // 排序字段
        page: 1, // 第几页
        rows: 20 // 每页多少条
      },
      total: 10,
      tableData: [],
 
      cascaderOptions: [],
      defaultProps: {
        checkStrictly: true,
        expandTrigger: 'hover',
        value: 'torg_code',
        label: 'torg_name'
      },
      roleArr: [],
      postArr: [],
      groupArr: [],
 
      dialogVisible: false,
      dialogForm: {
        page: 1, // 第几页
        rows: 20 // 每页多少条
      },
      tableDataDialog: [],
      totalDialog: 10,
 
      batchRoleCode: [],
      batchDialogRoleCode: []
 
    }
  },
  activated() {
    window.addEventListener('resize', this.getHeight)
    this.getHeight()
    this.getAllSelectData()
    this.getPrentOrganization()
  },
  created() {
  },
  mounted() {
    window.addEventListener('resize', this.getHeight)
    this.getHeight()
 
    this.getAllSelectData()
    this.getPrentOrganization()
  },
  methods: {
    // 组织架构大列表查询
    async getRoleAssignedUserData() {
      if (window.location.hash.indexOf('?') !== -1) {
        this.form.role_code = window.location.hash.split('?')[1].split('=')[1]
      }
 
      if (!this.form.role_code) {
        this.form.role_code = this.roleArr[0].rolecode
      }
 
      this.form.storg_code = this.form.storg_code ? this.form.storg_code[this.form.storg_code.length - 1] : ''
      this.form.post_code = this.form.post_code ? this.form.post_code.join(',') : ''
      this.form.group_code = this.form.group_code ? this.form.group_code.join(',') : ''
 
      const res = await RoleAssignedUserData(this.form)
      this.tableData = res.data
      this.total = res.count
    },
    async getPrentOrganization() {
      const { data: res } = await PrentOrganization()
      this.cascaderOptions = arrayToTree(res, {
        parentProperty: 'parent_id',
        customID: 'torg_code',
        childrenProperty: 'children'
      })
    },
    // 岗位 角色 班组
    async getAllSelectData() {
      const { data: res2 } = await RolePermissions()
      this.roleArr = res2
      await this.getRoleAssignedUserData()
 
      const { data: res1 } = await PostPermissions()
      this.postArr = res1
 
      const { data: res3 } = await GroupsPermissions()
      this.groupArr = res3
    },
    // 排序改变时
    sortChange({ column, prop, order }) {
      if (order === 'descending') {
        order = 'desc'
      } else if (order === 'ascending') {
        order = 'asc'
      } else {
        order = 'desc'
      }
      this.form.order = order
      this.form.prop = prop
      this.getRoleAssignedUserData()
    },
    // 重置
    reset() {
      this.form.usercode = ''
      this.form.username = ''
 
      this.form.storg_code = []
      this.form.post_code = []
      this.form.group_code = []
      this.getRoleAssignedUserData()
    },
    roleChange(val) {
      this.getRoleAssignedUserData()
      this.batchRoleCode = []
      this.$refs.tableDataRef.clearSelection()
    },
 
    async cancel(code) {
      // if (!this.form.role_code) {
      //   return this.$message.error('')
      // }
 
      const res = await RoleAssignedUserBatchCancel([code], this.form.role_code)
      if (res.code === '200') {
        this.$notify.success('取消授权成功!')
        await this.getRoleAssignedUserData()
      } else {
        this.$notify.error('取消授权失败!')
      }
    },
 
    async batchCancel() {
      const res = await RoleAssignedUserBatchCancel(this.batchRoleCode, this.form.role_code)
      if (res.code === '200') {
        this.$notify.success(this.batchRoleCode.length + '个用户取消授权成功!')
        await this.getRoleAssignedUserData()
        this.batchRoleCode = []
        this.$refs.tableDataRef.clearSelection()
      } else {
        this.$notify.error(this.batchRoleCode.length + '个用户取消授权失败!')
      }
    },
 
    // 新增按钮
    async add() {
      this.dialogVisible = true
 
      const data = {
        flag: 'FALSE', // TRUE(已关联) FALSE(未关联)
        role_code: this.form.role_code, // 角色编码
        usercode: '', // 用户编码
        username: '', // 用户名称
        storg_code: '', //
        post_code: '', //
        group_code: '', //
        prop: 'lm_date', // 排序字段
        order: 'desc', // 排序字段
        page: this.dialogForm.page, // 第几页
        rows: this.dialogForm.rows // 每页多少条
      }
      const res = await RoleAssignedUserData(data)
      this.tableDataDialog = res.data
      this.totalDialog = res.count
    },
 
    // 对话框关闭事件
    handleClose() {
      // this.form.flag = 'TRUE'
    },
    getRowKey(row) {
      return row.usercode
    },
    handleSelectionChange(rows) {
      this.batchRoleCode = rows.map(i => i.usercode)
    },
    handleDialogSelectionChange(rows) {
      this.batchDialogRoleCode = rows.map(i => i.usercode)
    },
    // 对话框取消
    dialogVisibleCancel() {
      this.dialogVisible = false
    },
    // 对话框确认
    async  dialogVisibleConfirm() {
      const res = await RoleAssignedUserBatchAdd(this.batchDialogRoleCode, this.form.role_code)
      if (res.code === '200') {
        this.$notify.success(this.batchDialogRoleCode.length + '个用户新增授权成功!')
        await this.getRoleAssignedUserData()
        this.batchDialogRoleCode = []
        this.$refs.tableDataDialogRef.clearSelection()
        this.dialogVisible = false
      } else {
        this.$notify.error(this.batchDialogRoleCode.length + '个用户新增授权失败!')
      }
    },
    // 获取页面高度
    getHeight() {
      this.$nextTick(() => {
        this.mainHeight = window.innerHeight - 85
        this.tableHeight = this.mainHeight - 255
        this.$refs.tableDataRef.doLayout()
      })
    }
  }
}
</script>