提交 | 用户 | age
|
38b50d
|
1 |
<!DOCTYPE html> |
X |
2 |
<html lang="zh-cn"> |
|
3 |
<head> |
|
4 |
<meta charset="UTF-8"> |
|
5 |
<meta name="viewport" |
|
6 |
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> |
|
7 |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> |
|
8 |
<title>维护权限</title> |
|
9 |
<link rel="stylesheet" href="layui/css/layui.css"> |
|
10 |
<link rel="stylesheet" href="css/main.css"> |
|
11 |
</head> |
|
12 |
<body> |
|
13 |
|
|
14 |
<!--权限维护弹层--> |
ec748c
|
15 |
<div class="permission-container" style="display: block;"> |
38b50d
|
16 |
<div class="permission-body"> |
X |
17 |
<div class="permission-title">选择人员与权限</div> |
|
18 |
<div class="layui-row staff-container flex"> |
|
19 |
<div class="layui-form list-body" lay-filter="form-staff"> |
|
20 |
<div class="layui-input-inline search-div"> |
|
21 |
<input type="search" id="search-input" name="search" autocomplete="off" class="layui-input" placeholder="请输入员工姓名"/> |
|
22 |
<i class="layui-icon layui-icon-search" style=""></i> |
|
23 |
</div> |
|
24 |
<div class="staff-list"> |
ec748c
|
25 |
|
38b50d
|
26 |
</div> |
X |
27 |
</div> |
|
28 |
<div class="flex flex-1 table-body"> |
|
29 |
|
|
30 |
<table class="layui-hide" id="table" lay-filter="table"></table> |
ec748c
|
31 |
<script type="text/html" id="checkboxHasView"> |
e81b7d
|
32 |
<input type="checkbox" name="lock" value="{{d.hasView}}" class="checkboxHasView" lay-skin="primary" lay-filter="checkboxHasView" {{ d.hasView ? 'checked' : '' }} {{ d.hasAuthor ? 'disabled' : '' }}> |
38b50d
|
33 |
</script> |
ec748c
|
34 |
<script type="text/html" id="checkboxHasDownload"> |
e81b7d
|
35 |
<input type="checkbox" name="lock" value="{{d.hasDownload}}" class="checkboxHasDownload" lay-skin="primary" lay-filter="checkboxHasDownload" {{ d.hasDownload ? 'checked' : '' }} {{ d.hasAuthor ? 'disabled' : '' }}> |
38b50d
|
36 |
</script> |
ec748c
|
37 |
<script type="text/html" id="checkboxHasDelete"> |
e81b7d
|
38 |
<input type="checkbox" name="lock" value="{{d.hasDelete}}" class="checkboxHasDelete" lay-skin="primary" lay-filter="checkboxHasDelete" {{ d.hasDelete ? 'checked' : '' }} {{ d.hasAuthor ? 'disabled' : '' }}> |
38b50d
|
39 |
</script> |
ec748c
|
40 |
|
38b50d
|
41 |
<div class="period-date" id="period-date"> |
X |
42 |
<script type="text/html" id="start-date"> |
|
43 |
<div class="layui-input-inline relative"> |
|
44 |
<i class="layui-icon layui-icon-time"></i> |
e81b7d
|
45 |
<input type="text" autocomplete="off" id="period-startDate" readonly value="{{d.startDate}}" class="layui-input period-date period-startDate" placeholder="开始时间" {{ d.hasAuthor ? 'disabled' : '' }}> |
38b50d
|
46 |
</div> |
X |
47 |
</script> |
|
48 |
<script type="text/html" id="end-date" > |
|
49 |
<div class="layui-input-inline relative"> |
|
50 |
<i class="layui-icon layui-icon-time"></i> |
e81b7d
|
51 |
<input type="text" autocomplete="off" id="period-endDate" readonly value="{{d.endDate}}" class="layui-input period-date period-endDate" placeholder="结束时间" {{ d.hasAuthor ? 'disabled' : '' }}> |
38b50d
|
52 |
</div> |
X |
53 |
</script> |
|
54 |
</div> |
ec748c
|
55 |
|
0046a7
|
56 |
<script type="text/html" id="dateFlag" > |
X |
57 |
<div class="selectDateFlag"> |
|
58 |
<select name="dateFlag" lay-filter="dateFlags" {{ d.hasAuthor ? 'disabled' : '' }}> |
|
59 |
<option value=""></option> |
|
60 |
<option value="0" {{d.dateFlag ==0 ?'selected':''}}>按每天时间段授权</option> |
|
61 |
<option value="1" {{d.dateFlag ==1 ?'selected':''}}>按连续时间授权</option> |
|
62 |
<option value="2" {{d.dateFlag ==2 ?'selected':''}}>无时间限制</option> |
|
63 |
</select> |
|
64 |
</div> |
|
65 |
</script> |
|
66 |
</div> |
ec748c
|
67 |
|
38b50d
|
68 |
<!-- 限制次数 --> |
ec748c
|
69 |
|
X |
70 |
<script type="text/html" id="allowDownNums"> |
0046a7
|
71 |
<input type="number" id="allowDownNums-input" name="search" title="0表示无限制" autocomplete="off" class="layui-input allowDownNumsTimes-input" value="{{d.allowDownNums}}" {{ d.hasAuthor ? 'disabled' : '' }}/> |
38b50d
|
72 |
</script> |
ec748c
|
73 |
<script type="text/html" id="allowViewNums"> |
0046a7
|
74 |
<input type="number" id="allowViewNums-input" name="search" title="0表示无限制" autocomplete="off" class="layui-input allowViewNumsTimes-input" value="{{d.allowViewNums}}" {{ d.hasAuthor ? 'disabled' : '' }}/> |
38b50d
|
75 |
</script> |
X |
76 |
|
|
77 |
<script type="text/html" id="barDemo"> |
e81b7d
|
78 |
<i class="layui-icon layui-icon-close pointer" lay-event="del" title="确认后才生效" style="display: {{ d.hasAuthor ? 'none' : 'block' }}"></i> |
38b50d
|
79 |
<!-- <a class="layui-btn layui-btn-danger layui-btn-xs" >删除</a>--> |
X |
80 |
</script> |
|
81 |
</div> |
|
82 |
|
|
83 |
</div> |
0046a7
|
84 |
<div class="layer-footer flex flex-end" style="padding-right: 20px"> |
38b50d
|
85 |
<button type="button" class="layui-btn layui-btn-primary" id="cancelBtn">取消</button> |
X |
86 |
<button type="button" class="layui-btn layui-btn-normal" id="enterBtn">确认</button> |
|
87 |
</div> |
|
88 |
</div> |
|
89 |
</div> |
ec748c
|
90 |
<!--<script src="http://rf.onbus.cn/shopping/view/javascript/jquery/jquery-2.1.1.min.js"--> |
X |
91 |
<!-- type="text/javascript"></script>--> |
|
92 |
<script src="/help/js/JQuery-3.6.0.js" type="text/javascript"></script> |
38b50d
|
93 |
<script src="layui/layui.js" type="text/javascript"></script> |
X |
94 |
<script> |
|
95 |
$(function () { |
|
96 |
var Dom = { |
|
97 |
searchInput: $('#search-input'), // 搜索框 |
|
98 |
staffList: $('.staff-list'), // 人员列表 |
|
99 |
cancelBtn: $('#cancelBtn'), // 取消按钮 |
|
100 |
enterBtn: $('#enterBtn'), // 确认按钮 |
|
101 |
}; |
|
102 |
var layer = layui.layer; |
|
103 |
var form = layui.form; |
|
104 |
var table = layui.table; |
|
105 |
var laydate = layui.laydate; |
|
106 |
var layerIndex = 0; //它是layer.close(index)等方法的必传参数。 |
|
107 |
var staffData = []; //左侧人员列表数据 |
|
108 |
var permissionData = []; //右侧表格权限数据 |
ec748c
|
109 |
var unid=getUrlParam("unid"); |
X |
110 |
var seq=getUrlParam("seq"); |
|
111 |
var operationType=false;//初始,查询,清空查询 |
38b50d
|
112 |
|
X |
113 |
//获取后台人员列表数据 |
|
114 |
getStaffData(); |
|
115 |
|
|
116 |
// 搜索框搜索 |
|
117 |
// 回车搜索 |
|
118 |
$('.search-div').keydown(function(event){ |
|
119 |
if(event.keyCode == 13){ |
|
120 |
searchRequest() |
|
121 |
} |
|
122 |
}) |
|
123 |
// 按钮搜索 |
|
124 |
$('.search-div i').on('click', function(){ |
|
125 |
searchRequest() |
|
126 |
}) |
|
127 |
|
|
128 |
// 输入框为空时还原人员列表数据 |
|
129 |
Dom.searchInput.on('input',function () { |
|
130 |
var val = $(this).val(); |
|
131 |
if (val.trim()==''){ |
ec748c
|
132 |
operationType=true; |
X |
133 |
getStaffData(""); |
|
134 |
// initStaffData() |
38b50d
|
135 |
} |
X |
136 |
}) |
|
137 |
|
|
138 |
// 发送搜索请求 |
|
139 |
function searchRequest() { |
|
140 |
var keyword = Dom.searchInput.val().trim() |
ec748c
|
141 |
operationType=true; |
X |
142 |
getStaffData(keyword); |
|
143 |
// console.log(keyword); |
|
144 |
// searchStaffData(keyword); |
38b50d
|
145 |
} |
ec748c
|
146 |
|
38b50d
|
147 |
|
X |
148 |
// 左侧选择部门事件 |
|
149 |
form.on('checkbox(departmentCheckbox)', function(data){ |
|
150 |
var thisCheckbox = $(this); |
|
151 |
var checked = data.elem.checked; //是否被选中,true或者false |
|
152 |
var index = thisCheckbox.data('index'); |
ec748c
|
153 |
var selectedData = staffData[index].info; |
38b50d
|
154 |
staffData[index].checked = checked; |
X |
155 |
var memberListEle = $('.staff-list .child-ul').eq(index).find('.memberChecked'); // 部门成员列表dom |
|
156 |
if (checked){ // 处理部门下的人员全选 |
|
157 |
selectedData.forEach(function (item,i) { |
|
158 |
// item.parentIndex = index; |
|
159 |
// item.index = i; |
|
160 |
// var checked = $('.layui-row').eq(index).find('.layui-row .memberChecked').eq(i); |
|
161 |
var checkbox = memberListEle.eq(i); |
|
162 |
var checked = checkbox.is(':checked'); |
|
163 |
// 非选择状态就添加选中并加入右侧表格 |
|
164 |
if (!checked){ |
|
165 |
item.checked = true; |
|
166 |
checkbox.prop('checked',true); |
|
167 |
permissionData.push(JSON.parse(JSON.stringify(item))); |
|
168 |
} |
|
169 |
}) |
|
170 |
form.render('checkbox'); |
|
171 |
permissionTable.reload({}); |
|
172 |
} else { // 取消部门下的人员全选 |
|
173 |
selectedData.forEach(function (item,i) { |
|
174 |
// item.parentIndex = index; |
|
175 |
// item.index = i; |
|
176 |
var indexStr = index.toString()+i.toString(); |
|
177 |
var checkbox = memberListEle.eq(i); |
|
178 |
var checked = checkbox.is(':checked'); |
|
179 |
// 对选中状态的取消选中,并删除表格内对应条目 |
|
180 |
if (checked){ |
|
181 |
item.checked = false; |
|
182 |
checkbox.prop('checked',false); |
|
183 |
var idx = 0; |
|
184 |
permissionData.forEach(function (item,index) { |
|
185 |
if (indexStr===item.parentIndex.toString()+item.index.toString()){idx = index;} |
|
186 |
}) |
|
187 |
permissionData.splice(idx,1); |
|
188 |
} |
|
189 |
}) |
|
190 |
form.render('checkbox'); |
|
191 |
// console.log(permissionData); |
|
192 |
permissionTable.reload({}); |
|
193 |
} |
|
194 |
}); |
ec748c
|
195 |
|
38b50d
|
196 |
// 左侧选择人员事件 |
X |
197 |
form.on('checkbox(staffCheckbox)', function(data){ |
|
198 |
var checkbox = $(this); |
|
199 |
var checked = data.elem.checked; //是否被选中,true或者false |
|
200 |
var parentIndex = checkbox.data('parentIndex'); |
|
201 |
var index = checkbox.data('index'); |
ec748c
|
202 |
var selectedData = staffData[parentIndex].info[index]; |
38b50d
|
203 |
selectedData.parentIndex = parentIndex; |
X |
204 |
selectedData.index = index; |
|
205 |
selectedData.checked = checked; |
|
206 |
if (checked){ // 被选中放入表格列表数据 |
|
207 |
permissionData.push(JSON.parse(JSON.stringify(selectedData))); |
|
208 |
permissionTable.reload({}); |
|
209 |
// 当前部门人员全选时,为当前部门添加选中 |
|
210 |
var checkedLength = 0; |
|
211 |
$('.staff-list .child-ul').eq(parentIndex).find('.memberChecked').each(function () { |
|
212 |
if (this.checked) checkedLength++; |
|
213 |
}) |
ec748c
|
214 |
if (checkedLength == staffData[parentIndex].info.length){ |
38b50d
|
215 |
$('.departmentChecked').eq(parentIndex).prop('checked',true); |
X |
216 |
staffData[parentIndex].checked = true; |
|
217 |
form.render('checkbox'); |
|
218 |
} |
|
219 |
// $('.departmentChecked').eq(parentIndex).prop('checked',false); |
|
220 |
} else { // 取消选中删除表格列表数据 |
|
221 |
var indexStr = parentIndex.toString()+index.toString(); |
|
222 |
var i = 0; |
|
223 |
permissionData.forEach(function (item,index) { |
|
224 |
if (indexStr===item.parentIndex.toString()+item.index.toString()){i = index;} |
|
225 |
}) |
|
226 |
permissionData.splice(i,1); |
|
227 |
// console.log(permissionData); |
|
228 |
permissionTable.reload({}); |
|
229 |
// 取消当前部门选中 |
|
230 |
$('.departmentChecked').eq(parentIndex).prop('checked',false); |
|
231 |
staffData[parentIndex].checked = false; |
|
232 |
form.render('checkbox') |
|
233 |
} |
|
234 |
// console.log($(this).data('parentIndex')); |
|
235 |
// console.log($(this).data('index')); |
|
236 |
// console.log('选中的数据',staffData[parentIndex].member[index]); |
|
237 |
}); |
ec748c
|
238 |
|
X |
239 |
|
38b50d
|
240 |
|
X |
241 |
var permissionTable = null; |
|
242 |
//表格相关 |
|
243 |
layui.use(['table'], function(){ |
|
244 |
// 创建渲染实例 |
|
245 |
permissionTable = table.render({ |
|
246 |
elem: '#table', |
|
247 |
data: permissionData, |
|
248 |
height: '450px', |
|
249 |
skin:'nob', |
|
250 |
text: {none: '请选择人员'}, |
|
251 |
editTrigger: 'click', |
ec748c
|
252 |
limit:100, |
38b50d
|
253 |
cols: [[ |
X |
254 |
// {type: 'checkbox', fixed: 'left'},deleteTableRow |
0046a7
|
255 |
{field:'userName', width:'10%', title: '用户', align:'center'}, |
X |
256 |
{field:'hasView', title:'查看', width:'6%', align:'center', toolbar: '#checkboxHasView'}, |
|
257 |
{field:'hasDownload', title:'下载', width:'6%', align:'center', toolbar: '#checkboxHasDownload'}, |
|
258 |
{field:'hasDelete',title:'删除', width:'6%', align:'center', toolbar: '#checkboxHasDelete'}, |
15cb62
|
259 |
{field: 'dateFlag', title:'时间控制方式', width:'16%',align:'center', toolbar: '#dateFlag'}, |
0046a7
|
260 |
{field: 'startDate', title:'开始时间', width:'15%',align:'center', toolbar: '#start-date'}, |
X |
261 |
{field: 'endDate', title:'结束时间', width:'15%',align:'center', toolbar: '#end-date'}, |
|
262 |
{field: 'allowDownNums', title:'允许下载次数', width:'12%',align:'center', toolbar: '#allowDownNums'}, |
|
263 |
{field: 'allowViewNums', title:'允许查看次数', width:'12%',align:'center', toolbar: '#allowViewNums'}, |
|
264 |
{ title:'', width:'3%', toolbar: '#barDemo', align:'center'} |
38b50d
|
265 |
]], |
X |
266 |
done: function(){ |
|
267 |
var id = this.id; |
|
268 |
// 监听时间选择 |
|
269 |
listenPermissionTime('start'); |
|
270 |
listenPermissionTime('end'); |
ec748c
|
271 |
|
0046a7
|
272 |
listenPermissionSelect('dateFlag'); |
38b50d
|
273 |
|
X |
274 |
// 监听查看、下载、删除CheckBox选择 |
ec748c
|
275 |
listenPermissionCheckbox('hasView'); |
X |
276 |
listenPermissionCheckbox('hasDownload'); |
|
277 |
listenPermissionCheckbox('hasDelete'); |
38b50d
|
278 |
|
X |
279 |
// 监听下载和查看次数Input输入 |
ec748c
|
280 |
listenPermissionInput('allowViewNums'); |
X |
281 |
listenPermissionInput('allowDownNums'); |
|
282 |
|
0046a7
|
283 |
$(".layui-table-body, .layui-table-box, .layui-table-cell").css('overflow', 'visible'); |
38b50d
|
284 |
} |
X |
285 |
,error: function(res, msg){ |
ec748c
|
286 |
// console.log(res, msg) |
38b50d
|
287 |
} |
X |
288 |
}); |
|
289 |
|
ec748c
|
290 |
|
38b50d
|
291 |
//触发单元格工具事件 |
X |
292 |
table.on('tool(table)', function(obj){ |
|
293 |
var data = obj.data; |
ec748c
|
294 |
// console.log('触发单元格工具事件',data,obj) |
38b50d
|
295 |
if(obj.event === 'del'){ |
X |
296 |
var i = $('td i.layui-icon-close').index($(this)); |
ec748c
|
297 |
// console.log('当前行',i); |
38b50d
|
298 |
layer.confirm('真的删除行么', function(index){ |
418160
|
299 |
let j=permissionData[i]; |
X |
300 |
let json={}; |
|
301 |
json.unid=unid; |
|
302 |
json.seq=seq; |
|
303 |
json.userCode=j.userCode; |
|
304 |
$.ajax({ |
|
305 |
url: '/attachmentOa/deleteAttachmentOa.do', |
|
306 |
type: 'POST', |
|
307 |
data: JSON.stringify(json), |
|
308 |
dataType: 'json', |
|
309 |
contentType: 'application/json', |
|
310 |
success: function (res) { |
|
311 |
if (res != null && res.code == 0) { |
|
312 |
layui.layer.msg(res.data); |
|
313 |
// obj.del(); |
|
314 |
permissionData.splice(i,1); |
|
315 |
permissionTable.reload({}); |
ec748c
|
316 |
|
418160
|
317 |
layer.close(index); |
X |
318 |
// 获取对应的左侧人员CheckBox |
|
319 |
var checkbox = $('.staff-list .child-ul').eq(data.parentIndex).find('.memberChecked').eq(data.index) |
|
320 |
// console.log('input input',checkbox); |
|
321 |
checkbox.prop('checked',false); |
|
322 |
// 取消部门选中 |
|
323 |
$('.departmentChecked').eq(data.parentIndex).prop('checked',false); |
|
324 |
form.render('checkbox'); |
|
325 |
} else { |
|
326 |
layui.layer.alert(res.data); |
|
327 |
} |
|
328 |
// top.layer.closeAll(); |
|
329 |
}, error: function (xmlHttpRequest, textStatus, errorThrown) { |
|
330 |
layui.layer.alert(xmlHttpRequest.responseText); |
|
331 |
} |
|
332 |
}) |
38b50d
|
333 |
}); |
X |
334 |
} |
|
335 |
}); |
|
336 |
}); |
|
337 |
|
|
338 |
// 表格右下方表单按钮 |
|
339 |
// 取消按钮 |
|
340 |
Dom.cancelBtn.on('click', function () { |
e81b7d
|
341 |
parent.layer.closeAll(); |
38b50d
|
342 |
}); |
X |
343 |
// 确认按钮 |
|
344 |
Dom.enterBtn.on('click', function () { |
ec748c
|
345 |
// console.log('待提交的数据',permissionData); |
X |
346 |
let param = {}; |
|
347 |
param.unid = unid; |
|
348 |
param.seq = seq; |
|
349 |
param.oaEntities = permissionData; |
|
350 |
$.ajax({ |
|
351 |
url: '/attachmentOa/setUserOA.do', |
|
352 |
type: 'POST', |
|
353 |
data: JSON.stringify(param), |
|
354 |
dataType: 'json', |
|
355 |
contentType: 'application/json', |
|
356 |
success: function (res) { |
|
357 |
if (res != null && res.code == 0) { |
|
358 |
layui.layer.alert(res.data,function () { |
|
359 |
location.reload(); |
|
360 |
}); |
|
361 |
} else { |
|
362 |
layui.layer.alert(res.data); |
|
363 |
} |
|
364 |
// top.layer.closeAll(); |
|
365 |
}, error: function (xmlHttpRequest, textStatus, errorThrown) { |
|
366 |
layui.layer.alert(xmlHttpRequest.responseText); |
|
367 |
} |
|
368 |
}) |
38b50d
|
369 |
}); |
X |
370 |
|
ec748c
|
371 |
|
X |
372 |
//获取url中的参数 |
|
373 |
function getUrlParam(name) { |
|
374 |
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 |
|
375 |
var r = window.location.search.substr(1).match(reg); //匹配目标参数 |
|
376 |
if (r != null) return unescape(r[2]); return null; //返回参数值 |
|
377 |
} |
38b50d
|
378 |
|
X |
379 |
//获取后台数据 |
|
380 |
function getStaffData(keyword) { |
|
381 |
$.ajax({ |
ec748c
|
382 |
url: '/attachmentOa/userInfo.do?unid=' + unid + '&seq=' + seq + '&keyword=' + (keyword == undefined ? '' : keyword), |
38b50d
|
383 |
type: 'GET', |
ec748c
|
384 |
contentType: 'application/json', |
X |
385 |
success: function (res) { |
|
386 |
if (res.code === -1) { |
|
387 |
layui.layer.alert(res.data); |
|
388 |
|
38b50d
|
389 |
} else { |
X |
390 |
staffData = res.data; |
|
391 |
// Dom.staffList.append(staffListDom(data)); |
ec748c
|
392 |
|
X |
393 |
initStaffData(keyword); |
38b50d
|
394 |
} |
X |
395 |
}, |
ec748c
|
396 |
error: function (XMLHttpRequest, textStatus, errorThrown) { |
X |
397 |
// console.log("请求错误",XMLHttpRequest, textStatus, errorThrown); |
|
398 |
layui.layer.alert("请求错误:" + XMLHttpRequest + '</br>' + errorThrown + '</br>'); |
38b50d
|
399 |
} |
X |
400 |
}); |
|
401 |
} |
ec748c
|
402 |
|
38b50d
|
403 |
|
X |
404 |
// 生成左侧人员列表Dom字符串 |
|
405 |
function staffListDom(data,isSearch) { |
|
406 |
var str = '<ul>'; |
|
407 |
for (let i = 0; i < data.length; i++) { |
|
408 |
var item = data[i]; |
|
409 |
var liStr = |
|
410 |
`<li class="layui-row ${ item.hidden ? 'hidden-el' : '' }"> |
|
411 |
<div class="layui-col-md2"> |
|
412 |
<input type="checkbox" class="departmentChecked" name="departmentChecked${i}" lay-filter="departmentCheckbox" lay-skin="primary" data-index="${i}" data-department='${JSON.stringify(item)}' ${ item.checked ? 'checked' : '' } ${isSearch?"disabled":''}> |
|
413 |
</div> |
ec748c
|
414 |
<div class="layui-col-md10 department-title">${item.ccName}</div>`; |
38b50d
|
415 |
|
ec748c
|
416 |
if (item.info&&item.info.length>0){ |
38b50d
|
417 |
var memberUlStr = '<ul class="child-ul">' |
ec748c
|
418 |
for (let j = 0; j < item.info.length; j++) { |
X |
419 |
var memberItem = item.info[j]; |
e81b7d
|
420 |
let isAuthor=memberItem.hasAuthor; |
38b50d
|
421 |
|
X |
422 |
var memberLiStr = |
|
423 |
`<li class="layui-row ${ memberItem.hidden ? 'hidden-el' : '' }"> |
|
424 |
<div class="layui-col-md2"> |
e81b7d
|
425 |
<input type="checkbox" class="memberChecked" name="memberChecked${j}" lay-filter="staffCheckbox" lay-skin="primary" data-parent-index="${i}" data-index="${j}" data-member='${JSON.stringify(memberItem)}' ${ memberItem.checked ? 'checked' : '' } ${isAuthor?"disabled":''}> |
38b50d
|
426 |
</div> |
ec748c
|
427 |
<div class="layui-col-md10 staff-title">${memberItem.userName}</div> |
38b50d
|
428 |
</li>` |
X |
429 |
memberUlStr+=memberLiStr; |
|
430 |
} |
|
431 |
liStr+=memberUlStr+'</ul>'; |
|
432 |
} |
|
433 |
str+=liStr |
|
434 |
} |
|
435 |
str+='</ul>' |
ec748c
|
436 |
// console.log(str); |
38b50d
|
437 |
return str; |
X |
438 |
} |
|
439 |
|
|
440 |
// 初始化人员列表数据 |
ec748c
|
441 |
// function initStaffData() { |
X |
442 |
// staffData.forEach(function (item,index) { |
|
443 |
// // delete item.hidden; |
|
444 |
// item.info.forEach(function (member,i) { |
|
445 |
// member.parentIndex = index; |
|
446 |
// member.index = i; |
|
447 |
// delete member.hidden; |
|
448 |
// // if (member.checked){ |
|
449 |
// // permissionData.push(JSON.parse(JSON.stringify(member))); |
|
450 |
// // permissionTable.reload({}); |
|
451 |
// // } |
|
452 |
// }) |
|
453 |
// }) |
|
454 |
// Dom.staffList.empty(); |
|
455 |
// Dom.staffList.append(staffListDom(staffData)); |
|
456 |
// form.render('checkbox'); |
|
457 |
// console.log('初始化后的staffData',staffData); |
|
458 |
// } |
|
459 |
// 初始化人员列表数据 |
|
460 |
// function initStaffData() { |
|
461 |
// staffData.forEach(function (item,index) { |
|
462 |
// var isCheckDepartment = item.checked; |
|
463 |
// delete item.hidden; |
|
464 |
// item.info.forEach(function (member,i) { |
|
465 |
// member.parentIndex = index; |
|
466 |
// member.index = i; |
|
467 |
// delete member.hidden; |
|
468 |
// if (isCheckDepartment){ |
|
469 |
// permissionData.push(JSON.parse(JSON.stringify(member))); |
|
470 |
// permissionTable.reload({}); |
|
471 |
// } else { |
|
472 |
// if (member.checked){ |
|
473 |
// permissionData.push(JSON.parse(JSON.stringify(member))); |
|
474 |
// permissionTable.reload({}); |
|
475 |
// } |
|
476 |
// } |
|
477 |
// |
|
478 |
// }) |
|
479 |
// }) |
|
480 |
// Dom.staffList.empty(); |
|
481 |
// Dom.staffList.append(staffListDom(staffData)); |
|
482 |
// form.render('checkbox'); |
|
483 |
// // console.log('初始化后的staffData',staffData); |
|
484 |
// } |
|
485 |
// 初始化人员列表数据 |
|
486 |
function initStaffData(keyword) { |
|
487 |
// var userCodes = []; |
|
488 |
if (operationType) { |
|
489 |
handleSearchData(); |
|
490 |
} else { |
|
491 |
staffData.forEach(function (item, index) { |
|
492 |
var isCheckDepartment = item.checked; |
|
493 |
delete item.hidden; |
|
494 |
item.info.forEach(function (member, i) { |
|
495 |
member.parentIndex = index; |
|
496 |
member.index = i; |
|
497 |
delete member.hidden; |
|
498 |
if (isCheckDepartment) { |
|
499 |
checkRepeatMember(member) |
|
500 |
} else { |
|
501 |
if (member.checked) { |
|
502 |
checkRepeatMember(member) |
|
503 |
} |
|
504 |
} |
|
505 |
}) |
|
506 |
permissionTable.reload({}); |
|
507 |
}) |
|
508 |
} |
|
509 |
|
|
510 |
if (operationType && keyword == "") { |
|
511 |
operationType = false; |
|
512 |
} |
|
513 |
Dom.staffList.empty(); |
|
514 |
Dom.staffList.append(staffListDom(staffData, operationType)); |
|
515 |
form.render('checkbox'); |
|
516 |
operationType=false; |
|
517 |
// console.log('初始化后的staffData', staffData); |
|
518 |
} |
|
519 |
|
|
520 |
function handleSearchData(){ |
|
521 |
var userCodes = []; |
|
522 |
for (let i = 0; i < permissionData.length; i++) { |
|
523 |
var item = permissionData[i]; |
|
524 |
userCodes.push(item.userCode) |
|
525 |
} |
38b50d
|
526 |
staffData.forEach(function (item,index) { |
ec748c
|
527 |
item.info.forEach(function (member,i) { |
38b50d
|
528 |
member.parentIndex = index; |
X |
529 |
member.index = i; |
ec748c
|
530 |
if (userCodes.includes(member.userCode)){ |
X |
531 |
member.checked = true |
|
532 |
} |
38b50d
|
533 |
}) |
X |
534 |
}) |
|
535 |
} |
ec748c
|
536 |
|
X |
537 |
function checkRepeatMember(member){ |
|
538 |
var userCodes = []; |
|
539 |
if (permissionData.length<1) { |
|
540 |
permissionData.push(JSON.parse(JSON.stringify(member))); |
|
541 |
} else { |
|
542 |
for (let i = 0; i < permissionData.length; i++) { |
|
543 |
var item = permissionData[i]; |
|
544 |
userCodes.push(item.userCode) |
|
545 |
} |
|
546 |
if (!userCodes.includes(member.userCode)){ |
|
547 |
permissionData.push(JSON.parse(JSON.stringify(member))); |
|
548 |
} |
|
549 |
|
|
550 |
} |
|
551 |
|
|
552 |
} |
|
553 |
|
|
554 |
|
38b50d
|
555 |
//搜索指定人员 |
X |
556 |
function searchStaffData(keyword) { |
|
557 |
var hasMatch = true; |
|
558 |
staffData.forEach(function (item) { |
ec748c
|
559 |
var length = item.info.length; // 记录匹配结果数 |
38b50d
|
560 |
// matchMemberData内有匹配人员时,所在部门也要显示 |
X |
561 |
item.member.forEach(function (member,i) { |
|
562 |
// console.log(member.username); |
|
563 |
hasMatch = new RegExp(keyword,'gm').test(member.username); |
|
564 |
// console.log(hasMatch); |
|
565 |
// 如果没有匹配,给当前人员添加隐藏属性 |
|
566 |
if (!hasMatch){ |
|
567 |
member.hidden = true; |
|
568 |
length--; |
|
569 |
} |
|
570 |
// hasMatch = false; |
|
571 |
}) |
|
572 |
// 如果全员未匹配,部门也要隐藏 |
|
573 |
if (length<1) { |
|
574 |
item.hidden = true; |
|
575 |
} |
ec748c
|
576 |
|
38b50d
|
577 |
}) |
X |
578 |
// console.log('匹配结果',matchMemberData); |
ec748c
|
579 |
// console.log('搜索匹配结果后',staffData); |
38b50d
|
580 |
Dom.staffList.empty(); |
X |
581 |
Dom.staffList.append(staffListDom(staffData,true)); |
|
582 |
form.render('checkbox'); |
|
583 |
} |
|
584 |
|
|
585 |
// 监听表格内权限选择事件 |
|
586 |
// type可取值为view(是否可查看)、download(是否可下载)、delete(是否可删除) |
|
587 |
function listenPermissionCheckbox(type) { |
|
588 |
var _type = type[0].toUpperCase()+type.substr(1); |
|
589 |
// console.log(_type,type); |
|
590 |
form.on('checkbox(checkbox'+_type+')', function(data){ |
|
591 |
var isChecked = data.elem.checked; |
|
592 |
// console.log(data.elem.checked); //是否被选中,true或者false |
|
593 |
// console.log(data.value); //复选框value值,也可以通过data.elem.value得到 |
|
594 |
var idx = $('.checkbox'+_type+'').index($(this)); |
|
595 |
permissionData[idx][type] = isChecked; |
ec748c
|
596 |
// console.log('获取修改权限CheckBox后的表格数据',idx,permissionData); |
38b50d
|
597 |
}); |
X |
598 |
} |
|
599 |
|
|
600 |
// 监听表格内时间段选择事件 |
|
601 |
// type可取值为start(开始时间)、end(结束时间) |
|
602 |
function listenPermissionTime(type) { |
|
603 |
// console.log(_type,type); |
|
604 |
$('.period-'+type+'Date').each(function (index) { |
|
605 |
var _this = this; |
|
606 |
laydate.render({ |
|
607 |
elem: _this, |
0046a7
|
608 |
type:'datetime', |
38b50d
|
609 |
// elem: '.layui-table', |
X |
610 |
// range: ['.period-startDate', '.period-endDate'], |
|
611 |
// trigger: 'click',//可以解决多个实例闪退问题 |
|
612 |
// isInitValue: false,//初始值填充 |
|
613 |
// value:$('#TimeVal'+index).text(), |
|
614 |
ready: function (date) {//初始回调 |
0046a7
|
615 |
console.log('初始:', date); //得到初始的日期时间对象:{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0} |
38b50d
|
616 |
}, |
X |
617 |
change: function (value, date, endDate) {//选择切换回调 |
ec748c
|
618 |
// console.log('选择切换回调:',value,date,endDate); //得到日期生成的值,如:2017-08-18 |
38b50d
|
619 |
}, |
X |
620 |
done: function (value, date) { |
|
621 |
// console.log(value, date,index); |
ec748c
|
622 |
permissionData[index][type+'Date'] = value;//Date.parse(value);//时间戳 |
X |
623 |
var startTime = new Date(permissionData[index].startDate).getTime(); |
|
624 |
var endTime = new Date(permissionData[index].endDate).getTime(); |
38b50d
|
625 |
// console.log(startTime,endTime); |
X |
626 |
// 判断时间是否合理 |
|
627 |
if (startTime&&endTime&&endTime<startTime){ |
|
628 |
layer.tips('结束时间不能小于开始时间', _this, { |
|
629 |
tips: [1, '#3595CC'], |
|
630 |
// closeBtn: 2, |
|
631 |
time: 5000 |
|
632 |
}); |
|
633 |
} else { |
|
634 |
layer.closeAll('tips'); |
|
635 |
} |
ec748c
|
636 |
// console.log('获取修改时间后的表格数据',index,permissionData); |
38b50d
|
637 |
} |
X |
638 |
}); |
|
639 |
}); |
|
640 |
} |
0046a7
|
641 |
//监听下拉选择值 |
X |
642 |
function listenPermissionSelect(type) { |
|
643 |
form.on('select(dateFlags)', function(data){ |
|
644 |
let v= $(this).closest('.selectDateFlag'); |
|
645 |
let index=$('.selectDateFlag').index(v); |
|
646 |
permissionData[index][type] = data.value; |
|
647 |
}); |
|
648 |
} |
38b50d
|
649 |
// 监听表格内权限输入框事件 |
X |
650 |
// type可取值为download(可下载次数)、view(可查看次数) |
|
651 |
function listenPermissionInput(type) { |
|
652 |
// console.log(_type,type); |
|
653 |
$('.'+type+'Times-input').blur(function(){ |
|
654 |
//获取input输入的值 |
|
655 |
var val = $(this).val(); |
ec748c
|
656 |
// console.log(val); |
38b50d
|
657 |
var idx = $('.'+type+'Times-input').index($(this)); |
ec748c
|
658 |
permissionData[idx][type] = Number(val); |
X |
659 |
// console.log('获取修改权限次数后的表格数据',idx,permissionData); |
38b50d
|
660 |
}); |
X |
661 |
|
|
662 |
} |
|
663 |
|
|
664 |
}); |
|
665 |
|
|
666 |
</script> |
|
667 |
|
|
668 |
|
|
669 |
</body> |
|
670 |
</html> |