@extends('admin/layout')
@section('content')
    <body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    {{--<div class="ibox-title"></div>--}}
                    <div class="ibox-content">

                        <div class="input-group">
                            <button type="button" class="btn btn-md btn-primary"
                                    style="margin-left: 10px"
                                    onclick="units.add(0)"> <span
                                    class="glyphicon glyphicon-plus"></span> 添加
                            </button>
                        </div>
                        <hr>
                        <div class="table-responsive">

                            <table id="table" class="table table-condensed" data-mobile-responsive="true"></table>

                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
    </body>
@endsection
@section('footer')

    <script>
        var units = {
            search: function () {
                tips.selectPage();
            },
            add: function () {
                layer.open({
                    type: 2,
                    content: ['/admin/classroom/questions-and-answers-update/0'],
                    area: ['60%', '100%'],
                    title: '添加'
                });
            },
            update: function (id) {
                layer.open({
                    type: 2,
                    content: ['/admin/classroom/questions-and-answers-update/' + id],
                    area: ['60%', '100%'],
                    title: '编辑'
                });
            },
            del: function (id) {
                tips.ajax({
                    url: ['/admin/classroom/questions-and-answers-delete/' + id],
                    type: 'get'
                });
                window.location.reload();
            },
        };

        var config = {};
        config.url = '/admin/classroom/questions-and-answers';
        config.columns = [ //字段
            {
                title: '序号', align: 'center', formatter: function (value, item, index) {
                    return index + 1;
                },
                width: '20px'
            },
            {title: '标题', field: 'title', align: 'center', width: '500px'},
            /*{title: '内容', field: 'content', align: 'center', width: '300px'},*/
            {title: '创建时间', field: 'created_at', align: 'center', width: '100px'},
            {
                title: '操作', field: 'id', align: 'center',
                formatter: function (value, rows) {
                    var str = '<button onclick="units.update(' + rows.id + ')" class="btn btn-xs"><span class="glyphicon glyphicon-edit"></span>编辑</button>&nbsp;';
                    str += '<button onclick="units.del(' + rows.id + ')" class="btn btn-xs"><span class="glyphicon glyphicon-edit"></span>删除</button>&nbsp;';
                    return str;
                }
            }
        ];
        tips.bootstrapTable(config);

    </script>
@endsection