<script type=
"text/javascript"
>
var
form =
""
;
layui.
use
(['form'],
function
() {
form = layui.form;
getTreeData();
});
function
getTreeData() {
$.ajax({
type:
"post"
,
url:
"/api/WebFW//getOrgTree"
,
datatype:
"json"
,
contenttype:
"application/json; charset=utf-8"
,
success:
function
(jdata) {
var
xtree1 =
new
layuiXtree({
elem: 'xtree1',
form: form,
data: strToJson(jdata),
isopen: true,
click:
function
(data) {
console.log(data.elem);
console.log(data.elem.checked);
alert(data.value);
}
});
document.getElementById('btn1').onclick =
function
() {
var
oCks = xtree1.GetChecked();
for
(
var
i = 0; i < oCks.length; i++) {
alert(oCks[i].value);
}
}
layuiXtree.prototype.ParendCheck =
function
(ckelem) {
var
_this = this;
var
xtree_p = ckelem.parentNode.parentNode;
if
(xtree_p.getAttribute('
class
') == 'layui-xtree-item') {
var
xtree_all = _this.getChildByClassName(xtree_p, 'layui-xtree-item');
var
xtree_count = 0;
for
(
var
i = 0; i < xtree_all.length; i++) {
if
(_this.getChildByClassName(xtree_all[i], 'layui-xtree-checkbox')[0].checked) {
xtree_count++;
}
}
if
(xtree_count <= 0) {
_this.getChildByClassName(xtree_p, 'layui-xtree-checkbox')[0].checked = false;
_this.getChildByClassName(xtree_p, 'layui-xtree-checkbox')[0].nextSibling.classList.remove('layui-form-checked');
}
else
{
_this.getChildByClassName(xtree_p, 'layui-xtree-checkbox')[0].checked = true;
_this.getChildByClassName(xtree_p, 'layui-xtree-checkbox')[0].nextSibling.classList.add('layui-form-checked');
}
this.ParendCheck(_this.getChildByClassName(xtree_p, 'layui-xtree-checkbox')[0]);
}
}
layuiXtree.prototype.ParentCheckboxChecked =
function
(e) {
var
_this = this;
if
(e.parentNode.parentNode.getAttribute('
class
') == 'layui-xtree-item') {
var
_pe = _this.getChildByClassName(e.parentNode.parentNode, 'layui-xtree-checkbox')[0];
_pe.checked = true;
_this.ParentCheckboxChecked(_pe);
}
}
layuiXtree.prototype.GetChecked =
function
() {
var
_this = this;
var
arr =
new
Array();
var
arrIndex = 0;
var
cks = _this.getByClassName('layui-xtree-checkbox');
for
(
var
i = 0; i < cks.length; i++) {
if
(cks[i].checked && cks[i].getAttribute('data-xend') == '1') {
arr[arrIndex] = cks[i];
arrIndex++;
}
}
return
arr;
}
layuiXtree.prototype.GetAllCheckBox =
function
() {
var
_this = this;
var
arr =
new
Array();
var
arrIndex = 0;
var
cks = _this.getByClassName('layui-xtree-checkbox');
for
(
var
i = 0; i < cks.length; i++) {
arr[arrIndex] = cks[i];
arrIndex++;
}
return
arr;
}
layuiXtree.prototype.GetParent =
function
(a) {
var
_this = this;
var
cks = _this.getByClassName('layui-xtree-checkbox');
for
(
var
i = 0; i < cks.length; i++) {
if
(cks[i].value == a) {
if
(cks[i].parentNode.parentNode.getAttribute('id') == _this._container.getAttribute('id'))
return
null;
return
_this.getChildByClassName(cks[i].parentNode.parentNode, 'layui-xtree-checkbox')[0];
}
}
return
null;
}
}
});
}
function
strToJson(str) {
var
json = (
new
Function(
"return "
+ str))();
return
json;
}
</script>