define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'books/certificate/index' + location.search,
                    add_url: 'books/certificate/add',
                    // edit_url: 'books/certificate/edit',
                    del_url: 'books/certificate/del',
                    multi_url: 'books/certificate/multi',
                    import_url: 'books/certificate/import',
                    table: 'certificate',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.nickname', title: __('发放用户')},
                        {field: 'goods.title', title: __('体验书籍')},
                        {field: 'free_start_time', title: __('体验开始时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'free_end_time', title: __('体验结束时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'effective_time', title: __('Effective_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'status', title: __('使用状态'), searchList: {"0":__('未使用'),"1":__('已使用')}, formatter: Table.api.formatter.status},
                        {field: 'is_expire', title: __('是否过期'), searchList: {"0":__('是'),"1":__('否')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'free_day', title: __('Free_day')},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
