var pindex = parent.layer.getFrameIndex(window.name); //获取窗口索引

$("#cancel").click(function () {
    parent.layer.close(pindex);
});

$("#nodemanage").click(function () {
    layer.open({
        type: 2,
        title: '前置机管理',
        shadeClose: true,
        area: ['100%', '100%'],
        offset: '0px',
        maxmin: false,
        content: 'nodeinfo',
        scrollbar: false,
        end: function () {
            var sel = $("#nodeinfo").val();
            $("#nodeinfo").empty();
            loadnode();
            $("#nodeinfo").val(sel);
        }
    });
});

$("#addProj").click(function () {
    layer.open({
        type: '1',
        title: '新增项目',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: "<div class='form-horizontal pd15'><div class='form-group' id='newProjName'><label class='col-sm-4 col-md-4 font12 pdt5' for='projName'>项目名称</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='projName' maxlength='64'></div></div></div>",
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var projName = $("#projName").val();
            projName = filterXSS(projName);
            if (projName == null || projName == "") {
                layer.tips('名称不可为空', '#projName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(projName)) {
                layer.tips('名称含有非汉字字符', '#projName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                $.ajax({
                    url: '/pqs9900/device/addProj',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        projName: projName
                    },
                    async: false,
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                        } else if (info.code == 400) {
                            layer.msg('添加失败！名称已存在', {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('添加失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#addProj2").click(function () {
    layer.open({
        type: '1',
        title: '新增项目',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: "<div class='form-horizontal pd15'><div class='form-group' id='newProjName'><label class='col-sm-4 col-md-4 font12 pdt5' for='projName'>项目名称</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='projName' maxlength='64'></div></div></div>",
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var projName = $("#projName").val();
            projName = filterXSS(projName);
            if (projName == null || projName == "") {
                layer.tips('名称不可为空', '#projName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(projName)) {
                layer.tips('名称含有非汉字字符', '#projName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                $.ajax({
                    url: '/pqs9900/device/addProj',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        projName: projName
                    },
                    async: false,
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                        } else if (info.code == 400) {
                            layer.msg('添加失败！名称已存在', {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('添加失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#modProj").click(function () {
    var projIndex = $("#projIndex").val();

    var content = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/loadProj",
        data: {
            projIndex: projIndex
        },
        async: false,
        success: function (data) {
            if (data == null) {
                layer.msg('项目信息加载失败!', {icon: 1, time: 1000});
            } else {
                content = content + "<div class='form-horizontal pd15'><div class='form-group' id='newporjName'><label class='col-sm-4 col-md-4 font12 pdt5' for='porjName'>项目名称</label><div class='col-sm-6 col-md-6'>" +
                    "<input  type='text' class=' form-control' style='width:210px' id='porjName'  maxlength='64' value='" + data.name + "'></div></div></div>"
            }
        }
    })

    layer.open({
        type: '1',
        title: '修改项目',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: content,
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var porjName = $("#porjName").val();
            porjName = filterXSS(porjName);
            if (porjName == null || porjName == "") {
                layer.tips('名称不可为空', '#porjName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(porjName)) {
                layer.tips('名称含有非汉字字符', '#porjName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                $.ajax({
                    url: '/pqs9900/device/updateporj',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        porjIndex: projIndex,
                        name: porjName
                    },
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('修改成功!', {icon: 1, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('修改失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#delProj").click(function () {
    var projIndex = $("#projIndex").val();
    layer.confirm('是否确认？', function () {
        $.ajax({
            method: "post",
            url: "/pqs9900/device/delporj",
            data: {
                projIndex: projIndex
            },
            async: false,
            success: function (data) {
                if (data.code == 200) {
                    layer.msg('删除成功!', {icon: 1, time: 1000});
                    getTree();
                } else if (data.code == 400) {
                    layer.msg('删除失败!请先删除下级节点', {icon: 2, time: 1000});
                } else {
                    layer.msg('删除失败！', {icon: 2, time: 1000});
                }
            }
        })
    })
});

$("#addPro").click(function () {
    var projIndex = $("#projIndex").val();

    var option = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/getDicPro",
        data: {},
        dataType: 'json',
        async: false,
        success: function (data) {
            for (var i = 0; i < data.length; i++) {

                option = option + "<option value='"
                    + data[i].dicIndex + "'>"
                    + data[i].dicName + "</option>";

            }
        }
    })

    layer.open({
        type: '1',
        title: '新增省份',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: "<div class='form-horizontal pd15'><div class='form-group' id='newProName'><label class='col-sm-4 col-md-4 font12 pdt5' for='proName'>省份</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='proName'>" + option + "</select></div></div></div>",
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var pastIndex;
            var node = "1";
            var proName = $("#proName").find("option:selected").text();
            proName = filterXSS(proName);
            if (proName == null || proName == "") {
                layer.tips('名称不可为空', '#proName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(proName)) {
                layer.tips('名称含有非汉字字符', '#proName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                $.ajax({
                    url: '/pqs9900/device/addPro',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        projIndex: projIndex,
                        proName: proName
                    },
                    async: false,
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                            pastIndex = info.body;
                        } else if (info.code == 400) {
                            layer.msg('添加失败！名称已存在', {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('添加失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();
                zTreeOnAsyncSuccess(node, pastIndex);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#addPro2").click(function () {
    var projIndex = $("#projIndex").val();
    var option = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/getDicPro",
        data: {},
        dataType: 'json',
        async: false,
        success: function (data) {
            for (var i = 0; i < data.length; i++) {

                option = option + "<option value='"
                    + data[i].dicIndex + "'>"
                    + data[i].dicName + "</option>";

            }
        }
    })

    layer.open({
        type: '1',
        title: '新增省份',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: "<div class='form-horizontal pd15'><div class='form-group' id='newProName'><label class='col-sm-4 col-md-4 font12 pdt5' for='proName'>省份</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='proName'>" + option + "</select></div></div></div>",
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var node = "1";
            var pastIndex;
            var proName = $("#proName").find("option:selected").text();
            proName = filterXSS(proName);
            if (proName == null || proName == "") {
                layer.tips('名称不可为空', '#proName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(proName)) {
                layer.tips('名称含有非汉字字符', '#proName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                $.ajax({
                    url: '/pqs9900/device/addPro',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        projIndex: projIndex,
                        proName: proName
                    },
                    async: false,
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                            pastIndex = info.body;
                        } else if (info.code == 400) {
                            layer.msg('添加失败！名称已存在', {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('添加失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();
                zTreeOnAsyncSuccess(node, pastIndex);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#modPro").click(function () {
    var proIndex = $("#proIndex").val();

    var content = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/loadPro",
        data: {
            proIndex: proIndex
        },
        async: false,
        success: function (data) {
            if (data == null) {
                layer.msg('省份信息加载失败!', {icon: 1, time: 1000});
            } else {
                content = content + "<div class='form-horizontal pd15'><div class='form-group' id='newProName'><label class='col-sm-4 col-md-4 font12 pdt5' for='proName'>省份名称</label><div class='col-sm-6 col-md-6'>" +
                    "<input  type='text' class=' form-control' style='width:210px' id='proName'  maxlength='64' value='" + data.name + "'></div></div></div>"
            }
        }
    })

    layer.open({
        type: '1',
        title: '修改省份',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: content,
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var node = "1";
            var pastIndex = proIndex;
            var proName = $("#proName").val();
            proName = filterXSS(proName);
            if (proName == null || proName == "") {
                layer.tips('名称不可为空', '#proName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(proName)) {
                layer.tips('名称含有非汉字字符', '#proName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                $.ajax({
                    url: '/pqs9900/device/updatePro',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        proIndex: proIndex,
                        name: proName
                    },
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('修改成功!', {icon: 1, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('修改失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();
                zTreeOnAsyncSuccess(node, pastIndex);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#delPro").click(function () {
    var proIndex = $("#proIndex").val();
    var node = "0";
    var pastIndex = $("#projIndex").val();
    layer.confirm('是否确认？', function () {
        $.ajax({
            method: "post",
            url: "/pqs9900/device/delPro",
            data: {
                proIndex: proIndex
            },
            async: false,
            success: function (data) {
                if (data.code == 200) {
                    layer.msg('删除成功!', {icon: 1, time: 1000});
                    getTree();
                    zTreeOnAsyncSuccess(node, pastIndex);
                } else if (data.code == 400) {
                    layer.msg('删除失败!请先删除下级节点', {icon: 2, time: 1000});
                } else {
                    layer.msg('删除失败！', {icon: 2, time: 1000});
                }
            }
        })
    })
});

$("#addGd").click(function () {
    var proIndex = $("#proIndex").val();

    layer.open({
        type: '1',
        title: '新增供电公司',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: "<div class='form-horizontal pd15'><div class='form-group' id='newGdName'><label class='col-sm-4 col-md-4 font12 pdt5' for='gdName'>供电公司名称</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='gdName' maxlength='64'></div></div></div>",
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var gdName = $("#gdName").val();
            gdName = filterXSS(gdName);
            if (gdName == null || gdName == "") {
                layer.tips('名称不可为空', '#gdName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(gdName)) {
                layer.tips('名称含有非汉字字符', '#gdName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                saveGd(proIndex, gdName, index);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#addGd2").click(function () {
    var proIndex = $("#proIndex").val();

    layer.open({
        type: '1',
        title: '新增供电公司',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: "<div class='form-horizontal pd15'><div class='form-group' id='newGdName'><label class='col-sm-4 col-md-4 font12 pdt5' for='gdName'>供电公司名称</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='gdName' maxlength='64'></div></div></div>",
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var gdName = $("#gdName").val();
            gdName = filterXSS(gdName);
            if (gdName == null || gdName == "") {
                layer.tips('名称不可为空', '#gdName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(gdName)) {
                layer.tips('名称含有非汉字字符', '#gdName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                saveGd(proIndex, gdName, index);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#modGd").click(function () {
    var gdIndex = $("#gdIndex").val();
    var proIndex = $("#proIndex").val();
    gdIndex = filterXSS(gdIndex);

    var content = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/loadGd",
        data: {
            gdIndex: gdIndex
        },
        async: false,
        success: function (data) {
            if (data == null) {
                layer.msg('供电公司信息加载失败!', {icon: 1, time: 1000});
            } else {
                content = content + "<div class='form-horizontal pd15'><div class='form-group' id='newGdName'><label class='col-sm-4 col-md-4 font12 pdt5' for='gdName'>供电公司名称</label><div class='col-sm-6 col-md-6'>" +
                    "<input  type='text' class=' form-control' style='width:210px' id='gdName' maxlength='64' value='" + data.name + "'></div></div></div>"
            }
        }
    })

    layer.open({
        type: '1',
        title: '修改供电公司',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: content,
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var gdName = $("#gdName").val();
            gdName = filterXSS(gdName);
            if (gdName == null || gdName == "") {
                layer.tips('名称不可为空', '#gdName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(gdName)) {
                layer.tips('名称含有非汉字字符', '#gdName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                modGd(gdName, gdIndex, proIndex, index);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#delGd").click(function () {
    var layii = 0;
    var node = "1";
    var gdIndex = $("#gdIndex").val();
    var pastIndex = $("#proIndex").val();
    layer.confirm('删除供电公司会删除下属所有信息!是否确认？', function () {
        $.ajax({
            method: "post",
            url: "/pqs9900/device/delGd",
            data: {
                gdIndex: gdIndex
            },
            beforeSend: function () {
                layii = ityzl_SHOW_LOAD_LAYER();
            },
            async: false,
            success: function (data) {
                if (data.code == 200) {
                    layer.msg('删除成功!', {icon: 1, time: 1000});
                    getTree();
                    zTreeOnAsyncSuccess(node, pastIndex);
                } else if (data.code == 400) {
                    layer.msg('删除失败!请先删除下级节点', {icon: 2, time: 1000});
                } else {
                    layer.msg('删除失败！', {icon: 2, time: 1000});
                }

                //***********关闭loading
                ityzl_CLOSE_LOAD_LAYER(layii);
            }
        })
    })
});

$("#addSub").click(function () {
    var option = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/getselect",
        data: {
            dictypeName: '电压等级'
        },
        dataType: 'json',
        async: false,
        success: function (data) {
            for (var i = 0; i < data.length; i++) {

                option = option + "<option value='"
                    + data[i].dicIndex + "'>"
                    + data[i].dicName + "</option>";

            }
        }
    })

    var gdIndex = $("#gdIndex").val();
    if (sysType == "0") {
        layer.open({
            type: '1',
            title: '新增变电站',
            shadeClose: true,
            resize: false,
            scrollbar: false,
            closeBtn: 0,
            area: '380px',
            content: "<div class='form-horizontal pd15'><div class='form-group' id='newSubName'><label class='col-sm-4 col-md-4 font12 pdt5' for='subName'>变电站名称</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='subName' maxlength='64'></div></div>" +
                "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvscale'>电压等级</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='subvscale'>" + option + "</select></div></div>" +
                "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='longitude'>经度</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='longitude' onkeyup='value=value.replace(/[^\-?\d.]/g,'')'></div></div>" +
                "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='latitude'>纬度</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='latitude' onkeyup='value=value.replace(/[^\-?\d.]/g,'')'></div></div></div>",
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //执行增加操作
                var subName = $("#subName").val();
                var scale = $("#subvscale").val();
                var longitude = $("#longitude").val();
                var latitude = $("#latitude").val();
                subName = filterXSS(subName);
                longitude = filterXSS(longitude);
                latitude = filterXSS(latitude);
                if (subName == null || subName == "") {
                    layer.tips('名称不可为空', '#subName', {
                        tips: [1, 'red'] //还可配置颜色
                    });
                    return false;
                } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(subName)) {
                    layer.tips('名称含有非汉字字符', '#subName', {
                        tips: [1, 'red'] //还可配置颜色
                    });
                    return false;
                }


                if (longitude == null || longitude == "") {
                    longitude = 0
                }

                if (latitude == null || latitude == "") {
                    latitude = 0
                }
                var pastIndex;
                var node = "3";
                $.ajax({
                    url: '/pqs9900/device/addSub',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        subName: subName,
                        gdIndex: gdIndex,
                        scale: scale,
                        longitude: longitude,
                        latitude: latitude
                    },
                    async: false,
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                            pastIndex = info.body;
                        } else if (info.code == 400) {
                            layer.msg('添加失败！名称已存在', {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('添加失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();

                zTreeOnAsyncSuccess(node, pastIndex);

            }, btn2: function (index, layero) {
                layer.close(index);
            }
        })
    } else {
        layer.open({
            type: '1',
            title: '新增变电站',
            shadeClose: true,
            resize: false,
            scrollbar: false,
            closeBtn: 0,
            area: '380px',
            content: "<div class='form-horizontal pd15'><div class='form-group' id='newSubName'><label class='col-sm-4 col-md-4 font12 pdt5' for='subName'>变电站名称</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='subName' maxlength='64'></div></div>" +
                "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvscale'>电压等级</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='subvscale'>" + option + "</select></div></div>" +
                "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='longitude'>经度</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='longitude' onkeyup='value=value.replace(/[^\-?\d.]/g,'')'></div></div>" +
                "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='latitude'>纬度</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='latitude' onkeyup='value=value.replace(/[^\-?\d.]/g,'')'></div></div></div>",
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //执行增加操作
                var subName = $("#subName").val();
                var scale = $("#subvscale").val();
                var longitude = $("#longitude").val();
                var latitude = $("#latitude").val();
                longitude = filterXSS(longitude);
                latitude = filterXSS(latitude);
                subName = filterXSS(subName);
                if (subName == null || subName == "") {
                    layer.tips('名称不可为空', '#subName', {
                        tips: [1, 'red'] //还可配置颜色
                    });

                    return false;
                } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(subName)) {
                    layer.tips('名称含有非汉字字符', '#subName', {
                        tips: [1, 'red'] //还可配置颜色
                    });
                    return false;
                }

                if (longitude == null || longitude == "") {
                    longitude = 0
                }

                if (latitude == null || latitude == "") {
                    latitude = 0
                }


                var pastIndex;
                var node = "3";
                $.ajax({
                    url: '/pqs9900/device/addSub',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        subName: subName,
                        gdIndex: gdIndex,
                        scale: scale,
                        longitude: longitude,
                        latitude: latitude
                    },
                    async: false,
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                            pastIndex = info.body;
                        } else if (info.code == 400) {
                            layer.msg('添加失败！名称已存在', {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('添加失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();

                zTreeOnAsyncSuccess(node, pastIndex);

            }, btn2: function (index, layero) {
                layer.close(index);
            }
        })
    }
});

$("#addSub2").click(function () {
    var option = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/getselect",
        data: {
            dictypeName: '电压等级'
        },
        dataType: 'json',
        async: false,
        success: function (data) {
            for (var i = 0; i < data.length; i++) {

                option = option + "<option value='"
                    + data[i].dicIndex + "'>"
                    + data[i].dicName + "</option>";

            }
        }
    })

    var gdIndex = $("#gdIndex").val();
    if (sysType == "0") {
        layer.open({
            type: '1',
            title: '新增变电站',
            shadeClose: true,
            resize: false,
            scrollbar: false,
            closeBtn: 0,
            area: '380px',
            content: "<div class='form-horizontal pd15'><div class='form-group' id='newSubName'><label class='col-sm-4 col-md-4 font12 pdt5' for='subName'>变电站名称</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='subName' maxlength='64'></div></div>" +
                "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvscale'>电压等级</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='subvscale'>" + option + "</select></div></div>" +
                "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='longitude'>经度</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='longitude' onkeyup='value=value.replace(/[^\-?\d.]/g,'')'></div></div>" +
                "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='latitude'>纬度</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='latitude' onkeyup='value=value.replace(/[^\-?\d.]/g,'')'></div></div></div>",
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //执行增加操作
                var subName = $("#subName").val();
                var scale = $("#subvscale").val();
                var longitude = $("#longitude").val();
                var latitude = $("#latitude").val();
                subName = filterXSS(subName);
                longitude = filterXSS(longitude);
                latitude = filterXSS(latitude);
                if (subName == null || subName == "") {
                    layer.tips('名称不可为空', '#subName', {
                        tips: [1, 'red'] //还可配置颜色
                    });
                    return false;
                } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(subName)) {
                    layer.tips('名称含有非汉字字符', '#subName', {
                        tips: [1, 'red'] //还可配置颜色
                    });
                    return false;
                }

                if (longitude == null || longitude == "") {
                    longitude = 0
                }

                if (latitude == null || latitude == "") {
                    latitude = 0
                }


                var pastIndex;
                var node = "3";
                $.ajax({
                    url: '/pqs9900/device/addSub',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        subName: subName,
                        gdIndex: gdIndex,
                        scale: scale,
                        longitude: longitude,
                        latitude: latitude
                    },
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                            pastIndex = info.body;
                        } else if (info.code == 400) {
                            layer.msg('添加失败！名称已存在', {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('添加失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();

                zTreeOnAsyncSuccess(node, pastIndex);

            }, btn2: function (index, layero) {
                layer.close(index);
            }
        })
    } else {
        layer.open({
            type: '1',
            title: '新增变电站',
            shadeClose: true,
            resize: false,
            scrollbar: false,
            closeBtn: 0,
            area: '380px',
            content: "<div class='form-horizontal pd15'><div class='form-group' id='newSubName'><label class='col-sm-4 col-md-4 font12 pdt5' for='subName'>变电站名称</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='subName' maxlength='64'></div></div>" +
                "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvscale'>电压等级</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='subvscale'>" + option + "</select></div></div>" +
                "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='longitude'>经度</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='longitude' onkeyup='value=value.replace(/[^\-?\d.]/g,'')'></div></div>" +
                "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='latitude'>纬度</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='latitude' onkeyup='value=value.replace(/[^\-?\d.]/g,'')'></div></div></div>",
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //执行增加操作
                var subName = $("#subName").val();
                var scale = $("#subvscale").val();
                var longitude = $("#longitude").val();
                var latitude = $("#latitude").val();

                longitude = filterXSS(longitude);
                latitude = filterXSS(latitude);
                subName = filterXSS(subName);
                if (subName == null || subName == "") {
                    layer.tips('名称不可为空', '#subName', {
                        tips: [1, 'red'] //还可配置颜色
                    });
                    return false;
                } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(subName)) {
                    layer.tips('名称含有非汉字字符', '#subName', {
                        tips: [1, 'red'] //还可配置颜色
                    });
                    return false;
                }

                if (longitude == null || longitude == "") {
                    longitude = 0
                }

                if (latitude == null || latitude == "") {
                    latitude = 0
                }

                var pastIndex;
                var node = "3";
                $.ajax({
                    url: '/pqs9900/device/addSub',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        subName: subName,
                        gdIndex: gdIndex,
                        scale: scale,
                        longitude: longitude,
                        latitude: latitude
                    },
                    async: false,
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                            pastIndex = info.body;
                        } else if (info.code == 400) {
                            layer.msg('添加失败！名称已存在', {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('添加失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();

                zTreeOnAsyncSuccess(node, pastIndex);

            }, btn2: function (index, layero) {
                layer.close(index);
            }
        })
    }
});

$("#modSub").click(function () {
    var option = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/getselect",
        data: {
            dictypeName: '电压等级'
        },
        dataType: 'json',
        async: false,
        success: function (data) {
            for (var i = 0; i < data.length; i++) {

                option = option + "<option value='"
                    + data[i].dicIndex + "'>"
                    + data[i].dicName + "</option>";

            }
        }
    })

    var gdIndex = $("#gdIndex").val();
    var subIndex = $("#subIndex").val();
    var content = "";
    var mapIndex;

    if (sysType == "1") {
        content = content + "<div class='form-horizontal pd15'><div class='form-group' id='newSubName'><label class='col-sm-4 col-md-4 font12 pdt5' for='subName'>变电站名称</label><div class='col-sm-6 col-md-6'>" +
            "<input  type='text' class=' form-control' style='width:210px' id='subName' maxlength='64'></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subscale'>电压等级</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='subscale'>" + option + "</select></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='longitude'>经度</label><div class='col-sm-6 col-md-6'>" +
            "<input  type='text' class=' form-control' style='width:210px' id='longitude' onkeyup='value=value.replace(/[^\-?\d.]/g,'')'></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='latitude'>纬度</label><div class='col-sm-6 col-md-6'>" +
            "<input  type='text' class=' form-control' style='width:210px' id='latitude' onkeyup='value=value.replace(/[^\-?\d.]/g,'')'></div></div></div>";
        layer.open({
            type: '1',
            title: '修改变电站',
            shadeClose: true,
            resize: false,
            scrollbar: false,
            closeBtn: 0,
            area: '380px',
            content: content,
            success: function (layero, index) {
                $.ajax({
                    method: "post",
                    url: "/pqs9900/device/loadSub",
                    data: {
                        subIndex: subIndex
                    },
                    async: false,
                    success: function (data) {
                        if (data == null) {
                            layer.msg('变电站信息加载失败!', {icon: 1, time: 1000});
                        } else {
                            $("#subName").val(data.name);
                            $("#subscale").val(data.scale);
                            $("#longitude").val(data.longItude);
                            $("#latitude").val(data.latItude);
                            mapIndex = data.mapIndex;
                        }
                    }
                })
            },
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //执行增加操作
                var scale = $("#subscale").val();
                var subName = $("#subName").val();
                var longitude = $("#longitude").val();
                var latitude = $("#latitude").val();
                subName = filterXSS(subName);
                longitude = filterXSS(longitude);
                latitude = filterXSS(latitude);

                if (subName == null || subName == "") {
                    layer.tips('名称不可为空', '#subName', {
                        tips: [1, 'red'] //还可配置颜色
                    });
                } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(subName)) {
                    layer.tips('名称含有非汉字字符', '#subName', {
                        tips: [1, 'red'] //还可配置颜色
                    });
                } else {
                    var pastIndex = subIndex;
                    var node = "3";
                    $.ajax({
                        url: '/pqs9900/device/updateSub',
                        type: 'POST',
                        dataType: "text",
                        async: false,
                        data: {
                            gdIndex: gdIndex,
                            subIndex: subIndex,
                            name: subName,
                            longitude: longitude,
                            latitude: latitude,
                            mapIndex: mapIndex,
                            scale: scale
                        },
                        success: function (data) {
                            var info = $.parseJSON(data);
                            if (info.code == 200) {
                                layer.msg('修改成功!', {icon: 1, time: 1000});

                            } else if (info.code == 400) {
                                layer.msg('修改失败！名称已存在', {icon: 2, time: 1000});
                            } else if (info.code == 501) {
                                layer.msg(info.message, {icon: 2, time: 1000});
                            } else {
                                layer.msg('修改失败！', {icon: 2, time: 1000});
                            }
                        }

                    });
                    layer.close(index);
                    getTree();

                    zTreeOnAsyncSuccess(node, pastIndex);
                }
            }, btn2: function (index, layero) {
                layer.close(index);
            }
        })
    } else {
        content = content + "<div class='form-horizontal pd15'><div class='form-group' id='newSubName'><label class='col-sm-4 col-md-4 font12 pdt5' for='subName'>变电站名称</label><div class='col-sm-6 col-md-6'>" +
            "<input  type='text' class=' form-control' style='width:210px' id='subName' maxlength='64'></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subscale'>电压等级</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='subscale'>" + option + "</select></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='longitude'>经度</label><div class='col-sm-6 col-md-6'>" +
            "<input  type='text' class=' form-control' style='width:210px' id='longitude' onkeyup='value=value.replace(/[^\-?\d.]/g,'')'></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='latitude'>纬度</label><div class='col-sm-6 col-md-6'>" +
            "<input  type='text' class=' form-control' style='width:210px' id='latitude' onkeyup='value=value.replace(/[^\-?\d.]/g,'')'></div></div></div>";

        layer.open({
            type: '1',
            title: '修改变电站',
            shadeClose: true,
            resize: false,
            scrollbar: false,
            closeBtn: 0,
            area: '380px',
            content: content,
            success: function (layero, index) {
                $.ajax({
                    method: "post",
                    url: "/pqs9900/device/loadSub",
                    data: {
                        subIndex: subIndex
                    },
                    async: false,
                    success: function (data) {
                        if (data == null) {
                            layer.msg('变电站信息加载失败!', {icon: 1, time: 1000});
                        } else {
                            $("#subName").val(data.name);
                            $("#subscale").val(data.scale);
                            $("#longitude").val(data.longItude);
                            $("#latitude").val(data.latItude);
                            mapIndex = data.mapIndex;
                        }
                    }
                })
            },
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //执行增加操作
                var subName = $("#subName").val();
                var scale = $("#subscale").val();
                var longitude = $("#longitude").val();
                var latitude = $("#latitude").val();
                subName = filterXSS(subName);
                longitude = filterXSS(longitude);
                latitude = filterXSS(latitude);
                if (subName == null || subName == "") {
                    layer.tips('名称不可为空', '#subName', {
                        tips: [1, 'red'] //还可配置颜色
                    });
                } else if (!/^[\u4E00-\u9FA5A-Za-z0-9_\s+±]+$/gi.test(subName)) {
                    layer.tips('名称含有非汉字字符', '#subName', {
                        tips: [1, 'red'] //还可配置颜色
                    });
                } else {
                    var pastIndex;
                    var node = "3";
                    $.ajax({
                        url: '/pqs9900/device/updateSub',
                        type: 'POST',
                        dataType: "text",
                        async: false,
                        data: {
                            gdIndex: gdIndex,
                            subIndex: subIndex,
                            name: subName,
                            longitude: longitude,
                            latitude: latitude,
                            mapIndex: mapIndex,
                            scale: scale
                        },
                        success: function (data) {
                            var info = $.parseJSON(data);
                            if (info.code == 200) {
                                layer.msg('修改成功!', {icon: 1, time: 1000});
                                pastIndex = subIndex;
                            } else if (info.code == 400) {
                                layer.msg('修改失败！名称已存在', {icon: 2, time: 1000});
                            } else if (info.code == 501) {
                                layer.msg(info.message, {icon: 2, time: 1000});
                            } else {
                                layer.msg('修改失败！', {icon: 2, time: 1000});
                            }
                        }

                    });
                    layer.close(index);
                    getTree();

                    zTreeOnAsyncSuccess(node, pastIndex);
                }
            }, btn2: function (index, layero) {
                layer.close(index);
            }
        })
    }
});

$("#delSub").click(function () {
    var node = "2";
    var subIndex = $("#subIndex").val();
    var pastIndex = $("#gdIndex").val();
    layer.confirm('是否确认？', function () {
        $.ajax({
            method: "post",
            url: "/pqs9900/device/delSub",
            data: {
                subIndex: subIndex
            },
            async: false,
            success: function (data) {
                if (data.code == 200) {
                    layer.msg('删除成功!', {icon: 1, time: 1000});
                    getTree();
                    zTreeOnAsyncSuccess(node, pastIndex);
                } else if (data.code == 400) {
                    layer.msg('删除失败!请先删除下级节点', {icon: 2, time: 1000});
                } else if (data.code == 600) {
                    layer.msg('删除失败！其下还有变压器', {icon: 2, time: 1000});
                } else {
                    layer.msg('删除失败！', {icon: 2, time: 1000});
                }
            }
        })
    })
});

$("#addDev").click(function () {
    var gdIndex = $("#gdIndex").val();
    var subIndex = $("#subIndex").val();
    layer.open({
        type: 2,
        title: '新增装置',
        shadeClose: true,
        shade: 0.3,
        area: '380px',
        maxmin: false,
        maxHeight: '400px',
        content: 'adddevice?gdIndex=' + gdIndex + '&subIndex=' + subIndex,
        scrollbar: false,
        success: function (layero, index) {
            layer.iframeAuto(index);
        }
    });
});

$("#addDev2").click(function () {
    var gdIndex = $("#gdIndex").val();
    var subIndex = $("#subIndex").val();
    layer.open({
        type: 2,
        title: '新增装置',
        shadeClose: true,
        shade: 0.3,
        area: '380px',
        maxmin: false,
        maxHeight: '400px',
        content: 'adddevice?gdIndex=' + gdIndex + '&subIndex=' + subIndex,
        scrollbar: false,
        success: function (layero, index) {
            layer.iframeAuto(index);
        }
    });
});

$("#modDev").click(function () {
    var gdIndex = $("#gdIndex").val();
    var subIndex = $("#subIndex").val();
    var devIndex = $("#devIndex").val();
    var content = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/loadDevice",
        data: {
            devIndex: devIndex
        },
        async: false,
        success: function (data) {
            if (data == null) {
                layer.msg('终端信息加载失败!', {icon: 1, time: 1000});
            } else {
                content = content + "<div class='form-horizontal pd15'><div class='form-group'><label class='col-sm-4 col-md-4 font12 pdt5' for='devName'>终端名称</label><div class='col-sm-6 col-md-6'>" +
                    "<input  type='text' class=' form-control' style='width:210px' id='devName' maxlength='64' value='" + data.name + "'></div></div></div>"
//	                		+ "<div class='form-group'><label class='col-sm-4 col-md-4 font12 pdt5' for='devName'>识别码</label><div class='col-sm-6 col-md-6'>" +
//	                		"<input  type='password' maxlength='20' class=' form-control' style='width:210px' id='devseries' value='"+data.series+"'></div></div>" +
//	                		"<div class='form-group'><label class='col-sm-4 col-md-4 font12 pdt5' for='devName'>秘钥</label><div class='col-sm-6 col-md-6'>" +
//	                		"<input  type='password' maxlength='20' class=' form-control' style='width:210px' id='devkey' value='"+data.key+"'></div></div></div>"
            }
        }
    })

    layer.open({
        type: '1',
        title: '修改终端',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: content,
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var devName = $("#devName").val();
//            	var series = $("#devseries").val();
//            	var key = $("#devkey").val();

            devName = filterXSS(devName);
//            	series=filterXSS(series);
//            	key=filterXSS(key);
//
//            	var regSeries =/^(?=.*[a-zA-Z])(?=.*\d)(?=.*[@#&_.]).{6,12}$/;
//            	var regkey =/^(?=.*[a-zA-Z])(?=.*\d)(?=.*[@#&_.]).{16,16}$/;
            if (devName == null || devName == "") {
                layer.tips('名称不可为空', '#devName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            }
//            	else if(series.length!=0 && series.length<8){
//                	layer.tips('请至少输入8位终端码', '#devseries', {
//                        tips: [1, 'red'] //还可配置颜色
//                    });
//                }else if(key.length!=0 && key.length<8){
//                	layer.tips('请至少输入8位秘钥', '#devkey', {
//                        tips: [1, 'red'] //还可配置颜色
//                    });
//                }
            else {
                var pastIndex = devIndex;
                var node = "4";
                $.ajax({
                    url: '/pqs9900/device/updateDeviceInfo',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        devIndex: devIndex,
                        name: devName
//                            ,series:series,
//                            key:key
                    },
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('修改成功!', {icon: 1, time: 1000});

                        } else if (info.code == 400) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('修改失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();

                zTreeOnAsyncSuccess(node, pastIndex);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#delDev").click(function () {
    var devIndex = $("#devIndex").val();
    var pastIndex = $("#subIndex").val();
    var node = "3";
    layer.confirm('是否确认？', function () {
        $.ajax({
            method: "post",
            url: "/pqs9900/device/delDeviceInfo",
            data: {
                devIndex: devIndex
            },
            async: false,
            success: function (data) {
                if (data.code == 200) {
                    layer.msg('删除成功!', {icon: 1, time: 1000});
                    getTree();

                    zTreeOnAsyncSuccess(node, pastIndex);
                } else if (data.code == 400) {
                    layer.msg('删除失败!请先删除下级节点', {icon: 2, time: 1000});
                } else {
                    layer.msg('删除失败！', {icon: 2, time: 1000});
                }
            }
        })
    })
});

$("#addSubv").click(function () {
    var gdIndex = $("#gdIndex").val();
    var subIndex = $("#subIndex").val();
    var devIndex = $("#devIndex").val();

    var option = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/getselect",
        data: {
            dictypeName: '电压等级'
        },
        dataType: 'json',
        async: false,
        success: function (data) {
            for (var i = 0; i < data.length; i++) {

                option = option + "<option value='"
                    + data[i].dicIndex + "'>"
                    + data[i].dicName + "</option>";

            }
        }
    })

    var subvNum = "";
    subvNum = subvNum + "<option value='1'>1</option>";
    subvNum = subvNum + "<option value='2'>2</option>";
    subvNum = subvNum + "<option value='3'>3</option>";
    subvNum = subvNum + "<option value='4'>4</option>";
    subvNum = subvNum + "<option value='5'>5</option>";
    subvNum = subvNum + "<option value='6'>6</option>";

    var option1 = "<option value='1'>实际母线</option>" +
        "<option value='0'>虚拟母线</option>"

    layer.open({
        type: '1',
        title: '新增母线',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: "<div class='form-horizontal pd15'><div class='form-group' id='newSubName'><label class='col-sm-4 col-md-4 font12 pdt5' for='subvName'>母线名称</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='subvName' maxlength='64'></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvnum'>母线号</label><div class='col-sm-6 col-md-6'><select class=' form-control' style='width:210px' id='subvnum'>" + subvNum + "</select></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvscale'>电压等级</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='subvscale'>" + option + "</select></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvModel'>母线模型</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='subvModel'>" + option1 + "</select></div></div></div>",
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var subvName = $("#subvName").val();
            var subvnum = $("#subvnum").val();
            var scale = $("#subvscale").val();
            var subvModel = $("#subvModel").val();
            subvName = filterXSS(subvName);

            if (subvName == null || subvName == "") {
                layer.tips('名称不可为空', '#subvName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (subvnum == null || subvnum == "") {
                layer.tips('母线号不可为空', '#subvnum', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[0-9]*$/gi.test(subvnum)) {
                layer.tips('请输入数字', '#subvnum', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                var pastIndex;
                var node = "5";
                $.ajax({
                    url: '/pqs9900/device/addSubv',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        subvName: subvName,
                        gdIndex: gdIndex,
                        subIndex: subIndex,
                        devIndex: devIndex,
                        subvnum: subvnum,
                        scale: scale,
                        subvModel: subvModel
                    },
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                            pastIndex = info.body;
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('添加失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();

                zTreeOnAsyncSuccess(node, pastIndex);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#addSubv2").click(function () {
    var gdIndex = $("#gdIndex").val();
    var subIndex = $("#subIndex").val();
    var devIndex = $("#devIndex").val();

    var option = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/getselect",
        data: {
            dictypeName: '电压等级'
        },
        dataType: 'json',
        async: false,
        success: function (data) {
            for (var i = 0; i < data.length; i++) {
                option = option + "<option value='"
                    + data[i].dicIndex + "'>"
                    + data[i].dicName + "</option>";
            }
        }
    })

    var subvNum = "";
    subvNum = subvNum + "<option value='1'>1</option>";
    subvNum = subvNum + "<option value='2'>2</option>";
    subvNum = subvNum + "<option value='3'>3</option>";
    subvNum = subvNum + "<option value='4'>4</option>";
    subvNum = subvNum + "<option value='5'>5</option>";
    subvNum = subvNum + "<option value='6'>6</option>";

    var option1 = "<option value='1'>实际母线</option>" +
        "<option value='0'>虚拟母线</option>"

    layer.open({
        type: '1',
        title: '新增母线',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: "<div class='form-horizontal pd15'><div class='form-group' id='newSubName'><label class='col-sm-4 col-md-4 font12 pdt5' for='subvName'>母线名称</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='subvName' maxlength='64'></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvnum'>母线号</label><div class='col-sm-6 col-md-6'><select class=' form-control' style='width:210px' id='subvnum'>" + subvNum + "</select></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvscale'>电压等级</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='subvscale'>" + option + "</select></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvModel'>母线模型</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='subvModel'>" + option1 + "</select></div></div></div>",
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var subvName = $("#subvName").val();
            var subvnum = $("#subvnum").val();
            var scale = $("#subvscale").val();
            var subvModel = $("#subvModel").val();
            subvName = filterXSS(subvName);

            if (subvName == null || subvName == "") {
                layer.tips('名称不可为空', '#subvName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (subvnum == null || subvnum == "") {
                layer.tips('母线号不可为空', '#subvnum', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[0-9]*$/gi.test(subvnum)) {
                layer.tips('请输入数字', '#subvnum', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                var pastIndex;
                var node = "5";
                $.ajax({
                    url: '/pqs9900/device/addSubv',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        subvName: subvName,
                        gdIndex: gdIndex,
                        subIndex: subIndex,
                        devIndex: devIndex,
                        subvnum: subvnum,
                        scale: scale,
                        subvModel: subvModel
                    },
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                            pastIndex = info.body;
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('添加失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();

                zTreeOnAsyncSuccess(node, pastIndex);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#modSubv").click(function () {
    var gdIndex = $("#gdIndex").val();
    var subIndex = $("#subIndex").val();
    var devIndex = $("#devIndex").val();
    var subvIndex = $("#subvIndex").val();

    var option = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/getselect",
        data: {
            dictypeName: '电压等级'
        },
        dataType: 'json',
        async: false,
        success: function (data) {
            for (var i = 0; i < data.length; i++) {
                option = option + "<option value='"
                    + data[i].dicIndex + "'>"
                    + data[i].dicName + "</option>";
            }
        }
    })

    var subvNum = "";
    subvNum = subvNum + "<option value='1'>1</option>";
    subvNum = subvNum + "<option value='2'>2</option>";
    subvNum = subvNum + "<option value='3'>3</option>";
    subvNum = subvNum + "<option value='4'>4</option>";
    subvNum = subvNum + "<option value='5'>5</option>";
    subvNum = subvNum + "<option value='6'>6</option>";

    var option1 = "<option value='1'>实际母线</option>" +
        "<option value='0'>虚拟母线</option>"

    var content = "";
    content = content + "<div class='form-horizontal pd15'><div class='form-group' id='newSubName'><label class='col-sm-4 col-md-4 font12 pdt5' for='subvName'>母线名称</label><div class='col-sm-6 col-md-6'>" +
        "<input  type='text' class=' form-control' style='width:210px' id='subvName' maxlength='64'></div></div>" +
        "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvnum'>母线号</label><div class='col-sm-6 col-md-6'><select class=' form-control' style='width:210px' id='subvnum'>" + subvNum + "</select></div></div>" +
        "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvscale'>电压等级</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='subvscale'>" + option + "</select></div></div>" +
        "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='subvModel'>母线模型</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='subvModel'>" + option1 + "</select></div></div></div>";


    layer.open({
        type: '1',
        title: '修改母线',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: content,
        success: function (layero, index) {
            $.ajax({
                method: "post",
                url: "/pqs9900/device/loadSubv",
                data: {
                    subvIndex: subvIndex
                },
                async: false,
                success: function (data) {
                    if (data == null) {
                        layer.msg('母线信息加载失败!', {icon: 1, time: 1000});
                    } else {
                        $("#subvName").val(data.name);
                        $("#subvnum").val(data.subvNum);
                        $("#subvscale").val(data.scale);
                        $("#subvModel").val(data.subvModel);
                    }
                }
            })
        },
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var subvName = $("#subvName").val();
            var subvnum = $("#subvnum").val();
            var scale = $("#subvscale").val();
            var subvModel = $("#subvModel").val();
            subvName = filterXSS(subvName);

            if (subvName == null || subvName == "") {
                layer.tips('名称不可为空', '#subvName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[0-9]*$/gi.test(subvnum)) {
                layer.tips('请输入数字', '#subvnum', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                var pastIndex = subvIndex;
                var node = "5";
                $.ajax({
                    url: '/pqs9900/device/updateSubv',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        subvName: subvName,
                        gdIndex: gdIndex,
                        subIndex: subIndex,
                        devIndex: devIndex,
                        subvIndex: subvIndex,
                        subvnum: subvnum,
                        scale: scale,
                        subvModel: subvModel
                    },
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('修改成功!', {icon: 1, time: 1000});

                        } else if (info.code == 400) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('修改失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();

                zTreeOnAsyncSuccess(node, pastIndex);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#delSubv").click(function () {
    var subvIndex = $("#subvIndex").val();
    var pastIndex = $("#devIndex").val();
    var node = "4";
    layer.confirm('是否确认？', function () {
        $.ajax({
            method: "post",
            url: "/pqs9900/device/delSubv",
            data: {
                subvIndex: subvIndex
            },
            async: false,
            success: function (data) {
                if (data.code == 200) {
                    layer.msg('删除成功!', {icon: 1, time: 1000});
                    getTree();

                    zTreeOnAsyncSuccess(node, pastIndex);
                } else if (data.code == 400) {
                    layer.msg('删除失败!请先删除下级节点', {icon: 2, time: 1000});
                } else {
                    layer.msg('删除失败！', {icon: 2, time: 1000});
                }
            }
        })
    })
});

$("#addLine").click(function () {
    var proIndex = $("#proIndex").val();
    var gdIndex = $("#gdIndex").val();
    var subIndex = $("#subIndex").val();
    var devIndex = $("#devIndex").val();
    var subvIndex = $("#subvIndex").val();

    var num = "";
    num = num + "<option value='1'>1</option>";
    num = num + "<option value='2'>2</option>";
    num = num + "<option value='3'>3</option>";
    num = num + "<option value='4'>4</option>";
    num = num + "<option value='5'>5</option>";
    num = num + "<option value='6'>6</option>";
    num = num + "<option value='7'>7</option>";
    num = num + "<option value='8'>8</option>";
    num = num + "<option value='9'>9</option>";

    var option = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/loadDepts",
        data: {
            proIndex: proIndex
        },
        dataType: 'json',
        async: false,
        success: function (data) {
            for (var i = 0; i < data.length; i++) {
                if (i == 0) {
                    option = option + "<option selected value='"
                        + data[i].deptsIndex + "'>"
                        + data[i].deptsName + "</option>";
                } else {
                    option = option + "<option value='"
                        + data[i].deptsIndex + "'>"
                        + data[i].deptsName + "</option>";
                }
            }
        }
    })

    layer.open({
        type: '1',
        title: '新增监测点',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: "<div class='form-horizontal pd15'><div class='form-group' id='newSubName'><label class='col-sm-4 col-md-4 font12 pdt5' for='lineName'>监测点名称</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='lineName' maxlength='64'></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12' for='lineNum'>监测点线路号</label><div class='col-sm-6 col-md-6'><select class=' form-control' style='width:210px' id='lineNum'>" + num + "</select></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='dept'>所属部门</label><div class='col-sm-6 col-md-6'><select class='form-control' style='width:210px' id='dept'>" + option + "</select></div></div></div>",
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var lineName = $("#lineName").val();
            var lineNum = $("#lineNum").val();
            var dept = $("#dept").val();
            lineName = filterXSS(lineName);

            if (lineName == null || lineName == "") {
                layer.tips('名称不可为空', '#lineName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[0-9]*$/gi.test(lineNum)) {
                layer.tips('请输入数字', '#lineNum', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                var pastIndex;
                var node = "6";
                $.ajax({
                    url: '/pqs9900/device/addLine',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        gdIndex: gdIndex,
                        subIndex: subIndex,
                        devIndex: devIndex,
                        subvIndex: subvIndex,
                        lineName: lineName,
                        lineNum: lineNum,
                        dept: dept
                    },
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                            pastIndex = info.body;
                        } else if (info.code == 400) {
                            layer.msg('添加失败!监测点号已使用!', {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('添加失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();

                zTreeOnAsyncSuccess(node, pastIndex);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#addLine2").click(function () {
    var proIndex = $("#proIndex").val();
    var gdIndex = $("#gdIndex").val();
    var subIndex = $("#subIndex").val();
    var devIndex = $("#devIndex").val();
    var subvIndex = $("#subvIndex").val();

    var num = "";
    num = num + "<option value='1'>1</option>";
    num = num + "<option value='2'>2</option>";
    num = num + "<option value='3'>3</option>";
    num = num + "<option value='4'>4</option>";
    num = num + "<option value='5'>5</option>";
    num = num + "<option value='6'>6</option>";

    var option = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/loadDepts",
        data: {
            proIndex: proIndex
        },
        dataType: 'json',
        async: false,
        success: function (data) {
            for (var i = 0; i < data.length; i++) {
                if (i == 0) {
                    option = option + "<option selected value='"
                        + data[i].deptsIndex + "'>"
                        + data[i].deptsName + "</option>";
                } else {
                    option = option + "<option value='"
                        + data[i].deptsIndex + "'>"
                        + data[i].deptsName + "</option>";
                }
            }
        }
    })

    layer.open({
        type: '1',
        title: '新增监测点',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: ['380px', '80%'],
        content: "<div class='form-horizontal pd15'><div class='form-group' id='newSubName'><label class='col-sm-4 col-md-4 font12 pdt5' for='lineName'>监测点名称</label><div class='col-sm-6 col-md-6'><input  type='text' class=' form-control' style='width:210px' id='lineName' maxlength='64'></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12' for='lineNum'>监测点线路号</label><div class='col-sm-6 col-md-6'><select class=' form-control' style='width:210px' id='lineNum'>" + num + "</select></div></div>" +
            "<div class='form-group' ><label class='col-sm-4 col-md-4 font12 pdt5' for='dept'>所属部门</label><div class='col-sm-6 col-md-6'><select  class='form-control' data-live-search='true' style='width:210px' id='dept'>" + option + "</select></div></div></div>",
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var lineName = $("#lineName").val();
            var lineNum = $("#lineNum").val();
            var dept = $("#dept").val();
            lineName = filterXSS(lineName);

            if (lineName == null || lineName == "") {
                layer.tips('名称不可为空', '#lineName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else if (!/^[0-9]*$/gi.test(lineNum)) {
                layer.tips('请输入数字', '#lineNum', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                var pastIndex;
                var node = "6";
                $.ajax({
                    url: '/pqs9900/device/addLine',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        gdIndex: gdIndex,
                        subIndex: subIndex,
                        devIndex: devIndex,
                        subvIndex: subvIndex,
                        lineName: lineName,
                        lineNum: lineNum,
                        dept: dept
                    },
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                            pastIndex = info.body;
                        } else if (info.code == 400) {
                            layer.msg('添加失败!监测点号已使用!', {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg('添加失败！', {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();

                zTreeOnAsyncSuccess(node, pastIndex);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        },
        success: function (layero, index) {
            $('#dept').selectpicker({
                noneSelectedText: '',
                width: 210,
                noneResultsText: '',
                liveSearch: true,
                size: 10   //设置select高度，同时显示5个值

            });
        }
    })
});


$("#modLine").click(function () {
    var gdIndex = $("#gdIndex").val();
    var subIndex = $("#subIndex").val();
    var devIndex = $("#devIndex").val();
    var subvIndex = $("#subvIndex").val();
    var lineIndex = $("#lineIndex").val();
    var content = "";
    $.ajax({
        method: "post",
        url: "/pqs9900/device/loadLine",
        data: {
            lineIndex: lineIndex
        },
        async: false,
        success: function (data) {
            if (data == null) {
                layer.msg('监测点信息加载失败!', {icon: 1, time: 1000});
            } else {
                content = content + "<div class='form-horizontal pd15'><div class='form-group' id='newSubName'><label class='col-sm-4 col-md-4 font12 pdt5' for='lineName'>监测点名称</label><div class='col-sm-6 col-md-6'>" +
                    "<input  type='text' class=' form-control' style='width:210px' id='lineName' maxlength='64' value='" + data.name + "'></div></div></div>"
            }
        }
    })

    layer.open({
        type: '1',
        title: '修改监测点',
        shadeClose: true,
        resize: false,
        scrollbar: false,
        closeBtn: 0,
        area: '380px',
        content: content,
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            //执行增加操作
            var lineName = $("#lineName").val();
            lineName = filterXSS(lineName);

            if (lineName == null || lineName == "") {
                layer.tips('名称不可为空', '#lineName', {
                    tips: [1, 'red'] //还可配置颜色
                });
            } else {
                var pastIndex = lineIndex;
                var node = "6";
                $.ajax({
                    url: '/pqs9900/device/updateLineBase',
                    type: 'POST',
                    dataType: "text",
                    async: false,
                    data: {
                        lineId: lineIndex,
                        lineName: lineName
                    },
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code == 200) {
                            layer.msg('修改成功!', {icon: 1, time: 1000});

                        } else if (info.code == 400) {
                            layer.msg('修改失败！名称已存在', {icon: 2, time: 1000});
                        } else if (info.code == 501) {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        } else {
                            layer.msg(info.message, {icon: 2, time: 1000});
                        }
                    }

                });
                layer.close(index);
                getTree();

                zTreeOnAsyncSuccess(node, pastIndex);
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        }
    })
});

$("#delLine").click(function () {
    var lineIndex = $("#lineIndex").val();
    var pastIndex = $("#subvIndex").val();
    var node = "5";
    layer.confirm('是否确认？', function () {
        $.ajax({
            method: "post",
            url: "/pqs9900/device/delLine",
            data: {
                lineIndex: lineIndex
            },
            async: false,
            success: function (data) {
                if (data.code == 200) {
                    layer.msg('删除成功!', {icon: 1, time: 1000});
                    getTree();

                    zTreeOnAsyncSuccess(node, pastIndex);
                } else {
                    layer.msg('删除失败！', {icon: 2, time: 1000});
                }
            }
        })
    })
});

var sysType = "";

$(document).ready(function () {
    var iii = ityzl_SHOW_LOAD_LAYER();
    var devtype = '装置类型';
    var div1 = "devtype";
    loadselect(devtype, div1);

    var scale = '电压等级';
    var div2 = "scale";
    loadselect(scale, div2);

    var manufacturer = '制造厂商';
    var div3 = "manufacturer";
    loadselect(manufacturer, div3);

    var loadType = '干扰源类型';
    var div4 = 'loadType';
    loadselect(loadType, div4);

    var businessType = '行业类型';
    var div5 = 'businessType';
    loadselect(businessType, div5);

    var devfunction = '装置功能';
    var div6 = 'devfunction';
    loadselect(devfunction, div6);

    var devCatena = '装置系列';
    var div7 = 'devCatena';
    loadselect(devCatena, div7);

    var calssificationGrade = '监测点分类等级';
    var div8 = "calssificationGrade";
    loadselect(calssificationGrade, div8);

    loadnode();

    loadSysType();

    if (sysType == "1") {
        document.getElementById("call").innerHTML = "召唤标志";
        var option = $("<option selected value='0'>变位触发</option>" +
            "<option value='1'>周期触发</option>" +
            "<option value='2'>变位触发(仅3秒)</option>");
        $("#callflag").append(option);
        $("#callflag").removeAttr("hidden");
    }

    //***********关闭loading
    ityzl_CLOSE_LOAD_LAYER(iii);
})


function loadselect(dictypeName, div) {
    var part = '#' + div;
    $.ajax({
        method: "post",
        url: "/pqs9900/device/getselect",
        data: {
            dictypeName: dictypeName
        },
        async: true,
        success: function (data) {
            if (data == null) {
                var message = dictypeName + '信息加载失败';
                layer.msg(message, {icon: 1, time: 1000});
            } else if (dictypeName == "装置功能") {
//				var listdata = [];
//				for(var i=0;i<data.length;i++){
//					var tmp = {};
//					tmp[data[i].dicIndex]=data[i].dicName;
//					listdata.push(tmp);
//				}
//				$('#devfunction').eq(0).hsCheckData({
//			        isShowCheckBox: true, //默认为false
//			        minCheck: 0,//默认为0，不限最少选择个数
//			        maxCheck: 9,//默认为0，不限最多选择个数
//			        data: listdata
//			    });

                $.each(data, function (i, item) {
                    var option = $("<option selected value='"
                        + item.dicIndex + "'>"
                        + item.dicName + "</option>");
                    $(part).append(option);
                })
                $('#devfunction').fSelect();
            } else {
                $.each(data, function (i, item) {
                    if (i == 0) {
                        var option = $("<option selected value='"
                            + item.dicIndex + "'>"
                            + item.dicName + "</option>");
                        $(part).append(option);
                    } else {
                        var option = $("<option value='"
                            + item.dicIndex + "'>"
                            + item.dicName + "</option>");
                        $(part).append(option);
                    }
                })
            }
        }
    })
}

function loadnode() {
    $.ajax({
        method: "post",
        url: "/pqs9900/device/getNodeInfo",
        data: {},
        async: false,
        success: function (data) {
            $.each(data, function (i, item) {
                if (i == 0) {
                    var option = $("<option selected value='"
                        + item.nodeIndex + "'>"
                        + item.nodeName + "</option>");
                    $("#nodeinfo").append(option);
                } else {
                    var option = $("<option value='"
                        + item.nodeIndex + "'>"
                        + item.nodeName + "</option>");
                    $("#nodeinfo").append(option);
                }
            })

        }
    })
}

function loadSysType() {
    $.ajax({
        method: "post",
        url: "/pqs9900/device/loadSysType",
        data: {},
        async: false,
        success: function (data) {
            sysType = data;
        }
    })
}

$("#devcommit").click(function () {
    var devname = $("#devname").val();
    var devIndex = $("#devIndex").val();
    var typename = $("#devtype").find("option:selected").text();
    var devtype = $("#devtype").val();
    var LogonTime = $("#LogonTime").val();
    var node = $("#nodeinfo").val();
    var devmodel = $("#devmodel").val();
    var gdname = $("#gdname").val();
    var subname = $("#subname").val();
    var datatype = $("#datatype").val();
    var manufacturer = $("#manufacturer").val();
    var NextTimeCheck = $("#NextTimeCheck").val();
    var mac = $("#mac").val();
    var port = $("#port").val();
    var callflag = $("#callflag").val();
    var devfunc = $("#devfunction").val();
    var series = $("#series").val();
    var key = $("#key").val();
    var ele = $('#electroplate').val()
    var ontime = $('#ontime').val()
    var contract = $('#contract').val()
    var devCatena = $("#devCatena").val()
    var sim = $("#sim").val()
    var devLocation = $("#devLocation").val()
    var devNo = $("#devNo").val()
    var isAlarm = $("#isAlarm").val()
    // if (devLocation.length > 100) {
    //     layer.msg('监测装置安装位置内容过长！', {icon: 2, time: 1000});
    //     return
    // }
    if (devNo.length > 50) {
        layer.msg('监测厂家设备编号内容过长！', {icon: 2, time: 1000});
        return
    }

    var devfunction = [];
    if (devfunc != null) {
        for (var i = 0; i < devfunc.length; i++) {
            devfunction.push(devfunc[i]);
        }
    }

    layer.confirm('是否确认？', function () {
        $.ajax({
            method: "post",
            traditional: true,
            url: "/pqs9900/device/updateDeviceInfo",
            data: {
                devIndex: devIndex,
                devtype: devtype,
                typename: typename,
                LogonTime: LogonTime,
                nodeIndex: node,
                name: devname,
                devmodel: devmodel,
                datatype: datatype,
                manufacturer: manufacturer,
                NextTimeCheck: NextTimeCheck,
                mac: mac,
                port: port,
                callflag: callflag,
                devfunc: JSON.stringify(devfunction),
                series: series,
                key: key,
                electroplate: ele, //电镀功能
                ontime: ontime,
                contract: contract,
                devCatena: devCatena,
                sim: sim,
                devLocation: devLocation,
                devNo: devNo,
                isAlarm: isAlarm
            },
            async: false,
            success: function (data) {
                if (data.code == 200) {
                    layer.msg('更新成功!', {icon: 1, time: 1000});
                    loadDevice(devIndex, gdname, subname);
                } else if (data.code == 501 || data.code == 400) {
                    layer.msg(data.message, {icon: 2, time: 1000});
                } else {
                    layer.msg('更新失败！', {icon: 2, time: 1000});
                }
            }
        })
    })
});

$("#linecommit").click(function () {
    var linename = $("#linename").val();
    var lineIndex = $("#lineIndex").val();
    var dlcMp = $("#dlcMp").val();
    var xycMp = $("#xycMp").val();
    var devcMp = $("#devcMp").val();
    var ct1 = $("#CT1").val();
    var ct2 = $("#CT2").val();
    var pt1 = $("#PT1").val();
    var pt2 = $("#PT2").val();
    var ptType = $("#ptType").val();
    var tInterval = $("#tInterval").val();
    var loadType = $("#loadType").val();
    var businessType = $("#businessType").val();
    var powerId = $("#powerId").val();
    var remark = $("#remark").val();
    var monitorId = $("#monitorId").val();
    var voltage = $("#VOLTAGE").val();
    var uvoltage = $("#UVOLTAGE").val();
    var objName = $("#objName").val()
    var statFlag = $("#statflag").val()
    var powerSubName = $("#PowerSubName").val()
    var calssificationGrade = $("#calssificationGrade").val()
    var superiorsSubstation = $("#superiorsSubstation").val()
    var hangLine = $("#hangLine").val()
    var owner = $("#owner").val()
    var ownerDuty = $("#ownerDuty").val()
    var ownerTel = $("#ownerTel").val()
    var isGridPoint = $("#isGridPoint").val()
    var lineStatus = $("#lineStatus").val()
    remark = filterXSS(remark);
    monitorId = filterXSS(monitorId);
    voltage = filterXSS(voltage);
    uvoltage = filterXSS(uvoltage);
    objName = filterXSS(objName)
    powerSubName = filterXSS(powerSubName)
    superiorsSubstation = filterXSS(superiorsSubstation)
    hangLine = filterXSS(hangLine)
    owner = filterXSS(owner)
    ownerDuty = filterXSS(ownerDuty)

    var tel = numberz;// 只能输入数字

    if (ownerTel != null && ownerTel != '') {
        if (!tel.test(ownerTel)) {
            layer.tips('联系方式格式有误', '#ownerTel', {
                tips: [1, 'red'],
                time: 2000
                // 还可配置颜色
            });
            return;
        }
    }

    layer.confirm('是否确认？', function () {
        $.ajax({
            method: "post",
            url: "/pqs9900/device/updateLine",
            data: {
                name: linename,
                lineIndex: lineIndex,
                dlcMp: dlcMp,
                xycMp: xycMp,
                devcMp: devcMp,
                ct1: ct1,
                ct2: ct2,
                pt1: pt1,
                pt2: pt2,
                ptType: ptType,
                tInterval: tInterval,
                loadType: loadType,
                businessType: businessType,
                powerId: powerId,
                remark: remark,
                monitorId: monitorId,
                voltage: voltage,
                uvoltage: uvoltage,
                objName: objName,
                statFlag: statFlag,
                powerSubName: powerSubName,
                calssificationGrade: calssificationGrade,
                superiorsSubstation: superiorsSubstation,
                hangLine: hangLine,
                owner: owner,
                ownerDuty: ownerDuty,
                ownerTel: ownerTel,
                isGridPoint: isGridPoint,
                lineStatus: lineStatus
            },
            async: false,
            success: function (data) {
                if (data.code == 200) {
                    layer.msg('更新成功!', {icon: 1, time: 1000});
                    loadLine(lineIndex);
                } else if (data.code == 501) {
                    layer.msg(data.message, {icon: 2, time: 1000});
                } else {
                    layer.msg('更新失败！', {icon: 2, time: 1000});
                }
            }
        })
    })
});

function saveGd(proIndex, gdName, index) {
    var pastIndex;
    var node = "2";
    $.ajax({
        url: '/pqs9900/device/addGd',
        type: 'POST',
        dataType: "text",
        data: {
            gdName: gdName,
            proIndex: proIndex
        },
        async: false,
        success: function (data) {
            var info = $.parseJSON(data);
            if (info.code == 200) {
                layer.msg('添加成功!', {icon: 1, time: 1000});
                pastIndex = info.body;
            } else if (info.code == 400) {
                layer.msg('添加失败！名称已存在', {icon: 2, time: 1000});
            } else if (info.code == 501) {
                layer.msg(info.message, {icon: 2, time: 1000});
            } else {
                layer.msg('添加失败！', {icon: 2, time: 1000});
            }
        }
    });
    layer.close(index);
    getTree();
    zTreeOnAsyncSuccess(node, pastIndex);
}

function modGd(gdName, gdIndex, proIndex, index) {
    var pastIndex = gdIndex;
    var node = "2";
    $.ajax({
        url: '/pqs9900/device/updateGd',
        type: 'POST',
        dataType: "text",
        data: {
            proIndex: proIndex,
            gdIndex: gdIndex,
            name: gdName
        },
        async: false,
        success: function (data) {
            var info = $.parseJSON(data);
            if (info.code == 200) {
                layer.msg('修改成功!', {icon: 1, time: 1000});
            } else if (info.code == 400) {
                layer.msg('修改失败！名称已存在', {icon: 2, time: 1000});
            } else if (info.code == 501) {
                layer.msg(info.message, {icon: 2, time: 1000});
            } else {
                layer.msg('修改失败！', {icon: 2, time: 1000});
            }

            layer.close(index);
            getTree();
            zTreeOnAsyncSuccess(node, pastIndex);
        }

    });
}

$('#importExl').click(function () {
    layer.open({
        type: 2,
        title: '批量导入',
        shadeClose: true,
        shade: 0.3,
        area: ['380px', '200px'],
        maxmin: false,
        content: 'importdev',
        scrollbar: false,
        end: function () {
            var tips = $("#tips").val();
            var expset = "first";
            if (tips.length > 0) {
                layer.open({
                    title: '提示',
                    content: tips,
                    yes: function (index, layero) {
                        $("#tips").val("")
                        layer.close(index);
                        getTree(expset);
                    }
                });
            }
        }
    });
});

$('#exportExl').click(function () {
    layer.confirm('是否确认导出？', function (index) {
        $.ajax({
            type: 'POST',
            url: '/pqs9900/device/exportDev',
            data: {},
            dataType: 'text',
            async: false,
            success: function (data) {
                if (data == "success") {
                    self.location.href = "/pqs9900/device/exportExcel";
                } else {
                    layer.msg('导出失败！', {icon: 2, time: 1000});
                }
            }
        });
        layer.close(index);
    });
});


$('#download').click(function () {
    window.location.href = "/pqs9900/device/downDevPloy";
});

$("#push").click(function () {
    var dataStr = '"data":{"type":"10"}';
    var leng = dataStr.length;
    var lengStr = '0000' + leng.toString();
    lengStr = lengStr.substring(lengStr.length - 4, lengStr.length);
    var jsonStr = 'len:' + lengStr + dataStr;
    layer.confirm('是否向前置推送消息？', function () {
        var layy = ityzl_SHOW_LOAD_LAYER();
        $.ajax({
            type: 'POST',
            url: '/pqs9900/device/pushNode',
            data: {
                message: jsonStr
            },
            dataType: 'text',
            success: function (data) {
                var info = $.parseJSON(data);
                if (info.code == 200) {
                    layer.msg(info.message, {icon: 1, time: 5000});
                } else if (info.code == 500) {
                    layer.msg(info.message, {icon: 2, time: 2000});
                }

                ityzl_CLOSE_LOAD_LAYER(layy);
            }
        });
    })
})

$('#updateAllLimit').click(function () {
    layer.confirm('是否确认批量更新限值？', function (index) {
        var layy = ityzl_SHOW_LOAD_LAYER();
        $.ajax({
            type: 'POST',
            url: '/pqs9900/device/updateAllLimit',
            data: {},
            dataType: 'text',
            async: false,
            success: function (data) {
                var info = $.parseJSON(data);
                if (info.code == 200) {
                    layer.msg('操作成功！', {icon: 1, time: 1000});
                } else {
                    layer.msg('操作失败！', {icon: 2, time: 1000});
                }
                ityzl_CLOSE_LOAD_LAYER(layy);
            }
        });
        layer.close(index);
    });
});
