/**
 *修改资源
 */
function getmange() {
    var resIndex = parent.$("#ResIndex").val();
    $.ajax({
        type: "post",
        url: "/pqs9900/manage/getmange",
        data: {
            resIndex: resIndex
        },
        success: function (data) {
            $("#name").val(data.name);
            $("#description").val(data.description);
            $.each(data.getType, function (i, item) {
                var option = $("<option value='" + item.dicIndex + "'>" + item.dicName + "</option>");
                $("#type").append(option);
            })
            var type = data.type;
            if (type === "暂无资源类目") {
                $("#type").prepend("<option value='暂无资源类目'>=======请选择=======</option>");
                $("#type").val("暂无资源类目");
            } else {
                $("#type").val(type);
            }
        }
    })
}

var i;
$(document).ready(function () {
    getmange();
    var resIndex = parent.$("#ResIndex").val();
    $("#update").click(function () {
        var name = $("#name").val();
        name = filterXSS(name);
        if (name == '') {
            layer.tips('资源名称不能为空',
                '#name', {
                    tips: [1, 'red']
                    //还可配置颜色
                });
        } else {
            var description = $("#description").val();
            description = filterXSS(description);
            if (description == '') {
                layer.tips('资源描述不能为空',
                    '#description', {
                        tips: [1, 'red']
                        //还可配置颜色
                    });
            } else {
                var type = $("#type").val();
                $.ajax({
                    type: "post",
                    url: "/pqs9900/manage/updateManageList",
                    data: {
                        resIndex: resIndex,
                        name: name,
                        type: type,
                        description: description
                    },
                    beforeSend: function () {
                        i = ityzl_SHOW_LOAD_LAYER();
                    },
                    success: function (data) {
                        if (data == 1) {
                            layer.msg("修改成功", {icon: 1, time: 2000}, function () {
                                parent.load();
                                parent.layer.closeAll()
                            });
                        } else if(data == 2){
                            layer.msg("该资源不存在或已被删除！", {icon: 5, time: 2000}, function () {
                                parent.layer.closeAll()
                            });
                        }else {
                            layer.msg("上传失败,上传的文件字段不正确", {icon: 5, time: 2000}, function () {
                                parent.layer.closeAll()
                            });
                        }
                    },
                    cache: false,
                });
                //***********关闭loading
                ityzl_CLOSE_LOAD_LAYER(i);
            }
        }
    })

});

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