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

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

            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.color', title: __('Car.color'), operate: 'LIKE'},
                        {field: 'car.type', title: __('Car.type'), operate: 'LIKE'},
                        {field: 'car.brand', title: __('Car.brand'), operate: 'LIKE'},
                        {field: 'car.xinghao', title: __('Car.xinghao'), operate: 'LIKE'},
                        {field: 'car.chejia', title: __('Car.chejia'), operate: 'LIKE'},
                        {field: 'car.fadongji', title: __('Car.fadongji'), operate: 'LIKE'},
                        {field: 'car.licheng', title: __('Car.licheng')},
                        {field: 'car.zhucetime', title: __('Car.zhucetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'fix_name', title: __('Fix_name'), operate: 'LIKE'},
                        {field: 'fix_info', title: __('Fix_info'), operate: 'LIKE'},
                        {field: 'fix_price', title: __('Fix_price'), operate:'BETWEEN'},
                        {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'coach_id', title: __('Coach_id')},
                        {field: 'coach.nickname', title: __('Coach.nickname'), operate: 'LIKE'},
                        {field: 'coach.mobile', title: __('Coach.mobile'), operate: 'LIKE'},
                        {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;
});
