layui.config({
    base: '../../js/',
});
layui.use(['form','layer','admin','upload','laytpl'],function(){
    var form = layui.form;
    var $ = layui.jquery;
    var layer = parent.layer === undefined ? layui.layer : top.layer;
    var upload = layui.upload;
    var laytpl = layui.laytpl;

    var lastsrc = $(".logo").val();
    //上传网站图标
    upload.render({
        elem: '.thumbImg',
        url: '/GoBlogApi/upload/?lastsrc='+lastsrc,
        method : "post",
        done: function(res, index, upload){
            if (res.code == 0) {
                $('.logo').val(res.data.src);                
            } else {
                top.layer.msg(res.msg, {icon: 2, time:3000});
            }
        }
    });
    
    //提交保存
    form.on("submit(editInfo)",function(data){
        $(this).text("提交中...").attr("disabled","disabled").addClass("layui-disabled");

        var data = {
            title       : $(".title").val(),
            logo        : $(".logo").val(),
            url         : $(".url").val(),
            desc        : $(".desc").val(),
            remark      : $(".remark").val(),
            status      : $('#status').val()
        };

        var id = $("#id").val();
        var type = 'post';
        if (id>0) {
            type = 'put';
            data = $.extend(data,{id:id});
        }
        var successfun = function(){
            layer.closeAll("iframe");
            parent.location.reload();
        };
        ZjqAdminAjax('/GoBlogApi/link/', type, data, successfun);
        $(this).text("立即提交").removeAttr("disabled").removeClass("layui-disabled");
        return false;
    });

});