var treeObj = null;
var setting = {
    check: {
        enable: true,
        chkDisabledInherit: true
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    view: {
        fontCss: setHighlight // 高亮一定要设置，setHighlight是自定义方法
    },
    callback: {
        onClick: zTreeOnClick
    }
};

var flowSet = false;

function zTreeOnClick() {
    var zTree = $.fn.zTree.getZTreeObj("tree");

    if (zTree != null) {
        var nodes = zTree.getSelectedNodes();   //获取树控件选中对象集合
        // 关闭所有节点的高亮
        var allNodes = treeObj.transformToArray(treeObj.getNodes());
        for (var i = 0; i < allNodes.length; i++) {
            allNodes[i].highlight = false;
            treeObj.updateNode(allNodes[i]);
        }

        // 高亮并展开搜索到的节点
        for (var i = 0; i < nodes.length; i++) {
            nodes[i].highlight = true;
            treeObj.updateNode(nodes[i]); // 更新节点，让高亮生效
        }

        if (nodes[0].level == 0) {   //根节点
            $("#buttonarea button").attr("hidden", "true");
            $("#addProj2").removeAttr("hidden");
        } else if (nodes[0].level == 1) {    //项目
            $("#buttonarea button").attr("hidden", "true");
            $("#addProj").removeAttr("hidden");
            $("#modProj").removeAttr("hidden");
            $("#delProj").removeAttr("hidden");
            $("#addPro2").removeAttr("hidden");

            var projIndex = nodes[0].nodeIndex;
            $("#projIndex").val(projIndex);
        } else if (nodes[0].level == 2) {    //省份
            $("#buttonarea button").attr("hidden", "true");
            $("#addPro").removeAttr("hidden");
            $("#modPro").removeAttr("hidden");
            $("#delPro").removeAttr("hidden");
            $("#addGd2").removeAttr("hidden");

            var projIndex = nodes[0].getParentNode().nodeIndex;
            $("#projIndex").val(projIndex);
            var proIndex = nodes[0].nodeIndex;
            $("#proIndex").val(proIndex);
        } else if (nodes[0].level == 3) {    //供电公司
            $("#buttonarea button").attr("hidden", "true");
            $("#addGd").removeAttr("hidden");
            $("#modGd").removeAttr("hidden");
            $("#delGd").removeAttr("hidden");
            $("#addSub2").removeAttr("hidden");

            var projIndex = nodes[0].getParentNode().getParentNode().nodeIndex;
            $("#projIndex").val(projIndex);
            var proIndex = nodes[0].getParentNode().nodeIndex;
            $("#proIndex").val(proIndex);
            var gdIndex = nodes[0].nodeIndex;
            $("#gdIndex").val(gdIndex);
        } else if (nodes[0].level == 4) {   //变电站
            $("#buttonarea button").attr("hidden", "true");
            $("#addSub").removeAttr("hidden");
            $("#modSub").removeAttr("hidden");
            $("#delSub").removeAttr("hidden");
            $("#addDev2").removeAttr("hidden");

            var projIndex = nodes[0].getParentNode().getParentNode().getParentNode().nodeIndex;
            $("#projIndex").val(projIndex);
            var proIndex = nodes[0].getParentNode().getParentNode().nodeIndex;
            $("#proIndex").val(proIndex);
            var gdIndex = nodes[0].getParentNode().nodeIndex;
            $("#gdIndex").val(gdIndex);
            var subIndex = nodes[0].nodeIndex;
            $("#subIndex").val(subIndex);
        } else if (nodes[0].level == 5) {    //终端
            $("#buttonarea button").attr("hidden", "true");
            $("#addDev").removeAttr("hidden");
            $("#modDev").removeAttr("hidden");
            $("#delDev").removeAttr("hidden");
            $("#addSubv2").removeAttr("hidden");
            $("#devcommit").removeAttr("disabled");

            var projIndex = nodes[0].getParentNode().getParentNode().getParentNode().getParentNode().nodeIndex;
            $("#projIndex").val(projIndex);
            var proIndex = nodes[0].getParentNode().getParentNode().getParentNode().nodeIndex;
            $("#proIndex").val(proIndex);
            var gdIndex = nodes[0].getParentNode().getParentNode().nodeIndex;
            var gdname = nodes[0].getParentNode().getParentNode().name;
            $("#gdIndex").val(gdIndex);
            var subIndex = nodes[0].getParentNode().nodeIndex;
            var subname = nodes[0].getParentNode().name;
            $("#subIndex").val(subIndex);
            var devIndex = nodes[0].nodeIndex;
            $("#devIndex").val(devIndex);

            loadDevice(devIndex, gdname, subname);
            loadLineIndex(devIndex);
        } else if (nodes[0].level == 6) {     //母线
            $("#buttonarea button").attr("hidden", "true");
            $("#addSubv").removeAttr("hidden");
            $("#modSubv").removeAttr("hidden");
            $("#delSubv").removeAttr("hidden");
            $("#addLine2").removeAttr("hidden");

            var projIndex = nodes[0].getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().nodeIndex;
            $("#projIndex").val(projIndex);
            var proIndex = nodes[0].getParentNode().getParentNode().getParentNode().getParentNode().nodeIndex;
            $("#proIndex").val(proIndex);
            var gdIndex = nodes[0].getParentNode().getParentNode().getParentNode().nodeIndex;
            $("#gdIndex").val(gdIndex);
            var subIndex = nodes[0].getParentNode().getParentNode().nodeIndex;
            $("#subIndex").val(subIndex);
            var devIndex = nodes[0].getParentNode().nodeIndex;
            $("#devIndex").val(devIndex);
            var subvIndex = nodes[0].nodeIndex;
            $("#subvIndex").val(subvIndex);
        } else if (nodes[0].level == 7) {    //线路
            $("#buttonarea button").attr("hidden", "true");
            $("#addLine").removeAttr("hidden");
            $("#modLine").removeAttr("hidden");
            $("#delLine").removeAttr("hidden");

            var projIndex = nodes[0].getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().nodeIndex;
            $("#projIndex").val(projIndex);
            var proIndex = nodes[0].getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().nodeIndex;
            $("#proIndex").val(proIndex);
            var gdIndex = nodes[0].getParentNode().getParentNode().getParentNode().getParentNode().nodeIndex;
            var gdname = nodes[0].getParentNode().getParentNode().getParentNode().getParentNode().name;
            $("#gdIndex").val(gdIndex);
            var subIndex = nodes[0].getParentNode().getParentNode().getParentNode().nodeIndex;
            var subname = nodes[0].getParentNode().getParentNode().getParentNode().name;
            $("#subIndex").val(subIndex);
            var devIndex = nodes[0].getParentNode().getParentNode().nodeIndex;
            $("#devIndex").val(devIndex);
            var subvIndex = nodes[0].getParentNode().nodeIndex;
            $("#subvIndex").val(subvIndex);
            var lineIndex = nodes[0].nodeIndex;
            $("#lineIndex").val(lineIndex);

            $("#linecommit").removeAttr("disabled");
            loadLine(lineIndex);

            loadDevice(devIndex, gdname, subname);
        }
    }
}

function zTreeOnAsyncSuccess(node, pastIndex) {
    var zTree = $.fn.zTree.getZTreeObj("tree");

    var nodes = zTree.getNodes();
    zTree.expandNode(nodes[0], true);

    // 关闭所有节点的高亮
    var allNodes = treeObj.transformToArray(treeObj.getNodes());
    for (var i = 0; i < allNodes.length; i++) {
        allNodes[i].highlight = false;
        treeObj.updateNode(allNodes[i]);
    }

    var childNodes = zTree.transformToArray(nodes[0]);

    var i = 0;
    for (i = 0; i < childNodes.length; i++) {
        var index = childNodes[i].nodeIndex.toString();
        var type = (childNodes[i].level - 1).toString();
        if (index == pastIndex && type == node) {
            if (node == "6") {
                var subvname = childNodes[i].getParentNode();
                var devname = childNodes[i].getParentNode().getParentNode();
                var bdname = childNodes[i].getParentNode().getParentNode().getParentNode();
                var gdname = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode();
                var proname = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode().getParentNode();
                var projname = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().getParentNode();

                zTree.expandNode(projname, true);
                zTree.expandNode(proname, true);
                zTree.expandNode(gdname, true);
                zTree.expandNode(bdname, true);
                zTree.expandNode(devname, true);
                zTree.expandNode(subvname, true);
                zTree.expandNode(childNodes[i], true);

                $("#buttonarea button").attr("hidden", "true");
                $("#addLine").removeAttr("hidden");
                $("#modLine").removeAttr("hidden");
                $("#delLine").removeAttr("hidden");

                var projIndex = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().nodeIndex;
                $("#projIndex").val(projIndex);
                var proIndex = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().nodeIndex;
                $("#proIndex").val(proIndex);
                var gdIndex = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode().nodeIndex;
                var gName = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode().name;
                $("#gdIndex").val(gdIndex);
                var subIndex = childNodes[i].getParentNode().getParentNode().getParentNode().nodeIndex;
                var sName = childNodes[i].getParentNode().getParentNode().getParentNode().name;
                $("#subIndex").val(subIndex);
                var devIndex = childNodes[i].getParentNode().getParentNode().nodeIndex;
                $("#devIndex").val(devIndex);
                var subvIndex = childNodes[i].getParentNode().nodeIndex;
                $("#subvIndex").val(subvIndex);
                var lineIndex = childNodes[i].nodeIndex;
                $("#lineIndex").val(lineIndex);

                $("#linecommit").removeAttr("disabled");
                loadLine(lineIndex);

                loadDevice(devIndex, gName, sName);
            } else if (node == "5") {
                var devname = childNodes[i].getParentNode();
                var bdname = childNodes[i].getParentNode().getParentNode();
                var gdname = childNodes[i].getParentNode().getParentNode().getParentNode();
                var proname = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode();
                var projname = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode().getParentNode();

                zTree.expandNode(projname, true);
                zTree.expandNode(proname, true);
                zTree.expandNode(gdname, true);
                zTree.expandNode(bdname, true);
                zTree.expandNode(devname, true);
                zTree.expandNode(childNodes[i], true);

                $("#buttonarea button").attr("hidden", "true");
                $("#addSubv").removeAttr("hidden");
                $("#modSubv").removeAttr("hidden");
                $("#delSubv").removeAttr("hidden");
                $("#addLine2").removeAttr("hidden");

                var projIndex = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode().getParentNode().nodeIndex;
                $("#projIndex").val(projIndex);
                var proIndex = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode().nodeIndex;
                $("#proIndex").val(proIndex);
                var gdIndex = childNodes[i].getParentNode().getParentNode().getParentNode().nodeIndex;
                $("#gdIndex").val(gdIndex);
                var subIndex = childNodes[i].getParentNode().getParentNode().nodeIndex;
                $("#subIndex").val(subIndex);
                var devIndex = childNodes[i].getParentNode().nodeIndex;
                $("#devIndex").val(devIndex);
                var subvIndex = childNodes[i].nodeIndex;
                $("#subvIndex").val(subvIndex);
            } else if (node == "4") {
                var bdname = childNodes[i].getParentNode();
                var gdname = childNodes[i].getParentNode().getParentNode();
                var proname = childNodes[i].getParentNode().getParentNode().getParentNode();
                var projname = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode();

                zTree.expandNode(projname, true);
                zTree.expandNode(proname, true);
                zTree.expandNode(gdname, true);
                zTree.expandNode(bdname, true);
                zTree.expandNode(childNodes[i], true);

                $("#buttonarea button").attr("hidden", "true");
                $("#addDev").removeAttr("hidden");
                $("#modDev").removeAttr("hidden");
                $("#delDev").removeAttr("hidden");
                $("#addSubv2").removeAttr("hidden");
                $("#devcommit").removeAttr("disabled");

                var projIndex = childNodes[i].getParentNode().getParentNode().getParentNode().getParentNode().nodeIndex;
                $("#projIndex").val(projIndex);
                var proIndex = childNodes[i].getParentNode().getParentNode().getParentNode().nodeIndex;
                $("#proIndex").val(proIndex);
                var gdIndex = childNodes[i].getParentNode().getParentNode().nodeIndex;
                var gName = childNodes[i].getParentNode().getParentNode().name;
                $("#gdIndex").val(gdIndex);
                var subIndex = childNodes[i].getParentNode().nodeIndex;
                var sName = childNodes[i].getParentNode().name;
                $("#subIndex").val(subIndex);
                var devIndex = childNodes[i].nodeIndex;
                $("#devIndex").val(devIndex);

                loadDevice(devIndex, gName, sName);
            } else if (node == "3") {
                var gdname = childNodes[i].getParentNode();
                var proname = childNodes[i].getParentNode().getParentNode();
                var projname = childNodes[i].getParentNode().getParentNode().getParentNode();

                zTree.expandNode(projname, true);
                zTree.expandNode(proname, true);
                zTree.expandNode(gdname, true);
                zTree.expandNode(childNodes[i], true);

                $("#buttonarea button").attr("hidden", "true");
                $("#addSub").removeAttr("hidden");
                $("#modSub").removeAttr("hidden");
                $("#delSub").removeAttr("hidden");
                $("#addDev2").removeAttr("hidden");

                var projIndex = childNodes[i].getParentNode().getParentNode().getParentNode().nodeIndex;
                $("#projIndex").val(projIndex);
                var proIndex = childNodes[i].getParentNode().getParentNode().nodeIndex;
                $("#proIndex").val(proIndex);
                var gdIndex = childNodes[i].getParentNode().nodeIndex;
                $("#gdIndex").val(gdIndex);
                var subIndex = childNodes[i].nodeIndex;
                $("#subIndex").val(subIndex);
            } else if (node == "2") {
                var proname = childNodes[i].getParentNode();
                var projname = childNodes[i].getParentNode().getParentNode();

                zTree.expandNode(projname, true);
                zTree.expandNode(proname, true);
                zTree.expandNode(childNodes[i], true);

                $("#buttonarea button").attr("hidden", "true");
                $("#addGd").removeAttr("hidden");
                $("#modGd").removeAttr("hidden");
                $("#delGd").removeAttr("hidden");
                $("#addSub2").removeAttr("hidden");

                var projIndex = childNodes[i].getParentNode().getParentNode().nodeIndex;
                $("#projIndex").val(projIndex);
                var proIndex = childNodes[i].getParentNode().nodeIndex;
                $("#proIndex").val(proIndex);
                var gdIndex = childNodes[i].nodeIndex;
                $("#gdIndex").val(gdIndex);
            } else {
                var projname = childNodes[i].getParentNode();

                zTree.expandNode(projname, true);
                zTree.expandNode(childNodes[i], true);

                $("#buttonarea button").attr("hidden", "true");
                $("#addPro").removeAttr("hidden");
                $("#modPro").removeAttr("hidden");
                $("#delPro").removeAttr("hidden");
                $("#addGd2").removeAttr("hidden");

                var projIndex = childNodes[i].getParentNode().nodeIndex;
                $("#projIndex").val(projIndex);
                var proIndex = childNodes[i].nodeIndex;
                $("#proIndex").val(proIndex);
            }

            childNodes[i].highlight = true;
            treeObj.updateNode(childNodes[i]); // 更新节点，让高亮生效
        }
    }
}

function setHighlight(treeId, treeNode) {
    return (treeNode.highlight) ? {
        color: "#000000",
        "font-weight": "bold",
        "border-bottom": "dotted 1px #fff"
    } : {color: "#666", "font-weight": "normal"};
}

function getTree(expset) {
    jQuery.ajax({
        type: 'POST',
        dataType: "json",
        url: '/pqs9900/device/deviceTree',
        data: {},
        async: false,
        error: function () {
        },
        success: function (data) {
            var datalist = [];
            if (expset == "first") {
                for (var i = 0; i < data.length; i++) {
                    var str = '';

                    str += '{' + "id:" + data[i].id;
                    str += ',' + "name:'" + data[i].name + "'";
                    str += ',' + "nodeIndex:" + data[i].nodeIndex;
                    str += ',' + "nodeType:" + data[i].nodeType;
                    str += ',' + "ppId:" + data[i].ppId;
                    if (data[i].nodeType == "0" || data[i].nodeType == "1" || data[i].nodeType == "2") {
                        str += ',' + "open:" + true;
                    } else {
                        str += ',' + "open:" + false;
                    }
                    str += ',' + "state:" + data[i].state;
                    str += ',' + "pId:" + data[i].pId + '}';
                    datalist.push(str);
                }
            } else {
                for (var i = 0; i < data.length; i++) {
                    var str = '';

                    str += '{' + "id:" + data[i].id;
                    str += ',' + "name:'" + data[i].name + "'";
                    str += ',' + "nodeIndex:" + data[i].nodeIndex;
                    str += ',' + "nodeType:" + data[i].nodeType;
                    str += ',' + "ppId:" + data[i].ppId;
                    str += ',' + "open:" + false;
                    str += ',' + "state:" + data[i].state;
                    str += ',' + "pId:" + data[i].pId + '}';
                    datalist.push(str);
                }
            }
            datalist = eval('[' + datalist + ']');// string->json数组

            var zNodes = datalist;

            treeObj = $.fn.zTree.init($("#tree"), setting, zNodes);
        }
    });
}

$(document).ready(function () {
    var st = "first";
    getTree(st);
    var zTree = $.fn.zTree.getZTreeObj("tree");
    flowSet = parent.flowTrue;
    if (flowSet) {
        searchNode(parent.$("#devN").val());
        $("#buttonarea button").attr("hidden", "true");
        $("#addDev").removeAttr("hidden");
        $("#modDev").removeAttr("hidden");
        $("#delDev").removeAttr("hidden");
        $("#addSubv2").removeAttr("hidden");
        $("#devcommit").removeAttr("disabled");

        loadDevice(parent.$("#devI").val(), parent.$("#gdN").val(), parent.$("#suBN").val());
        loadLineIndex(parent.$("#devI").val());
    }
});

function loadDevice(devIndex, gdname, subname) {
    jQuery.ajax({
        type: 'POST',
        dataType: "json",
        url: '/pqs9900/device/loadDevice',
        data: {
            devIndex: devIndex
        },
        success: function (data) {
            var iptype = data.iptype;
            if (iptype == "cld") {
                $("#ipmac").html("<font color='red'>*</font>MAC:");
                $("#mac").val(data.ip);

                $("#onlycld").removeAttr("hidden");
            } else if (iptype == "pqdif") {
                $("#ipmac").html("<font color='red'>*</font>IP/MAC:");
                $("#mac").val(data.ip);

                $("#onlycld").attr("hidden", "true");
            } else {
                $("#ipmac").html("<font color='red'>*</font>IP:");
                $("#mac").val(data.ip);

                $("#onlycld").attr("hidden", "true");
            }
            $("#devname").val(data.name);
            $("#devtype").val(data.devType);
            $("#port").val(data.portId);

            if (data.status == 1) {
                $("#status").val("正常");
            } else {
                $("#status").val("中断");
            }

            $("#gdname").val(gdname);
            $("#subname").val(subname);

            $("#LogonTime").val(data.logTime);
            $("#UpdateTime").val(data.updTime);
            $("#nodeinfo").val(data.nodeIndex);
            $("#datatype").val(data.datatype);
            $("#devmodel").val(data.devmodel);

            $("#ThisTimeCheck").val(data.thisTime);
            $("#NextTimeCheck").val(data.nextTime);
            $("#manufacturer").val(data.manufacturer);
            $("#callflag").val(data.callFlag);
            $("#electroplate").val(data.electroplate);
            $("#ontime").val(data.ontime);
            $("#contract").val(data.contract);
            $("#devCatena").val(data.devCatena);
            $("#sim").val(data.sim);
            $("#devLocation").val(data.devLocation);
            $("#devNo").val(data.devNo);
            $("#isAlarm").val(data.isAlarm==null? 1:data.isAlarm);
            $("#devfunction").find("option").remove();
//			$("#devfunction").val(data.devfunction);
            var devfunction = [];
            for (v of data.devfunction) {
                devfunction.push(v.fucname);
            }
            changeDevfunc(devfunction);
//			if(data.devfunction!=null){
//				for(var i=0;i<data.devfunction.length;i++){
//					$("#devfunction").val(data.devfunction[i]);
//					var mm = $("#devfunction").find("option:contains("+data.devfunction[i].fucname+")");
//					.attr("selected",true);
//				}
//			}

            if (data.series.length > 0) {
                $("#series").val(data.series);
            } else {
                $("#series").val("");
            }
            if (data.key.length > 0) {
                $("#key").val(data.key);
            } else {
                $("#key").val("");
            }
        }
    })
}

function loadLineIndex(devIndex) {
    jQuery.ajax({
        type: 'POST',
        dataType: "json",
        url: '/pqs9900/device/loadLineIndex',
        data: {
            devIndex: devIndex
        },
        success: function (data) {
            if (data != 0) {
                loadLine(data);
            }
        }
    })
}

function loadLine(lineIndex) {
    jQuery.ajax({
        type: 'POST',
        dataType: "json",
        url: '/pqs9900/device/loadLine',
        data: {
            lineIndex: lineIndex
        },
        success: function (data) {
            $("#linename").val(data.name);
            $("#scale").val(data.scale);
            $("#dlcMp").val(data.dlcMp);
            $("#xycMp").val(data.xycMp);
            $("#jzcMp").val(data.jzcMp);
            $("#devcMp").val(data.devcMp);
            $("#CT1").val(data.ct1);
            $("#CT2").val(data.ct2);
            $("#PT1").val(data.pt1);
            $("#PT2").val(data.pt2);
            $("#ptType").val(data.ptType);
            $("#tInterval").val(data.tinterval);
            $("#loadType").val(data.loadType);
            $("#businessType").val(data.businessType);
            $("#powerId").val(data.powerId);
            $("#remark").val(data.remark);
            $("#monitorId").val(data.monitorId);
            $("#VOLTAGE").val(data.voltageDev);
            $("#UVOLTAGE").val(data.uvoltageDev);
            $("#objName").val(data.objName)
            $("#statflag").val(data.statFlag)
            $("#PowerSubName").val(data.powerSubstationName)
            $("#calssificationGrade").val(data.calssificationGrade)
            $("#superiorsSubstation").val(data.superiorsSubstation)
            $("#hangLine").val(data.hangLine)
            $("#owner").val(data.owner)
            $("#ownerDuty").val(data.ownerDuty)
            $("#ownerTel").val(data.ownerTel)
            $("#isGridPoint").val(data.isGridPoint)
            $("#lineStatus").val(data.status)

            $("#wiringDiagram").show()
            if(data.wiringDiagram!== null ){
                $("#demo1").show()
            }else {
                $("#demo1").hide()
            }
            if (data.monitorId != null && data.monitorId !== ' '){
                $("#send").css("display","block");
            } else {
                $("#send").css("display","none");
            }
        }
    })
}

function changeDevfunc(devfunction) {
    var dictypeName = "装置功能";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/getselect",
        data: {
            dictypeName: dictypeName
        },
        async: true,
        success: function (data) {
            $.each(data, function (i, item) {
                if (devfunction.indexOf(item.dicIndex) > -1) {
                    var option = $("<option selected value='"
                        + item.dicIndex + "'>"
                        + item.dicName + "</option>");
                    $('#devfunction').append(option);
                } else {
                    var option = $("<option value='"
                        + item.dicIndex + "'>"
                        + item.dicName + "</option>");
                    $('#devfunction').append(option);
                }
            })
            $('#devfunction').fSelect("device");
        }
    })
}

