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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'car_id', title: __('Car_id')},
                        {field: 'car.chepaihao', title: __('Car.chepaihao'), operate: 'LIKE'},
                        {field: 'car.brand', title: __('Car.brand'), operate: 'LIKE'},
                        {field: 'car.xinghao', title: __('Car.xinghao'), operate: 'LIKE'},
                        {field: 'coach_id', title: __('Coach_id')},
                        {field: 'coach.nickname', title: __('Coach.nickname'), operate: 'LIKE'},
                        {field: 'info', title: __('Info'), operate: 'LIKE'},
                        {field: 'lipei_price', title: __('Lipei_price'), operate:'BETWEEN'},
                        {field: 'zeren', title: __('Zeren'), operate: 'LIKE'},
                        {field: 'baoxianshangfu', title: __('Baoxianshangfu'), operate:'BETWEEN'},
                        {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {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;
});
