/**
 * 修改通用字典类型
 */
$(document).ready(function () {
    var dicTypeIndex = parent.$("#dicTypeIndex").val();
    $.ajax({
        type: "post",
        url: "/pqs9900/type/selType",
        data: {"dicTypeIndex": dicTypeIndex},
        success: function (data) {
            if (data[0].dicTypeDiscribe == null) {
                data[0].dicTypeDiscribe = "暂无描述";
            }
            $("#dicTypeName").val(data[0].dicTypeName);
            $("#dicTypeDescription").val(data[0].dicTypeDiscribe);
        }
    })
    //取消
    $("#close").click(function () {
        parent.layer.closeAll();
        parent.$("#u1").html("");
    });
    $("#updateinsertAddDicType").click(function () {
        var dicTypeName = $("#dicTypeName").val();
        dicTypeName = dicTypeName.replace(/(^\s*)|(\s*$)/g, '');
        dicTypeName = filterXSS(dicTypeName);
        var re = chinesez;//只能输入汉字
        if (!re.test(dicTypeName)) {
            layer.tips('通用字典名非法', '#dicTypeName', {
                tips: [1, 'red'] //还可配置颜色
            });
            $("#dicTypeName").val("");
            $("#dicTypeName").prop("placeholder", "通用字典名由汉字组成");
        } else {
            var dicTypeDescription = $("#dicTypeDescription").val();
            dicTypeDescription = filterXSS(dicTypeDescription);
            dicTypeDescription = dicTypeDescription.replace(/(^\s*)|(\s*$)/g, '');
            $.ajax({
                url: '/pqs9900/type/updateType',
                type: 'POST',
                dataType: "text",
                data: {
                    dicTypeIndex: dicTypeIndex,
                    dicTypeName: dicTypeName,
                    dicTypeDiscribe: dicTypeDescription
                },
                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 () {
                                parent.getTree();
                                parent.cc(parent.splitTree());
                                parent.layer.closeAll()
                            });
                        } else if (data == 0) {
                            layer.msg("字典类型已存在", {
                                icon: 5,
                                time: 1000
                            })
                        } else if (data == 2) {
                            layer.msg("类型名称为空", {
                                icon: 5,
                                time: 1000
                            })
                        } else if (data == 3) {
                            layer.msg("类型名称非法，只由汉字组成", {
                                icon: 5,
                                time: 1000
                            })
                        } else {
                            layer.msg("修改字典类型失败", {
                                icon: 5,
                                time: 1000
                            })
                        }
                    }
                }
            });
        }
    });
})