<!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="name" value="" placeholder="搜索模板名称" 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="{:PluginsAdminUrl('vr_ticket', 'seat_template', '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="{:PluginsAdminUrl('vr_ticket', 'seat_template', '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: '{:PluginsAdminUrl("vr_ticket", "seat_template", "list")}',
        cols: [[
            {field: 'id', title: 'ID', width: 80},
            {field: 'name', title: '模板名称', minWidth: 150},
            {field: 'category_name', title: '绑定分类', width: 150},
            {field: 'seat_count', title: '座位数', width: 100},
            {field: 'status', title: '状态', width: 100, templet: '#statusTpl'},
            {field: 'add_time', title: '创建时间', width: 180, templet: function(d) {
                return d.add_time > 0 ? layui.util.toDateString(d.add_time * 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('{:PluginsAdminUrl("vr_ticket", "seat_template", "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>
