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

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

            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: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'type', title: __('文件类型'), searchList: {"0":__('课件'),"1":__('资源'),"2":__('资料包')}, formatter: Table.api.formatter.normal},
                        // {field: 'books_id', title: __('Books_id')},
                        {field: 'is_specimen', 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: 'is_deleted', title: __('Is_deleted'), searchList: {"0":__('Is_deleted 0'),"1":__('Is_deleted 1')}, formatter: Table.api.formatter.normal},
                        {field: 'sort', title: __('Sort')},
                        {
                            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;
});
