layui.use(['form', 'layer'], function () {
    var form = layui.form
    layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    form.on("submit(save)", function (data) {
        //弹出loading
        //var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});

        //弹出loading
        var index = layer.msg('数据提交中，请稍候...', {
            icon: 16,
            shade: 0.8,
            time:true //取消自动关闭
        });

        //实际使用时的提交信息
        $.ajax( {
            url : "/upms/permission/save",
            type : "POST",
            dataType:"json",
            contentType:'application/json;charset=UTF-8',
            data:JSON.stringify({authCode:$("#authCode").val(),
                authName:$("#authName").val(),
                authType: $('input[name="authType"]:checked').val(),
                parentId: $("#parentId").val(),
                permissionName: $("#permissionName").val(),
                permission: $("#permission").val(),
                linkUrl: $("#linkUrl").val(),
                remark: $("#remark").val(),
                id: $("#id").val()
            }),
            success : function(res) {
                layer.close(index);//手动关闭
                layer.msg(res.message);
                layer.closeAll("iframe");
                //刷新父页面
                parent.location.reload();
            },
            error:function(e){
                layer.close(index);//手动关闭
                layer.msg("操作失败,请重试!");
                layer.closeAll("iframe");
                //刷新父页面
                parent.location.reload();
            }
        })
    })
})