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

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

            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: 'chepaihao', title: __('Chepaihao'), operate: 'LIKE'},
                        {field: 'color', title: __('Color'), operate: 'LIKE'},
                        {field: 'chepaicolor', title: __('Chepaicolor'), searchList: {"5":__('Chepaicolor 5'),"1":__('Chepaicolor 1'),"2":__('Chepaicolor 2'),"3":__('Chepaicolor 3'),"4":__('Chepaicolor 4'),"9":__('Chepaicolor 9'),"91":__('Chepaicolor 91'),"92":__('Chepaicolor 92'),"94":__('Chepaicolor 94'),"224":__('Chepaicolor 224'),"225":__('Chepaicolor 225')}, formatter: Table.api.formatter.normal},
                        {field: 'type', title: __('Type'), operate: 'LIKE'},
                        {field: 'brand', title: __('Brand'), operate: 'LIKE'},
                        {field: 'xinghao', title: __('Xinghao'), operate: 'LIKE'},
                        {field: 'chejia', title: __('Chejia'), operate: 'LIKE'},
                        {field: 'fadongji', title: __('Fadongji'), operate: 'LIKE'},
                        {field: 'licheng', title: __('Licheng')},
                        {field: 'is_etc', title: __('Is_etc'), searchList: {"0":__('Is_etc 0'),"1":__('Is_etc 1')}, formatter: Table.api.formatter.normal},
                        {field: 'power', title: __('Power'), searchList: {"1":__('Power 1'),"2":__('Power 2')}, formatter: Table.api.formatter.normal},
                        {field: 'seatnum', title: __('Seatnum')},
                        {field: 'xingshi_num', title: __('Xingshi_num'), operate: 'LIKE'},
                        {field: 'xingshi_images', title: __('Xingshi_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'yingyun_images', title: __('Yingyun_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'zhucetime', title: __('Zhucetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'department', title: __('Department'), operate: 'LIKE'},
                        {field: 'leasetype', title: __('Leasetype'), searchList: {"1":__('Leasetype 1'),"2":__('Leasetype 2'),"3":__('Leasetype 3')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table,
                            buttons:[
                                {
                                    name:'gpsinfo',
                                    text:'即时信息',
                                    title:'即时信息',
                                    icon:'fa fa-exclamation-circle',
                                    classname:'btn btn-xs btn-info btn-dialog',
                                    url:'car/gpsinfo/id/{ids}',
                                    target:'_self',
                                    refresh:true,
                                }
                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

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