

<title>RtspLiveServer</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a><cite>视频管理</cite></a>
        <a><cite>视频用户</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-front-formlist">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-block">
                        <input type="text" name="user" placeholder="请输入" maxlength="30" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-useradmin" data-type="batchdel">删除</button>
                <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button>
            </div>

            <table id="LAY-manage" lay-filter="LAY-manage"></table>
            <script type="text/html" id="imgTpl">
                <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
            </script>
            <script type="text/html" id="table-toolbar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script>
    //.use('video', layui.factory('video'))必需加否则影响部分表格加载失败
    layui.use('auth', layui.factory('auth')).use(['admin', 'auth', 'table'], function () {
        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , table = layui.table
            , form = layui.form;

        form.render(null, 'layadmin-front-formlist');

        //事件
        var active = {
            batchdel: function () {
                var checkStatus = table.checkStatus('LAY-manage')
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }
                layer.confirm('确定删除选中视频用户？', function (index) {
                    var arr = new Array();
                    $.each(checkData, function (i, e) {
                        arr.push(e.user);
                    });
                    var names = arr.join(',');
                    $.ajax(
                        {
                            type: "POST",
                            url: '/api/auth_delete',
                            cache: false,//禁止缓存
                            data: {
                                'user': names
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                var res = XMLHttpRequest.responseJSON;
                                if (res != undefined)
                                    layer.msg(res.message, { icon: 0, time: 2000 });
                            },
                            success: function (data) {
                                layer.close(index); //执行关闭
                                table.reload('LAY-manage');
                            }
                        });

                });
            }
            , add: function () {
                admin.popup({
                    title: '添加视频用户'
                    , area: ['600px', '350px']
                    , id: 'LAY-popup-user-add'
                    , shadeClose: false
                    , success: function (layero, index) {
                        view(this.id).render('video/authform').done(function () {
                            form.render(null, 'layuiadmin-form');

                            //监听提交
                            form.on('submit(LAY-front-submit)', function (data) {
                                var field = data.field; //获取提交的字段
                                $.ajax(
                                    {
                                        type: "POST",
                                        url: '/api/auth_save',
                                        cache: false,//禁止缓存
                                        data: field,
                                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                                            var res = XMLHttpRequest.responseJSON;
                                            if (res != undefined)
                                                layer.msg(res.message, { icon: 0, time: 2000 });
                                        },
                                        success: function (data) {
                                            layui.table.reload('LAY-manage'); //重载表格
                                            layer.close(index); //执行关闭
                                        }
                                    });
                            });
                        });
                    }
                });
            }
        };

        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>