multiTree.html
2.78 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
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('部门树选择')" />
<th:block th:include="include :: ztree-css" />
</head>
<style>
body{height:auto;font-family: "Microsoft YaHei";}
button{font-family: "SimSun","Helvetica Neue",Helvetica,Arial;}
</style>
<body class="hold-transition box box-main">
<input id="treeId" name="treeId" type="hidden" th:value="${multiDept.ids}"/>
<input id="treeName" name="treeName" type="hidden" th:value="${multiDept.names}"/>
<div class="wrapper"><div class="treeShowHideButton" onclick="$.tree.toggleSearch();">
<label id="btnShow" title="显示搜索" style="display:none;">︾</label>
<label id="btnHide" title="隐藏搜索">︽</label>
</div>
<div class="treeSearchInput" id="search">
<label for="keyword">关键字:</label><input type="text" class="empty" id="keyword" maxlength="50">
<button class="btn" id="btn" onclick="$.tree.searchNode()"> 搜索 </button>
</div>
<div class="treeExpandCollapse">
<a href="javascript:;" onclick="$.tree.expand()">展开</a> /
<a href="javascript:;" onclick="$.tree.collapse()">折叠</a>
</div>
<div id="tree" class="ztree treeselect"></div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: ztree-js" />
<script th:inline="javascript">
var prefix = ctx + "system/user"
var deptIds = $("#treeId").val();
var deptNames = $("#treeName").val();
var checks = [];
$(function() {
var url = prefix + "/multiDeptData/" + deptIds;
var options = {
url: url,
expandLevel: 2,
check: {
enable: true,//显示复选框
chkStyle: "checkbox"
},
onCheck : zOnCheck
};
$.tree.init(options);
initChecks();
});
function initChecks() {
if (deptIds && deptIds == "100") {
return;
}
if (deptIds && deptNames) {
var idArray = deptIds.split("-");
var nameArray = deptNames.split("、");
if (idArray.length == nameArray.length) {
for (var i = 0; i < idArray.length; i++) {
checks.push({id: idArray[i], name: nameArray[i]});
}
}
}
}
function zOnCheck(event, treeId, treeNode) {
if (treeNode.checked) {
checks.push({id: treeNode.id, name: treeNode.name});
} else {
removeCheck(treeNode.id);
}
setValue();
}
function setValue() {
var ids = "";
var names = "";
$.each(checks, function (idx, item) {
ids += item.id + "-";
names += item.name + "、";
});
$("#treeId").val(ids.substring(0, ids.lastIndexOf('-')));
$("#treeName").val(names.substring(0, names.lastIndexOf('、')));
}
function removeCheck(chkid) {
$.each(checks, function (idx, item) {
if (item != undefined && item.id == chkid) {
checks.splice(idx, 1);
}
})
}
</script>
</body>
</html>