<?php /*a:3:{s:68:"/home/affivpnx/app.peakwork.pro/app/admin/view/system/group_add.html";i:1763742186;s:65:"/home/affivpnx/app.peakwork.pro/app/admin/view/public/header.html";i:1763742186;s:65:"/home/affivpnx/app.peakwork.pro/app/admin/view/public/footer.html";i:1763742186;}*/ ?>
<!doctype html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>后台登录-<?php echo htmlentities($system_name); ?></title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" href="/static/admin/css/font.css">
    <link rel="stylesheet" href="/static/admin/css/xadmin.css">
    <script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
    <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
    <script src="/static/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/admin/js/xadmin.js?date=<?php echo date('Ymd'); ?>"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="/static/admin/js/html5.min.js"></script>
    <script src="/static/admin/js/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form method="post" class="layui-form layui-form-pane">
            <input type="hidden" name="id" value="<?php echo htmlentities($id); ?>">
            <div class="layui-form-item">
                <label for="title" class="layui-form-label">
                    <span class="x-red">*</span>角色名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="title" name="title" required="" lay-verify="required|nikename"
                           autocomplete="off" class="layui-input" value="<?php echo htmlentities($title); ?>">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">
                    拥有权限
                </label>
                <table class="layui-table layui-input-block">
                    <tbody id="group_add">
                    <?php if(is_array($menu) || $menu instanceof \think\Collection || $menu instanceof \think\Paginator): if( count($menu)==0 ) : echo "" ;else: foreach($menu as $p_k=>$p_menu): ?>
                    <tr>
                        <td>
                            <input name="rule_id[]" lay-skin="primary" type="checkbox" lay-filter="father"
                                   lay-verify="check" value="<?php echo htmlentities($p_k); ?>" title="<?php echo htmlentities($p_menu['name']); ?>"
                                   <?php if(in_array((string)$p_k,$rule,TRUE)): ?>checked<?php endif; ?>>
                        </td>
                        <?php if(!empty($p_menu['children'])): ?>
                        <td>
                            <div class="layui-input-block">
                                <?php if(is_array($p_menu['children']) || $p_menu['children'] instanceof \think\Collection || $p_menu['children'] instanceof \think\Paginator): if( count($p_menu['children'])==0 ) : echo "" ;else: foreach($p_menu['children'] as $c_k=>$c_menu): ?>
                                <input name="rule_id[]" lay-skin="primary" type="checkbox"
                                       lay-verify="check" value="<?php echo htmlentities($p_k.'-'.$c_k); ?>" title="<?php echo htmlentities($c_menu['name']); ?>"
                                       <?php if(in_array($p_k.'-'.$c_k,$rule)): ?>checked<?php endif; ?>>
                                <?php if(!empty($c_menu['children'])): if(is_array($c_menu['children']) || $c_menu['children'] instanceof \think\Collection || $c_menu['children'] instanceof \think\Paginator): if( count($c_menu['children'])==0 ) : echo "" ;else: foreach($c_menu['children'] as $cc_k=>$cc_menu): ?>
                                <input name="rule_id[]" lay-skin="primary" type="checkbox"
                                       lay-verify="check" value="<?php echo htmlentities($p_k.'-'.$c_k.'-'.$cc_k); ?>" title="<?php echo htmlentities($cc_menu['name']); ?>"
                                       <?php if(in_array($p_k.'-'.$c_k.'-'.$cc_k,$rule)): ?>checked<?php endif; ?>>
                                <?php endforeach; endif; else: echo "" ;endif; ?>
                                <?php endif; ?>
                                <?php endforeach; endif; else: echo "" ;endif; ?>
                            </div>
                        </td>
                        <?php endif; ?>
                    </tr>
                    <?php endforeach; endif; else: echo "" ;endif; ?>
                    </tbody>
                </table>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        var form = layui.form;

        //自定义验证规则
        form.verify({
            nikename: function (value) {
                if (value.length < 2) {
                    return '昵称至少得2个字符啊';
                }
            },
            check: function () {
                var check_num = $('#group_add input:checked').length;
                if (!check_num)
                    return '请选择权限';
            }
        });

        //监听提交
        form.on('submit(add)', function (data) {
            console.log(data.field);
            $.ajax({
                url: "<?php echo url('admin/System/groupAdd'); ?>",
                type: 'post',
                data: data.field,
                dataType: 'json',
                success: function (res) {
                    layer.msg(res.msg);
                    if (res.status == '200') {
                        setTimeout(function () {
                            // 获得frame索引
                            // var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            // parent.layer.close(index);
                            parent.location.reload();
                        }, 1000);
                    }
                },
                error: function () {
                    layer.msg('系统繁忙,请重试');
                }
            });
            return false;
        });

        //全选
        form.on('checkbox(father)', function (data) {
            if (data.elem.checked) {
                $(data.elem).parent().siblings('td').find('input').prop("checked", true);
                form.render();
            } else {
                $(data.elem).parent().siblings('td').find('input').prop("checked", false);
                form.render();
            }
        });
    });
</script>
</body>
</html>
<script type="application/javascript">
    /**
     * 统一接口返回提示弹窗
     * type 1-成功 2-失败
     * info 提示信息
     * */
    function tipAction(type, info) {
        layer.msg(info, {icon: type, time: 1500})
    }

    //图片放大
    function showBig(obj) {
        let img_src = $(obj).attr('src');
        layer.open({
            type: 1,
            area: ['70%', 'auto'],
            shadeClose: true,
            title: false,
            closeBtn: false,
            content: `<div style=""><img src="${img_src}" alt="" width="100%"></div>`
        });
    }
</script>

