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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                asyndownload: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', visible:false,title: __('User_id')},
                        {field: 'activity_order_id', visible:false,title: __('Activity_order_id')},
                        {field: 'activity_id',visible:false, title: __('Activity_id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'order.totalprice', title: __('Order.totalprice'), operate:'BETWEEN'},
                        {field: 'order.order_no',visible:false, title: __('Order.order_no'), operate:'BETWEEN'},
                        {field: 'order.num', title: __('购买人数'), operate:'BETWEEN'},

                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.realname',visible:false, title: __('User.realname'), operate: 'LIKE'},
                        {field: 'user.mobile',visible:false, title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'order.order_no',visible:false, title: __('Order.order_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'activity.title',visible:false, title: __('Activity.title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},


                        {field: 'address_city',visible:false, title: __('Address_city'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'cate_ids', title: __('Cate_ids'), searchList: cateListJson, formatter: Table.api.formatter.flag},
                        {field: 'province',visible:false, title: __('Province')},
                        {field: 'city',visible:false, title: __('City')},
                        {field: 'district',visible:false, title: __('District')},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'address_detail', title: __('Address_detail'), operate: 'LIKE'},
                        {field: 'longitude',visible:false, title: __('Longitude'), operate: 'LIKE'},
                        {field: 'latitude',visible:false, title: __('Latitude'), operate: 'LIKE'},
                        {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'sign_start_time', title: __('Sign_start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'sign_end_time', title: __('Sign_end_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'stock', title: __('Stock')},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'recommend',visible:false, title: __('Recommend'), searchList: {"0":__('Recommend 0'),"1":__('Recommend 1')}, formatter: Table.api.formatter.normal},
                        {field: 'hot',visible:false, title: __('Hot'), searchList: {"0":__('Hot 0'),"1":__('Hot 1')}, formatter: Table.api.formatter.normal},
                        {field: 'new',visible:false, title: __('New'), searchList: {"0":__('New 0'),"1":__('New 1')}, formatter: Table.api.formatter.normal},
                        {field: 'sale',visible:false, title: __('Sale')},
                        {field: 'views',visible:false, title: __('Views')},
                        {field: 'add_type',visible:false, title: __('Add_type'), searchList: {"1":__('Add_type 1'),"2":__('Add_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'add_id',visible:false, title: __('Add_id')},
                        {field: 'feel', title: __('Feel'), searchList: {"0":__('Feel 0'),"1":__('Feel 1')}, formatter: Table.api.formatter.normal},
                        {field: 'sign_num',visible:false, title: __('Sign_num')},
                        {field: 'verification_num',visible:false, title: __('Verification_num')},
                        {field: 'collect',visible:false, title: __('Collect')},
                        {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: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'school/activity/order/order_detail/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'school/activity/order/order_detail/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'school/activity/order/order_detail/destroy',
                                    refresh: true
                                }
                            ],
                            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;
});