//模糊搜索name满足条件的节点
function searchNode(value) {
    if (value == "")
        return;

    // 获取搜索的节点
    var nodes = treeObj.getNodesByParamFuzzy("name", value);
    // 关闭所有节点的高亮
    var allNodes = treeObj.transformToArray(treeObj.getNodes());
    for (var i = 0; i < allNodes.length; i++) {
        allNodes[i].highlight = false;
        treeObj.updateNode(allNodes[i]);
    }
    // 展开第一层节点
    treeObj.expandAll(false);
    treeObj.expandNode(treeObj.getNodes()[0], true);
    // 高亮并展开搜索到的节点
    for (var i = 0; i < nodes.length; i++) {
        nodes[i].highlight = true;
        treeObj.updateNode(nodes[i]); // 更新节点，让高亮生效
        treeObj.expandNode(nodes[i].getParentNode(), true);
    }
}

$('#send').click(function () {
    var text = document.getElementById("monitorId").value;
    jQuery.ajax({
        type: 'POST',
        dataType: "json",
        url: '/pqs9900/device/addMonitor',
        data: {
            monitorId: text
        },
        success: function (data) {
            if (data.code === 200) {
                //提示新增成功
                layer.msg('推送成功!', {icon: 1, time: 1000});
            } else if (data.code === 201){
                //提示重复录入
                layer.msg('已录入,请勿重复录入!', {icon: 2, time: 1000});
            } else if (data.code === 500){
                //提示错误
                layer.msg('推送失败!', {icon: 2, time: 1000});
            }
        }
    })
})