index.html
17.9 KB
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
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<meta content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="广联帐户管理中心-员工管理" />
<meta name="author" content="GLSX Web Team" />
<meta name="keywords" itemprop="keywords" content="广联,帐户管理,员工管理" />
<link rel="stylesheet" type="text/css" href="/css/main.css" />
<link rel="stylesheet" type="text/css" href="/css/employee.css" />
<link rel="stylesheet" type="text/css" href="/css/commonResetIndex.css" />
<title>员工管理</title>
</head>
<style>
xm-select>.xm-body .scroll-body {
width: 300px;
}
xm-select:hover {
border: 1px solid #2A58AD !important;
}
.hide {
display: none;
}
.show {
display: inline-block;
}
</style>
<body>
<div id="app">
<main>
<div>
<div class="search-block">
<!-- layui-form-pane -->
<form action="" class="layui-form" lay-filter="employeeForm">
<div class="layui-form-item">
<div class="twocol">
<div class="layui-inline" pane id="addEl">
<button type="button" class="layui-btn layui-btn-normal createBtn" id="addEmployee">
<i class="layui-icon layui-icon-addition"></i>
<span>创建员工</span>
</button>
</div>
<div class="layui-inline merchantNames" pane>
<label class="layui-form-label">商户名称</label>
<div class="layui-input-block">
<!-- <select name="merchantId" id="merchantName" lay-verify="required"></select> -->
<div id="merchantNameSelect" style="width: 300px" class="xm-select-demo"></div>
</div>
</div>
</div>
</div>
<div class="divideLine"></div>
<div class="layui-form-item secondInput">
<div class="layui-inline creater">
<label class="layui-form-label">创建者</label>
<div class="layui-input-block">
<input type="text" name="createdName" required lay-verify="required" placeholder="请输入创建者"
autocomplete="off" class="layui-input" />
</div>
</div>
<div class="layui-inline roleId hide" pane>
<label class="layui-form-label">角色</label>
<div class="layui-input-block">
<select name="roleId" id="roleId" lay-verify="required" placeholder="请选择状态"></select>
</div>
</div>
<div class="layui-inline status" pane>
<label class="layui-form-label">状态</label>
<div class="layui-input-block">
<select name="status" id="status" lay-verify="required" placeholder="请选择状态"></select>
</div>
</div>
<div class="layui-inline" pane>
<div class="layui-input-inline updateSelectAngle" style="width: 100px">
<select name="type" lay-verify="required" placeholder="员工姓名/手机号">
<option value="0">员工姓名</option>
<option value="1">手机号</option>
</select>
</div>
<div class="layui-input-inline" style="width: 250px">
<input type="text" name="keywords" required lay-verify="required" placeholder="请输入" autocomplete="off"
class="layui-input updateCircleAngle" />
</div>
</div>
<div id="from" class="layui-inline">
<label class="layui-form-label">来源:</label>
<div class="layui-input-inline" style="width: 246px">
<select name="createdSource" id="searchfrom">
<option value="">全部</option>
<option value="1">账户中心</option>
<option value="2">SCRM</option>
<option value="3">生意助手</option>
<option value="4">门店助手</option>
</select>
</div>
</div>
<div class="layui-inline" style="float: right" pane>
<button type="button" class="layui-btn layui-btn-normal exportInputBtn" id="employeeExport">导出</button>
<button id="employeeReset" class="layui-btn">重置</button>
<button type="button" class="layui-btn layui-btn-normal searchInputBtn" id="employeeSearch">查询</button>
</div>
</div>
</form>
<!-- 表格 -->
<div class="table-page">
<table id="employeeTable" lay-filter="employeeTool"></table>
<div id="employeePage" class="align-left"></div>
</div>
</div>
</div>
</main>
</div>
<script src="https://img02.glsx.com.cn/layui/layui.js"></script>
<script src="/js/load.js"></script>
<script>
layui.use(['table', 'request', 'form', 'helper', 'laypage', 'xmSelect'], function () {
var request = layui.request
var table = layui.table
var form = layui.form
var helper = layui.helper
var laypage = layui.laypage
var xmSelect = layui.xmSelect
var $ = layui.$
// var isDxternal = isAppend()
// if (isDxternal) {
// $('#addEl').remove()
// }
var roleId = $('#roleId')
var accountInfo = helper.store.get('accountInfo')
if (accountInfo) {
if (accountInfo.merchantAccountLevel == 4) {
$('.merchantNames').addClass('hide')
}
$('.creater').addClass('hide')
$('.roleId').removeClass('hide')
$('.roleId').addClass('show')
}
// 商户名称列表
var merchantName = $('#merchantName')
var status = $('#status')
var cols = [
//表头
{ field: '', title: '序号', type: 'numbers', width: 60 },
{ field: 'staffName', title: '员工姓名', width: 120, align: 'center' },
// { field: 'staffCode', title: '员工号', align: 'center' },
{ field: 'roleName', title: '角色', align: 'center' },
{ field: 'staffPhone', title: '登录手机号', align: 'center', width: 125 },
{ field: 'entmicroName', title: '企微号', align: 'center', width: 125 },
{ field: 'statusName', title: '状态', align: 'center', width: 80 },
{ field: 'createdAccount', title: '创建者', align: 'center' },
{ field: 'merchantName', title: '商户名(商户号)', align: 'center', width: 160 },
{ field: 'createdSourceStr', title: '来源', align: 'center', width: 160 ,templet: '#sourceTpl',},
{ field: 'createdTime', title: '创建时间', align: 'center', width: 160 },
{ field: 'updatedTime', title: '更新时间', align: 'center', width: 90 },
{ title: '操作', width: 160, align: 'center', toolbar: '#employeeBar' },
{ field: 'statusName', title: '启用开关', width: 85, templet: '#switchTpl', unresize: true }
]
var colums = [
//表头
{ field: '', title: '序号', type: 'numbers', width: 60 },
{ field: 'staffName', title: '员工姓名', width: 180, align: 'center' },
// { field: 'staffCode', title: '员工号', align: 'center' },
{ field: 'entmicroName', title: '员工企微号', align: 'center', width: 125 },
{ field: 'roleName', title: '角色', align: 'center' },
{ field: 'staffPhone', title: '登录手机号', align: 'center', width: 125 },
{ field: 'merchantName', title: '所属门店', align: 'center', width: 125, hide: accountInfo && accountInfo.merchantAccountLevel == 4 },
{ field: 'belongingEntmicroName', title: '所属企微', align: 'center', width: 125 },
{ field: 'statusName', title: '状态', align: 'center' },
{ field: 'updatedTime', title: '更新时间', align: 'center', width: 180 },
{ title: '操作', width: 160, align: 'center', toolbar: '#employeeBar' },
{ field: 'statusName', title: '启用开关', width: 85, templet: '#switchTpl', unresize: true }
]
//创建table实例
var employeeTable = table.render({
elem: '#employeeTable',
skin: 'nob',
height: 'full-300',
cols: accountInfo ? [colums] : [cols],
done: function (res, curr, count) {
$('.switch .layui-unselect:not(.layui-form-onswitch)').hover(
function (e) {
console.log(document.getElementsByName('sex'))
console.log(res, curr, count)
// 鼠标移入
layer.tips(
'<span style="color:#333333;font-size: 14px;font-weight: 400;">启用前,你可先为该员工创建角色,配置其所需的功能权限。如下所示:\n\
1. 角色管理-创建角色;\n\
2. 选择员工账户-修改角色</span>',
this,
{
tips: [4, '#fff'],
time: 0
}
)
},
function () {
// 鼠标移出
layer.closeAll()
}
)
}
})
// 分页配置
var page = {
pageNum: 1,
pageSize: 10
}
var pageOptions = {
elem: 'employeePage',
groups: 5,
layout: ['count', 'page', 'skip'],
jump: function (obj, first) {
//obj包含了当前分页的所有参数,比如:
page.pageNum = obj.curr
page.pageSize = obj.limit
//首次不执行
if (!first) {
getTabelList(employeeTable, getSearch())
// 移入移出
}
}
}
var merchantNameSelect = xmSelect.render({
el: '#merchantNameSelect',
prop: {
name: 'merchantName',
value: 'id'
},
name: 'merchantId',
clickClose: true,
filterable: true,
radio: true,
data: [],
on: function (data) {
if (data.isAdd) {
var id = data.change[0].id
findRoleList(id)
} else {
roleId.empty()
form.render('select')
}
}
})
// 初始化
init()
/** table工具条事件 */
table.on('tool(employeeTool)', function (obj) {
console.log(obj, '1111')
var data = obj.data
var layEvent = obj.event
var tr = obj.tr
if (layEvent === 'detail') {
go('employee', 'detail', { id: data.id, merchantId: data.merchantId })
} else if (layEvent === 'edit') {
go('employee', 'add', { id: data.id, merchantId: data.merchantId, merchantName: data.merchantName })
} else if (layEvent === 'del') {
layer.confirm('是否确认删除该员工?', { title: '', closeBtn: 0 }, function (index) {
// obj.del() //删除对应行(tr)的DOM结构,并更新缓存
var params = {
method: 'merchants.api.staff.deleteStaff',
id: data.id
}
request(params, function (res) {
if (res.code == '0') {
layer.close(index)
getTabelList(employeeTable)
}
})
//向服务端发送删除指令
})
} else if (layEvent === 'updateTime') {
layer.open({
type: 2,
title: '',
closeBtn: 0,
area: ['560px', '230px'],
fixed: false, //不固定
// maxmin: true,
btn: ['确定', '取消'],
content: 'validPeriod.html?id=' + data.id + '&effectiveTime=' + data.effectiveTime,
yes: function (index, layero) {
var body = layer.getChildFrame('body', index)
helper.store.set('isRefresh', false)
body.find('#periodVerifyBtn').click()
},
end: function () {
var isRefresh = helper.store.get('isRefresh')
if (isRefresh) {
getTabelList(employeeTable)
layer.msg('修改成功', {
icon: 1
})
}
helper.store.remove('isRefresh')
}
})
}
})
//监听性别操作
form.on('switch(sexDemo)', function (obj) {
if (this.value == '-') {
obj.elem.checked = !obj.elem.checked
form.render('checkbox')
layer.msg('您还未给该员工设置“角色”!\n\
设置角色:员工账户管理-修改-角色权限', { time: 2000 })
} else {
const param = {
id: obj.elem.dataset.id,
status: obj.elem.checked ? 0 : 2
}
var params = helper.clone(false, { method: 'merchants.api.staff.updateStatus' }, param)
request(params, function (res) {
if (res.code == '0') {
layer.msg('操作成功', {
icon: 1
})
var searchData = getSearch()
getTabelList(employeeTable, searchData, true)
layer.closeAll()
}
})
}
})
/** 手动触发事件 */
// 查询事件
$('#employeeSearch').on('click', function () {
var searchData = getSearch()
getTabelList(employeeTable, searchData, true)
})
// 新增点击事件
$('#addEmployee').on('click', function () {
go('employee', 'add')
})
// 重置
$('#employeeReset').on('click', function () {
$(".layui-form")[0].reset()
layui.form.render();
merchantNameSelect.setValue([])
// form.render('select')
getTabelList(employeeTable)
return false
})
// 导出
$('#employeeExport').on('click', function () {
var searchData = getSearch()
var params = helper.clone(false, { method: 'merchants.api.staff.exportData' }, searchData)
request(params, function (res) {
if (res.code == '0') {
window.open(res.data)
}
})
})
/** 定义方法 */
// 初始化方法
function init() {
findAllMerchant()
findAllDictData()
getTabelList(employeeTable)
}
// 获取table列表接口
function getTabelList(table, search, isResetPageNum) {
search = search || {}
var params = helper.clone(
false,
{
pageNum: page.pageNum,
pageSize: page.pageSize,
method: 'merchants.api.staff.findStaffByPage'
},
search
)
request(params, function (res) {
var data = helper.formateNullFieldData(res.data)
var options = {
data: data.data
}
pageOptions.count = data.count
if (isResetPageNum) {
pageOptions.curr = 1
}
laypage.render(pageOptions)
employeeTable.reload(options)
})
}
// 查询所有商户
function findAllMerchant() {
var params = { method: 'merchants.api.menu.findAllMerchant' }
request(params, function (result) {
if (result.code == '0') {
if (accountInfo && accountInfo.merchantAccountLevel == 4) {
findRoleList(result.data[0].id)
} else {
merchantNameSelect.update({
data: result.data,
autoRow: true,
paging: result.data.length > 20
})
}
}
})
}
// 查询角色权限列表
function findRoleList(merchantId) {
var params = { method: 'merchants.api.role.list', id: merchantId, delFlag: 0 }
request(params, function (res) {
if (res.code == '0') {
var list = res.data
roleId.empty()
list.unshift('')
$.each(list, function (index, item) {
roleId.append(new Option(item.roleName, item.id))
})
form.render('select')
}
})
}
// 搜索
function getSearch() {
var formVal = form.val('employeeForm')
var searchData = helper.clone(false, formVal)
if (searchData.type == 0) {
searchData.staffName = formVal.keywords
searchData.staffPhone = ''
} else if (searchData.type == 1) {
searchData.staffName = ''
searchData.staffPhone = formVal.keywords
} else {
searchData.staffName = ''
searchData.staffPhone = ''
}
delete searchData.type
delete searchData.keywords
return searchData
}
function findAllDictData() {
var params = {
method: 'merchants.api.menu.findAllDictData',
dictType: 'staff_status'
}
request(params, function (res) {
if (res.code == '0') {
var list = res.data
list.unshift('')
$.each(list, function (index, item) {
status.append(new Option(item.dictLabel, item.dictValue))
})
form.render('select')
}
})
}
})
</script>
<script type="text/html" id="employeeBar">
<div>
<a class="layui-btn-xs" lay-event="detail">查看</a>
<a class="layui-btn-xs" lay-event="edit">修改</a>
<a class="layui-btn-xs" lay-event="del">删除</a>
</div>
<!-- <div>
<a class="layui-btn-xs" lay-event="updateTime">修改账户有效期</a>
</div> -->
</script>
<script type="text/html" id="switchTpl">
<!-- 这里的 checked 的状态只是演示 -->
<div class="switch">
<input type="checkbox" name="sex" value="{{d.roleName}}" data-id="{{d.id}}" lay-skin="switch" lay-text="开|关"
lay-filter="sexDemo" {{ d.status==0 ? 'checked' : '' }}>
</div>
</script>
</body>
</html>