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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'orderno', title: __('Orderno'), operate: 'LIKE'},
                        {field: 'ordertype', title: __('Ordertype'), searchList: {"1":__('Ordertype 1'),"2":__('Ordertype 2'),"3":__('Ordertype 3')}, formatter: Table.api.formatter.normal},
                        {field: 'company_id', title: __('Company_id')},
                        {field: 'company.name', title: __('Company.name'), operate: 'LIKE'},
//                        {field: 'staff_id', title: __('Staff_id'), operate:false, visible:false},
                        {field: 'staff.truename', title: __('Staff.truename'), operate: 'LIKE'},
                        {field: 'staff.mobile', title: __('Staff.mobile'), operate: 'LIKE'},
//                        {field: 'user_id', title: __('User_id'), operate:false, visible:false},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'user_name', title: __('User_name'), operate: 'LIKE'},
//                        {field: 'user_car_id', title: __('User_car_id'), operate: false, visible: false},
                        {field: 'user_car_number', title: __('User_car_number'), operate: 'LIKE'},
                        {field: 'user_mobile', title: __('User_mobile'), operate: 'LIKE'},
                        {field: 'user_address', title: __('User_address'), operate: 'LIKE'},
//                        {field: 'pre_order_id', title: __('Pre_order_id'), operate:false, visible:false},
                        {field: 'pre_order.pre_order_no', title: __('Order.pre_order_no'), operate: 'LIKE'},
//                        {field: 'servicetype_id', title: __('Servicetype_id'), operate:false, visible:false},
                        {field: 'servicetype.title', title: __('Servicetype.title'), operate: 'LIKE'},
                        {field: 'server_time', title: __('Server_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'server_info', title: __('Server_info'), operate: 'LIKE'},
                        {field: 'server_images', title: __('Server_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
//                        {field: 'package_id', title: __('Package_id'), operate:false, visible:false},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'paytype', title: __('Paytype'), searchList: {"1":__('Paytype 1'),"2":__('Paytype 2'),"3":__('Paytype 3')}, formatter: Table.api.formatter.normal},
                        {field: 'pay_fee', title: __('Pay_fee'), operate:'BETWEEN'},
                        {field: 'appen_fee', title: __('Appen_fee'), operate:'BETWEEN'},
                        {field: 'total_fee', title: __('Total_fee'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'hexiao_time', title: __('Hexiao_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'cancel_time', title: __('Cancel_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'cancel_reason', title: __('Cancel_reason'), operate: 'LIKE'},
                        {field: 'finish_time', title: __('Finish_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'next_date', title: __('Next_date'), operate: 'LIKE'},
                        {field: 'next_carlicheng', title: __('Next_carlicheng'), operate: 'LIKE'},
//                        {field: 'pay_order_id', title: __('Pay_order_id'), operate: false, visible: false},
                        {field: 'operate', title: __('Operate'), table: table,
                            buttons:[
                                {
                                    name:'appenlist',
                                    text:'追加服务项',
                                    title:'追加服务项',
                                    icon:'fa fa-exclamation-circle',
                                    classname:'btn btn-xs btn-info btn-dialog',
                                    url:'orderappen/index/order_id/{ids}?dialog=1',
                                    target:'_self',
                                    extend: 'data-area=["90%","90%"]',
                                },

                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

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