<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>核销员管理 - VR票务</title>
    {{include file="public/head" }}
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">核销员管理</div>
        <div class="layui-card-body">
            <!-- 搜索栏 -->
            <div class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">关键词</label>
                        <div class="layui-input-inline">
                            <input type="text" name="keywords" value="" placeholder="姓名/用户ID" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-inline">
                            <select name="status" lay-search>
                                <option value="">全部</option>
                                <option value="1">启用</option>
                                <option value="0">禁用</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn" lay-submit lay-filter="search">搜索</button>
                        <a href="{:MyUrl('plugins_vr_ticket/admin/verifier/save')}" class="layui-btn layui-btn-normal">添加核销员</a>
                    </div>
                </div>
            </div>

            <!-- 数据表格 -->
            <table class="layui-hide" id="table" lay-filter="table"></table>

            <script type="text/template" id="statusTpl">
                {{# if (d.status == 1) { }}
                    <span class="layui-badge layui-bg-green">启用</span>
                {{# } else { }}
                    <span class="layui-badge layui-bg-gray">禁用</span>
                {{# } }}
            </script>

            <script type="text/template" id="actionTpl">
                <a href="{:MyUrl('plugins_vr_ticket/admin/verifier/save')}?id={{d.id}}" class="layui-btn layui-btn-xs">编辑</a>
                <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs" lay-fn="del" data-id="{{d.id}}">禁用</a>
            </script>
        </div>
    </div>
</div>

{{include file="public/footer" }}
<script>
layui.use('table', function() {
    var table = layui.table;
    var form = layui.form;

    table.render({
        elem: '#table',
        url: '{:MyUrl("plugins_vr_ticket/admin/verifier/list")}',
        cols: [[
            {field: 'id', title: 'ID', width: 80},
            {field: 'name', title: '核销员名称', minWidth: 120},
            {field: 'user_id', title: '用户ID', width: 100},
            {field: 'user_name', title: '关联用户', minWidth: 150},
            {field: 'status', title: '状态', width: 100, templet: '#statusTpl'},
            {field: 'created_at', title: '创建时间', width: 180, templet: function(d) {
                return d.created_at > 0 ? layui.util.toDateString(d.created_at * 1000) : '-';
            }},
            {field: 'action', title: '操作', width: 150, templet: '#actionTpl'},
        ]]
    });

    form.on('submit(search)', function(data) {
        table.reload('table', {where: data.field, page: {curr: 1}});
        return false;
    });

    $(document).on('click', '[lay-fn="del"]', function() {
        var id = $(this).data('id');
        layer.confirm('确认禁用该核销员？', function(index) {
            $.post('{:MyUrl("plugins_vr_ticket/admin/verifier/delete")}', {id: id}, function(res) {
                if (res.code == 0) {
                    layer.msg('操作成功');
                    table.reload('table');
                } else {
                    layer.msg(res.msg || '操作失败');
               }}
            });
            layer.close(index);
        });
    });
});
</script>
</body>
</html>
