/**
 * 修改变压器
 */
$(document).ready(function () {
    var tfIndex = parent.$("#tfIndex").val();
    var subIndex = parent.$("#subIndex").val();
    var sub;
    var tName=parent.tfName;
    var node=parent.nodIndex;
    var typeId = "";
    $.ajax({
        type: "POST",
        url: "/pqs9900/trans/selectId",
        data: {"tfIndex": tfIndex},
        success: function (data) {
            sub = data.subIndex;
            $("#tfName").val(data.tfName);
            $("#description").val(data.tfDescribe);
            $.each(data.writings, function (i, item) {
                var option = $("<option value='" + item.dicIndex + "'>" + item.dicName + "</option>");
                $("#Wring").append(option);
            })

            var Wring = data.wiring;
            if (Wring === "暂无接线方式") {
                $("#Wring").prepend("<option value='暂无接线方式'>=======请选择=======</option>");
                $("#Wring").val("暂无接线方式");
            } else {
                $("#Wring").val(Wring);
            }
        }
    })
    $("#close").click(function () {
        parent.layer.closeAll();
    });
    $("#updateTrans").click(function () {
        if (subIndex == '') {
            subIndex = sub;
        } else {
            subIndex = subIndex;
        }
        var tfName = $("#tfName").val();
        tfName = tfName.replace(/(^\s*)|(\s*$)/g,
            '');
        tfName = filterXSS(tfName);
        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/updateTrans',
            type: 'POST',
            dataType: "text",
            data: {
                tfIndex: tfIndex,
                tfName: tfName,
                wiring: wiring,
                description: description,
                subIndex: subIndex
            },
            success: function (data) {
                //没有权限的请求
                if (data == 300) {
                    location.href = '/pqs9900/auth/unauthorized';
                    //没有登陆的请求
                } else if (data == 301) {
                    location.href = '/pqs9900';
                } else {
                    if (data == 1) {
                        layer.msg("修改变压器成功", {
                            icon: 6,
                            time: 1000
                        }, function () {
                            if(tName==undefined||node==undefined){
                                parent.load();
                            }else {
                                parent.queryInfo(tName,node);
                            }
                            parent.getTree();
                            parent.layer.closeAll();
                        });
                    } else if (data == 0) {
                        layer.msg("名称已存在", {
                            icon: 5,
                            time: 1000
                        })
                    } else if(data == 3){
                        layer.msg("修改变压器失败，原因是变压器名为空", {
                            icon: 5,
                            time: 1000
                        })
                    }else if(data == 4){
                        layer.msg("修改变压器失败，原因是变压器名非法", {
                            icon: 5,
                            time: 1000
                        })
                    }else if(data == 5){
                        layer.msg("修改变压器失败，原因是变压器名称长度在500内", {
                            icon: 5,
                            time: 1000
                        })
                    }
                }
            }
        });
    });

})