<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <meta name="decorator" content="base" />
    <meta charset="utf-8">
    <title>layuiAdmin 网站用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
    <title>编辑角色</title>
    <style>html{background-color: #fff;padding-bottom: 50px;}</style>
</head>
<body>

<div class="layui-form">
    <div class="layui-card-body">

            <div id="textDiv">
                <div class="layui-form-item">
                    <div class="contentBody ">
                        <label class="layui-form-label"><i class="mark">*</i>角色名称：</label>
                        <div class="layui-input-inline">
                            <input name="roleId" hidden value="${role.id}">
                            <input type="text" name="name" lay-verify="required" autocomplete="off" value="${role.name}" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <%--<div class="layui-form-item layui-hide">
              <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
            </div>--%>
    </div>
    <div class="operate-footer">
        <button class="layui-btn " lay-submit lay-filter="component-form-element" <%--onclick="addRole()"--%>>保存</button>
        <button class="layui-btn layui-btn-primary" onclick="cancel()">取消</button>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/ueditor/1.4.3/third-party/jquery-1.10.2.js"></script>
<script>
    layui.use(['form','table'], function(){
        var $ = layui.$;
        form = layui.form;
        form.verify({
            loginNameRule:[/^[0-9A-Za-z]{6,20}$/,'登录名只能是6-20位数字字母组合'],
            passwordRule: [/^[0-9A-Za-z]{6,20}$/,'登录名只能是6-20位数字字母组合'],
        });

        form.on('submit(component-form-element)',function(){
            var roleId=$("input[name=roleId]").val();
            var name=$("input[name=name]").val();
            var sort=$("input[name=sort]").val();
            $.ajax({
                type: 'post',
                data:{roleId:roleId,name:name,sort:sort},
                url: "${ctx}/member/saveEditPlatformRole",
                success: function (data) {
                    if (data == '200') {
                        var index = parent.layer.getFrameIndex(window.name);
                        //再执行关闭
                        layer.msg('编辑成功！', {icon:1,time:1000},function(){
                            parent.layer.close(index);
                            parent.location.reload(); //刷新父页面
                        })
                    } else if (data == '202') {
                        layer.msg("编辑失败", {icon: 2});
                    } else if (data == '205') {
                        layer.msg("角色名称已存在！", {icon: 2});
                    } else {
                        layer.msg("参数信息有误，请检查！", {icon: 2});
                    }
                },
                error: function (e) {
                    layer.msg("请刷新！", {icon: 2});
                    return;
                }
            })
        })

    });
    function cancel(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
</script>
</body>
</html>
