/**
 * 新增变压器
 */
$(document).ready(function () {
    var subIndex = parent.$("#subIndex").val();
    var tName = parent.tfName;
    var node = parent.nodIndex;
    $.ajax({
        type: "POST",
        url: "/pqs9900/trans/selectWring",
        data: "",
        success: function (data) {
            $.each(data, function (i, item) {
                var option = $("<option value='" + item.dicIndex
                    + "'>" + item.dicName + "</option>");
                $("#Wring").append(option);
            })
        }
    })
    $("#close").click(function () {
        parent.layer.closeAll();
    })
    //新增
    $("#addTrans").click(function () {
        if (subIndex == '') {
            layer.msg('未选择变电站，请返回选择', {icon: 5, time: 1000}, function () {
                layer.close();
            });
        } else {
            var tfName = $("#tfName").val();
            tfName = filterXSS(tfName);
            tfName = tfName.replace(/(^\s*)|(\s*$)/g,
                '');
            var re = cenz;// 不能输入特殊字符
            if (!re.test(tfName)) {
                layer.tips('不能输入特殊字符且不能为空', '#tfName', {
                    tips: [1, 'red']
                });
                $("#tfName").val("");
                $("#tfName").prop("placeholder",
                    "不能输入特殊字符且不能为空");
            }
            var Wiring = $("#Wring").val();
            Wiring = filterXSS(Wiring);
            var description = $("#description").val();
            description = filterXSS(description);
            $.ajax({
                url: '/pqs9900/trans/saveTrans',
                type: 'POST',
                dataType: "text",
                data: {
                    tfName: tfName,
                    Wiring: Wiring,
                    description: description,
                    subIndex: subIndex
                },
                success: function (data) {
                    // 没有权限的请求
                    if (data.code == 300) {
                        location.href = '/pqs9900/auth/unauthorized';
                        // 没有登陆的请求
                    } else if (data.code == 301) {
                        location.href = '/pqs9900';
                    } else {
                        if (data == 0) {
                            layer.msg('名称已存在', {icon: 5, time: 1000}, function () {
                                layer.close();
                            });
                        } else if (data == 1) {
                            layer.msg('新增变压器成功', {
                                icon: 6, time: 1000
                            });
                            parent.queryInfo(tName, node);
                            parent.getTree();
                            parent.layer.closeAll();
                        } else if (data == 2) {
                            layer.msg('变压器名称为空', {
                                icon: 6, time: 1000
                            });
                            parent.queryInfo(tName, node);
                            parent.getTree();
                            parent.layer.closeAll();
                        } else if (data == 3) {
                            layer.msg('变压器类型为空', {
                                icon: 6, time: 1000
                            });
                            parent.queryInfo(tName, node);
                            parent.getTree();
                            parent.layer.closeAll();
                        } else if (data == 4) {
                            layer.msg('变压器名称非法', {
                                icon: 6, time: 1000
                            });
                            parent.queryInfo(tName, node);
                            parent.getTree();
                            parent.layer.closeAll();
                        } else if (data == 5) {
                            layer.msg('变压器描述长度为500内', {
                                icon: 6, time: 1000
                            });
                            parent.queryInfo(tName, node);
                            parent.getTree();
                            parent.layer.closeAll();
                        }
                    }
                }
            });
        }
    })

});