companyAuthority.html
5.83 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
<style>
.cmpy-auth-card {
width: 760px;
background: #fff;
margin: auto;
padding: 15px;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
}
.cmpy-auth-card .yunyin-company-panel:last-child {
border-bottom: none;
padding-bottom: 0px;
}
.yunyin-company-panel {
border-bottom: 1px solid #e9e5e5;
padding-bottom: 5px;
user-select:none;
}
.yunyin-company-panel .company {
font-size: 13px;
}
.yunyin-company-panel .sub-company {
display: inline-block;
text-align: center;
padding: 5px 15px;
border-radius: 5px !important;
color: #5d5c5c;
font-size: 13px;
background: linear-gradient(to bottom, #fafafa, #eeeeee);
cursor: pointer;
border: 1px solid #eeeeee;
}
.yunyin-company-panel .sub-company.active {
background: linear-gradient(to bottom, #2ab4c0, #229ea9);
color: #fdfdfd;
}
</style>
<div id="roleCompanyAuthority">
<div class="page-head">
<div class="page-title">
<h1>模块配置</h1>
</div>
</div>
<ul class="page-breadcrumb breadcrumb">
<li><a href="/pages/home.html" data-pjax>首页</a> <i
class="fa fa-circle"></i></li>
<li><span class="active">权限管理</span> <i class="fa fa-circle"></i></li>
<li><a href="list.html" data-pjax>角色管理</a> <i class="fa fa-circle"></i></li>
<li><span class="active">分公司数据权限</span></li>
</ul>
<div class="cmpy-auth-card">
<h4>角色信息</h4>
<table class="table">
<tr>
<td>
代码:<span id="roleCode"></span>
</td>
<td>
名称:<span id="roleName"></span>
</td>
</tr>
</table>
</div>
<br><br>
<div class="cmpy-auth-card cmpy-list">
</div>
<div class="cmpy-auth-card" style="text-align: right;">
<button type="button" class="btn btn-default">返回</button>
<button type="button" class="btn btn-primary saveBtn" ><i class="fa fa-check"></i>保存</button>
</div>
<script id="role-company-authority-temp" type="text/html">
{{each list as obj i}}
<div class="yunyin-company-panel">
<h5 class="company">{{obj.name}}</h5>
{{each obj.childs as fgs i}}
<div class="sub-company" data-company="{{obj.name}}" data-id="{{fgs.upCode}}_{{fgs.businessCode}}">{{fgs.businessName}}</div>
{{/each}}
</div>
{{/each}}
</script>
</div>
<script>
$(function () {
var id = $.url().param('no')
,roleObj;
if(!id){
alert('缺少主键');
}
else{
$.get('/role/'+id , function(obj){
$('#roleCompanyAuthority #roleCode').text(obj.codeName);
$('#roleCompanyAuthority #roleName').text(obj.roleName);
});
}
$.get('/business/all', function (rs) {
var baseCode;
//找到跟节点
$.each(rs, function () {
if(this.upCode == 0){
baseCode=this.businessCode;
return false;
}
});
if(!baseCode){
alert('大爷找不到跟节点,数据有问题吧!!!');
return;
}
//提取二级节点
var secondMap={};
$.each(rs, function () {
if(this.upCode==baseCode){
secondMap[this.businessCode] = {
name: this.businessName,
childs: []
};
}
});
//分公司节点
$.each(rs, function () {
if(secondMap[this.upCode])
secondMap[this.upCode].childs.push(this);
});
//排序
for(var sid in secondMap){
secondMap[sid].childs.sort(naturalSort);
}
var htmlStr=template('role-company-authority-temp', {list: get_vals(secondMap)});
$('#roleCompanyAuthority .cmpy-list').html(htmlStr);
//查询公司权限信息
$get('/companyAuthority/all', {roleId_eq: id}, function (rs) {
//console.log(rs);
var dataId;
$.each(rs, function () {
dataId=this.companyCode+'_'+this.subCompanyCode;
$('.cmpy-list div.sub-company[data-id='+dataId+']').addClass('active');
});
});
});
$('#roleCompanyAuthority').on('click', '.cmpy-list .sub-company', function () {
if($(this).hasClass('active'))
$(this).removeClass('active');
else
$(this).addClass('active');
});
var get_vals = function(json) {
var array = [];
for (var key in json) {
array.push(json[key]);
}
return array;
}
var naturalSort=function (a, b) {
return a.businessCode.localeCompare(b.businessCode);
}
//保存
$('#roleCompanyAuthority .saveBtn').on('click', function () {
var ats=$('.cmpy-list div.sub-company.active', '#roleCompanyAuthority')
,data=[];
var code;
$.each(ats, function () {
code = $(this).data('id').split('_');
data.push({
companyCode: code[0],
subCompanyCode: code[1],
companyName: $(this).data('company'),
subCompanyName: $(this).text()
});
});
$post('/companyAuthority/save', {roleId: id, authJsonStr: JSON.stringify(data)}, function (rs) {
alert('保存成功!');
})
});
});
</script>