add.html
32.2 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
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
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
<!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" />
<title>角色管理</title>
<style>
.Wrap {
margin: 8px 0 0;
padding-bottom: 100px;
}
.show {
display: inline-block;
width: 360px;
}
.hide {
display: none;
}
.tabmutiple-content-wrap {
background-color: #f4f6fc;
/* padding-top: 10px; */
/* padding-bottom: 1px; */
}
.tabmutiple-content {
/* margin: 0 10px; */
background-color: #fff;
}
.contentGrayBg {
/* background-color: #fff; */
/* border: 2px solid red; */
}
.layui-tab-title {
background-color: #f4f6fc;
box-sizing: border-box;
}
.contentGrayBg .layui-this {
background-color: #fff;
border: 2px solid #fff;
margin-left: -3px;
}
.contentGrayBg .layui-tab {
border: 10px solid #f4f6fc;
}
.edit-box {
padding: 0 20px 20px;
color: #333333;
background-color: #ffffff;
margin: 15px auto;
position: relative;
/* height: 100%; */
}
.edit-box .grayLine {
position: absolute;
left: 0;
top: 48px;
background-color: #d8d8d8;
width: 100%;
height: 1px;
}
.edit-title {
height: 78px;
line-height: 78px;
padding: 0 20px;
margin-bottom: 15px;
font-size: 16px;
font-weight: 700;
color: #333333;
background-color: #fff;
}
.baseInfo {
height: 48px;
line-height: 48px;
font-size: 16px;
color: #333333;
font-weight: 600;
}
#roleTitle {
font-size: 20px;
color: #333333;
font-weight: bold;
}
.layui-tab-content {
position: relative;
}
.layui-no-data {
width: 100%;
height: 500px;
}
.layui-no-data .no-data {
position: absolute;
top: 50%;
height: 50%;
width: 100%;
text-align: center;
font-size: 14px;
line-height: 22px;
}
.layui-no-data .no-data div {
margin-top: 12px;
}
.xm-select-demo,
xm-select>.xm-body .scroll-body {
width: 360px;
}
</style>
</head>
<body>
<div id="app">
<main>
<div class="Wrap">
<div class="layui-form-item edit-title" style="position: relative">
<div id="roleTitle" class="layui-input-inline"></div>
</div>
<div class="sub-bg-white edit-box">
<div class="grayLine"></div>
<form class="layui-form add" lay-filter="roleForm" action="">
<div class="layui-form-item">
<div class="layui-input-inline baseInfo">角色基本信息</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">所属商户:</label>
<div class="layui-input-block" id="merchantBox">
<!-- <div id="merchantSelect" class="hide">
<select id="merchantName" name="merchantId" lay-filter="merchants" lay-verify="required" autocomplete="off" placeholder="请选择商户名称" required></select>
</div> -->
<div id="merchantNameSelect" class="xm-select-demo"></div>
<div class="hide" id="merchantIdText" style="line-height: 36px"></div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">角色名称:</label>
<div class="layui-input-block">
<input type="text" name="roleName" maxlength="15" lay-verify="required" placeholder="请输入角色名称"
class="layui-input" />
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">角色说明:</label>
<div class="layui-input-block">
<input type="text" name="roleDescription" maxlength="50" placeholder="请输入角色说明" class="layui-input" />
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">角色权限:</label>
<div class="layui-input-block" id="accountType">
<!-- <input lay-filter="switch" type="checkbox" name="merchantId" value="1" title="引流渠道商" />
<input lay-filter="switch" type="checkbox" name="merchantId" value="2" title="服务商/合作商" /> -->
</div>
</div>
<div class="tabmutiple-content-wrap removeCheckBg">
<!-- <div id="authorityTree"> -->
<div class="layui-tab tabmutiple-content" lay-filter="roleAuth">
<ul class="layui-tab-title"></ul>
<div class="layui-tab-content contentGrayBg"></div>
</div>
<!-- </div> -->
</div>
<div class="footer-close">
<button class="layui-btn hide" id="draft">存草稿</button>
<button class="layui-btn" lay-submit lay-filter="roleSubmit">确定</button>
<button type="reset" class="layui-btn" id="return">取消</button>
</div>
</form>
</div>
</div>
</main>
</div>
<script src="https://img02.glsx.com.cn/layui/layui.js"></script>
<script src="/js/load.js"></script>
<script>
layui.use(['form', 'element', 'request', 'laytpl', 'xmSelect', 'gtree', 'helper', 'xmSelect'], function () {
// var merchantId = qs('merchantId')
var roleid = qs('id')
var element = layui.element
var form = layui.form
var helper = layui.helper
var arr_box = []
var $ = layui.$
var xmSelect = layui.xmSelect
var request = layui.request
var merchantId = ''
var accountInfo = helper.store.get('accountInfo')
// 禁用所有input框的回车事件
var inputs = document.getElementsByTagName('input')
for (let i = 0; i < inputs.length; i++) {
var input = inputs[i]
input.onkeydown = function (event) {
if (event.keyCode == 13) {
event.keyCode = 0;
event.returnValue = false;
}
}
}
var merchantNameSelect = xmSelect.render({
el: '#merchantNameSelect',
prop: {
name: 'merchantName',
value: 'id'
},
layVerify: 'required',
model: {
label: {
type: 'text',
text: {}
}
},
name: 'merchantId',
filterable: true,
radio: true,
clickClose: true,
data: [],
on: function (data) {
merchantId = data.change[0].id
findMenuFunTreeByMerId(merchantId)
for (var key in treeData) {
active.tabDelete('roleAuth', key)
treeData = {}
}
}
})
if (roleid) {
$('#roleTitle').append('修改角色')
getById(roleid)
$('#merchantIdText').text(qs('merchantName'))
$('#merchantIdText').removeClass('hide')
$('#merchantIdText').addClass('show')
$('#merchantNameSelect').addClass('hide')
} else {
$('#roleTitle').append('新增角色')
$('#draft').removeClass('hide')
$('#draft').addClass('show')
// var str =
// '<div id="merchantSelect" class="hide"><select id="merchantName" name="merchantId" lay-filter="merchants" lay-verify="required" autocomplete="off" placeholder="请选择商户名称" required></select></div>'
// $('#merchantBox').append(str)
findAllMerchant()
// $('#merchantSelect').removeClass('hide')
// $('#merchantSelect').addClass('show')
// findMenuFunTreeByMerId()
}
var merchantName = $('#merchantName')
// start
var laytpl = layui.laytpl
var xmSelect = layui.xmSelect
var tree = layui.gtree
var helper = layui.helper
var check_arr = []
var requestList = []
var templateData = {}
var selectEl = {}
var treeData = {}
var menuFunTreeData = [] // 商户的菜单权限树数据
var active = {
/**
* 第一级tab添加
* item: {name: 选项卡名称, value: 选项卡值}
* roleAuth: 选项卡过滤器的名称 lay-filter绑定的名字
* content: 一个放置模板的视图容器,用于呈现渲染结果 带有id的div
* id:选项卡标题的lay-id属性值
* 需要引入laytpl 模块
* rolesAuth:模板的id
* view 放置模板的视图容器的dom
* templateData:用于渲染模板的数据
* productList:复选下拉框的list,修改过的数据{name: '', value: ''}
* products:对应的菜单下的产品list,包含了对应的权限树,原始数据,需作为参数传入treeTabAdd中,在实例化tree时传入的数据使用
*/
tabAdd: function (item, productList) {
// 渠道的id,一层选项卡的id
var id = item.value
// roleAuth 一层选项卡过滤器的名称
element.tabAdd('roleAuth', {
title: item.title,
// 放置模板视图的上一级div
content: '<div id="role' + id + '"></div>',
// 选项卡标题的lay-id属性值
id: id
})
var getTpl = `<form class="layui-form layui-form-pane" action="">\
<div class="layui-form-item" pane>\
<label class="layui-form-label">选择产品:</label>\
<div class="layui-input-block" id="project${id}">
</div>
</div>
</form>
<div style="font-size:14px;color:#333;font-weight:500;margin-left: 55px;">请选择产品权限</div>
<div class="layui-tab " lay-filter="treeTab{{d.id}}">
<ul class="layui-tab-title"></ul>
<div class="layui-tab-content">
<div class="layui-no-data show" id="nodata${id}">
<div class="no-data">
<img src="../../css/img/no-data.png" />
<div>请先选择产品</div>
</div>
</div>
</div>
</div>`
// '<div id="select{{d.id}}"></div> <div class="layui-tab layui-tab-brief" lay-filter="treeTab{{d.id}}"><ul class="layui-tab-title"></ul> <div class="layui-tab-content"></div></div>'
view = document.getElementById('role' + id)
templateData.id = id // 渲染模版的数据
laytpl(getTpl).render(templateData, function (html) {
view.innerHTML = html
})
var products = menuFunTreeData.find(item => item.accounttypeId == id).products
products.forEach(i => {
var str = $('<input lay-filter="filter" data-id="' + id + '" type="checkbox" name="check[' + id + ']" value="' + i.productId + '" title="' + i.productName + '" lay-skin="primary" />')
$('#project' + id).append(str)
if (productList) {
productList.forEach(j => {
if (j.productId == i.productId) {
str.attr('checked', true)
}
})
}
form.render()
})
// $.each(menuFunTreeData, function(index, item) {
// if (item.accounttypeId == id) {
// // products = item.products
// $.each(item.products, function(idx, i) {
// var str = $('<input lay-filter="filter" data-id="' + id + '" type="checkbox" name="check[' + id + ']" value="' + i.productId + '" title="' + i.productName + '" lay-skin="primary" />')
// $('#project' + id).append(str)
// })
// }
// })
// console.log('productList', products, id)
// selectEl[id] = xmSelect.render({
// el: '#select' + id,
// data: productList,
// on: function(data) {
// //arr: 当前多选已选中的数据
// var arr = data.arr
// //change, 此次选择变化的数据,数组
// var change = data.change
// //isAdd, 此次操作是新增还是删除
// var isAdd = data.isAdd
// var filterName = 'treeTab' + id
// if (isAdd) {
// active.treeTabAdd(change[0], id, products)
// } else {
// var productId = 'tab_' + id + '_' + change[0].value
// active.tabDelete(filterName, productId)
// delete treeData[id][change[0].value]
// }
// if (arr.length != 0) {
// var productId = 'tab_' + id + '_' + arr[0].value
// active.tabChange(filterName, productId)
// }
// }
// })
// console.log(selectEl[id])
},
// tab删除
tabDelete: function (name, id) {
element.tabDelete(name, id)
},
// tab Change
tabChange: function (name, id) {
element.tabChange(name, id)
if (name == 'roleAuth') {
$(`#nomenu${id}`).html('请选择产品')
} else {
const accounttypeId = id.split('_')[1]
const productId = id.split('_')[2]
$(`#nodata${accounttypeId}`).removeClass('show')
$(`#nodata${accounttypeId}`).addClass('hide')
$(`#nomenu${accounttypeId}`).html('暂无可选择的菜单功能')
menuFunTreeData.forEach(item => {
if (item.accounttypeId == accounttypeId) {
item.products.forEach(i => {
if (i.productId == productId) {
if (i.merchantProTreeResponses.length == 0) {
$(`#nomenutab_${accounttypeId}_${productId}`).removeClass('hide')
$(`#nomenutab_${accounttypeId}_${productId}`).addClass('show')
} else {
$(`#nomenutab_${accounttypeId}_${productId}`).removeClass('show')
$(`#nomenutab_${accounttypeId}_${productId}`).addClass('hide')
}
}
})
}
})
}
},
/**
* 第二级选项卡
* treeTabAdd 产品的权限添加
* item: {name: 选项卡名称, value: 选项卡值}
* id 第一级选项卡的item.value
* filterName: 过滤器的名称 lay-filter绑定的值
* treeData:渲染模板的数据,和用来存放对应树实例的对象,
* products:产品list数组
* defaultList:编辑时传入,默认勾选中的数组。(举例:[1,2,3])
*/
treeTabAdd: function (item, id, treeListData, defaultList) {
var productId = 'tab_' + id + '_' + item.value
var filterName = 'treeTab' + id // 过滤器的名称 lay-filter
element.tabAdd(filterName, {
title: item.name,
content: '<div id="treeTab' + productId + '"></div>', // 放置模板视图的div
id: productId
})
var getTreeTpl = treeAuth.innerHTML, // 获取的模板的id的内容
treeView = document.getElementById('treeTab' + productId) // 放置模板视图的div
treeData[id] = treeData[id] || {}
treeData[id][item.value] = treeData[id][item.value] || {}
treeData[id][item.value].id = productId // 渲染模版的数据
treeData[id][item.value].productId = item.value
laytpl(getTreeTpl).render(treeData[id][item.value], function (html) {
treeView.innerHTML = html
})
// var treeListData = []
// $.each(products, function(index, i) {
// if (item.value == i.productId) {
// treeListData = i.merchantProTreeResponses
// }
// })
var treedom = 'tree_' + productId
if (treeListData && treeListData.length != 0) {
if (!roleid) {
treeData[id][item.value].treeObj = tree.create(treedom, treeListData)
treeData[id][item.value].treeObj.checkAllNodes(true)
} else {
treeData[id][item.value].treeObj = tree.create(treedom, treeListData)
if (defaultList) {
treeData[id][item.value].treeObj.checkNodes(defaultList)
} else {
treeData[id][item.value].treeObj.checkAllNodes(true)
}
}
// $(`#nodata${id}`).removeClass('show')
// $(`#nodata${id}`).addClass('hide')
} else {
// $(`#nodata${id}`).removeClass('hide')
// $(`#nodata${id}`).addClass('show')
}
}
}
// 产品复选框change事件
form.on('checkbox(filter)', function (data) {
var roleId = +data.elem.dataset.id
var projectId = data.value
var isAdd = data.elem.checked
var filterName = 'treeTab' + roleId
// merchantProTreeResponses
var changeObj = menuFunTreeData.find(item => item.accounttypeId == roleId).products.find(i => i.productId == projectId)
var products = menuFunTreeData.find(item => item.accounttypeId == roleId).products
if (isAdd) {
// 新增
active.treeTabAdd(
{
name: changeObj.productName,
value: changeObj.productId
},
roleId,
changeObj.merchantProTreeResponses
)
} else {
// 删除
var productId = 'tab_' + roleId + '_' + changeObj.productId
active.tabDelete(filterName, productId)
if (Object.keys(treeData).length != 0) {
delete treeData[roleId][changeObj.productId]
}
if (Object.keys(treeData).length == 0 || Object.keys(treeData[roleId]).length == 0) {
$(`#nodata${roleId}`).removeClass('hide')
$(`#nodata${roleId}`).addClass('show')
}
}
if (Object.keys(treeData).length != 0) {
var productId = 'tab_' + roleId + '_' + changeObj.productId
active.tabChange(filterName, productId)
}
})
// 复选框的change事件
form.on('checkbox(switch)', function (data) {
if (data.elem.checked) {
var obj = { title: data.elem.title, value: data.elem.value }
check_arr.push({
accounttypeId: data.elem.value
})
active.tabAdd(obj)
treeData[+data.elem.value] = {}
} else {
for (var i in check_arr) {
var id = check_arr[i].accounttypeId
if (check_arr[i].accounttypeId == data.elem.value) {
active.tabDelete('roleAuth', id)
check_arr.splice(i, 1)
}
}
delete treeData[data.elem.value]
}
if (check_arr.length != 0) {
active.tabChange('roleAuth', check_arr[0].accounttypeId)
}
})
// end
// 表单提交
form.on('submit(roleSubmit)', function (data) {
if (check_arr.length == 0) {
layer.msg('请选择角色权限', {
icon: 2
})
return false
}
getAuthList()
insert(0, data.field)
return false
})
// select 选择触发
form.on('select(merchants)', function (data) {
check_arr.forEach(item => {
active.tabDelete('roleAuth', item.accounttypeId)
})
// check_arr = []
// treeData = {}
merchantId = data.value
findMenuFunTreeByMerId(merchantId)
})
// 存草稿
$('#draft').on('click', function () {
var formVal = form.val('roleForm')
if (!merchantId) {
layer.msg('请选择所属商户', {
icon: 2
})
return false
}
if (formVal.roleName || formVal.roleDescription || Object.keys(treeData).length != 0) {
getAuthList()
insert(1, formVal)
} else {
layer.msg('至少填一项', {
icon: 2
})
}
return false
})
// 返回上个页面
$('#return').on('click', function () {
window.history.back()
})
// 调用新增接口
function insert(delFlag, formVal) {
var otherParams = {
merchantId: merchantId,
delFlag: delFlag
}
let hasProduct = requestList.some(item => item.productList.length != 0)
// 找这个数组里面是否有空值,然后判断是否为草稿,
if (delFlag == 1) { // 草稿
// if (hasProduct) {
otherParams.requestList = JSON.stringify(requestList)
// } else {
// otherParams.requestList = JSON.stringify([])
// }
// if (requestList.length != 0) {
// otherParams.requestList = JSON.stringify(requestList)
// } else {
// otherParams.requestList = JSON.stringify([])
// }
} else {
if (hasProduct) {
otherParams.requestList = JSON.stringify(requestList)
} else {
layer.msg('请选择产品', {
icon: 2
})
return
}
// if (requestList.length != 0) {
// otherParams.requestList = JSON.stringify(requestList)
// } else {
// layer.msg('请选择产品', {
// icon: 2
// })
// return
// }
}
// otherParams.requestList = JSON.stringify([])
if (roleid) {
otherParams.id = roleid
otherParams.method = 'merchants.api.role.update'
} else {
otherParams.method = 'merchants.api.role.insert'
}
var params = helper.clone(true, formVal, otherParams)
delete params.select
request(params, function (res) {
if (res.code == '0') {
layer.msg('操作成功', {
icon: 1
})
window.history.back()
}
})
}
// 查询商户的菜单权限树
function findMenuFunTreeByMerId(merchantId) {
var params = {
method: 'merchants.api.merchant.findMenuFunTreeByMerId',
id: merchantId
}
request(params, function (res) {
if (res.code == '0') {
// callback(res.data)
menuFunTreeData = res.data
var accountType = $('#accountType')
accountType.empty()
menuFunTreeData.forEach((item, index) => {
var str = $('<input lay-filter="switch" type="checkbox" name="accounttypeId" value="' + item.accounttypeId + '" title="' + item.accounttypeName + '" />')
accountType.append(str)
if (roleid) {
check_arr.forEach(i => {
if (i.accounttypeId == item.accounttypeId) {
var productData = i
var id = item.accounttypeId
str.attr('checked', true)
var obj = { title: item.accounttypeName, value: item.accounttypeId }
active.tabAdd(obj, productData.productList)
if (productData.productList && productData.productList.length != 0) {
productData.productList.forEach(j => {
var products = item.products.find(n => n.productId == j.productId)
active.treeTabAdd(
{
name: j.productName,
value: j.productId
},
item.accounttypeId,
products.merchantProTreeResponses,
j.idList
)
if (products.merchantProTreeResponses.length == 0) {
$(`#nomenutab_${id}_${j.productId}`).removeClass('hide')
$(`#nomenutab_${id}_${j.productId}`).addClass('show')
} else {
$(`#nomenutab_${id}_${j.productId}`).removeClass('show')
$(`#nomenutab_${id}_${j.productId}`).addClass('hide')
}
})
var filterName = 'treeTab' + item.accounttypeId
var productId = 'tab_' + item.accounttypeId + '_' + productData.productList[0].productId
active.tabChange(filterName, productId)
} else {
treeData[productData.accounttypeId] = {}
}
}
})
}
})
if (check_arr.length != 0) {
active.tabChange('roleAuth', check_arr[0].accounttypeId)
}
// $.each(menuFunTreeData, function(index, item) {
// if (roleid) {
// 角色权限的check
// for (var i = 0; i < check_arr.length; i++) {
// if (check_arr[i].accounttypeId == item.accounttypeId) {
// var productData = check_arr[i]
// str.attr('checked', true)
// var obj = { title: item.accounttypeName, value: item.accounttypeId }
// active.tabAdd(obj)
// var selectArr = []
// var menuData = []
// if (productData.productList) {
// for (var j = 0; j < productData.productList.length; j++) {
// menuData = productData.productList[j]
// selectArr.push(menuData.productId)
// active.treeTabAdd(
// {
// name: menuData.productName,
// value: menuData.productId
// },
// item.accounttypeId,
// item.products,
// menuData.idList
// )
// }
// selectEl[item.accounttypeId].setValue(selectArr)
// var filterName = 'treeTab' + item.accounttypeId
// var productId = 'tab_' + item.accounttypeId + '_' + item.products[0].productId
// console.log(filterName, productId)
// active.tabChange(filterName, productId)
// }
// }
// }
// if (check_arr.length != 0) {
// active.tabChange('roleAuth', check_arr[0].accounttypeId)
// }
// }
// })
form.render('checkbox')
}
})
}
// 根据id获取角色详情
function getById(id) {
var params = {
method: 'merchants.api.role.getById',
id: id
}
request(params, function (res) {
if (res.code == '0') {
var data = res.data
var accounttypeId = ''
if (data.responseList) {
check_arr = data.responseList
}
merchantId = data.merchantId
findMenuFunTreeByMerId(data.merchantId)
form.val('roleForm', {
roleName: data.roleName,
roleDescription: data.roleDescription,
merchantId: data.merchantId
})
}
})
}
// 获取角色权限数据requestList
function getAuthList() {
requestList = []
// check_arr.forEach(i => {
for (var key in treeData) {
var accountObj = treeData[key]
var productList = []
// if (i.accounttypeId == key) {
// if (Object.keys(accountObj).length != 0) {
for (var i in accountObj) {
var productObj = accountObj[i]
var menuIdList = []
var functionIdList = []
var functionIdLists = []
var functionValueIdLists = []
if (productObj.treeObj) {
var nodes = productObj.treeObj.getCheckedNodes(true)
$.each(nodes, function (index, item) {
if (item.logo == 'function') {
functionIdLists.push(item)
} else if (item.logo == 'functionValue') {
functionValueIdLists.push(item)
} else {
if (item.logo != 'neglect') {
menuIdList.push(item.id)
}
}
})
$.each(functionValueIdLists, function (idx, m) {
// m.parentId
var findIdx = -1
$.each(functionIdList, function (idn, n) {
if (n.id == m.parentId) {
findIdx = idn
}
})
if (findIdx != -1) {
functionIdList[findIdx].functionValue += ';' + m.id + ':' + m.label
} else {
functionIdList.push({
id: m.parentId,
menuId: m.superParentId,
functionValue: m.id + ':' + m.label
})
}
})
$.each(functionIdLists, function (idx, m) {
functionIdList.push({
id: m.parentId,
menuId: m.superParentId
})
})
productList.push({
productId: productObj.productId,
functionIdList: functionIdList,
menuIdList: menuIdList
})
} else {
productList.push({
productId: productObj.productId,
functionIdList: [],
menuIdList: []
})
}
}
requestList.push({
accountTypeId: key,
productList: productList
})
// }
// } else {
// requestList.push({
// accountTypeId: i.accounttypeId,
// productList: []
// })
// }
}
// })
}
// 查询所有商户
function findAllMerchant() {
var params = { method: 'merchants.api.menu.findAllMerchant' }
request(params, function (result) {
if (result.code == '0') {
merchantNameSelect.update({
data: result.data,
autoRow: true,
paging: result.data.length > 20
})
if (accountInfo && accountInfo.merchantAccountLevel == 4) {
const merchantName = result.data[0].merchantName
$('#merchantIdText').text(merchantName)
merchantId = result.data[0].id
$('#merchantIdText').removeClass('hide')
$('#merchantIdText').addClass('show')
$('#merchantNameSelect').remove()
findMenuFunTreeByMerId(merchantId)
// $('#merchantNameSelect').addClass('hide')
} else {
merchantNameSelect.setValue([merchantId])
$('#merchantSelect').removeClass('hide')
$('#merchantSelect').addClass('show')
}
// var list = result.data
// list.unshift('')
// $.each(list, function(index, item) {
// merchantName.append(new Option(item.merchantName, item.id))
// })
// form.render('select')
}
})
}
})
</script>
<script type="text/html" id="rolesAuth">
`
<div id="select{{d.id}}"></div>
<div class="layui-tab layui-tab-brief" lay-filter="treeTab{{d.id}}">
<ul class="layui-tab-title"></ul>
<div class="layui-tab-content"></div>
</div>
`
</script>
<script type="text/html" id="treeAuth">
<!-- <button class="layui-btn" data-type="{{d.id}}" id="checkedAll">全选</button>
<button class="layui-btn" id="cancelCheckedAll">取消全选</button> -->
<ul id="tree_{{d.id}}" class="ztree wrapper-tree"></ul>
<div class="layui-no-data show" id="nomenu{{d.id}}">
<div class="no-data">
<img src="../../css/img/no-data.png" />
<div>暂无可选择的菜单功能</div>
</div>
</div>
</script>
</body>
</html>