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

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

            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: 'feel', title: __('是否免费'), searchList: {"0":__('付费课程'),"1":__('免费课程')}, formatter: Table.api.formatter.normal},
                        {field: 'classes_num', title: __('Classes_num')},
                        {field: 'use_num', title: __('Use_num')},
                        {field: 'sub_num', title: __('Sub_num')},
                        {field: 'classes_order_id',visible:false, title: __('Classes_order_id')},
                        {field: 'manystore_id',visible:false, title: __('Manystore_id')},
                        {field: 'shop_id', title: __('Shop_id')},
                        {field: 'user_id',visible:false, title: __('User_id')},
                        {field: 'classes_cate_ids',visible:false, title: __('Classes_cate_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'classes_label_ids',visible:false, title: __('Classes_label_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'self_label_tag', title: __('Self_label_tag'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        {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: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'headimage', title: __('Headimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'type', title: __('Type'), searchList: {"out":__('Type out'),"in":__('Type in')}, formatter: Table.api.formatter.normal},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},

                        {field: 'unit_price', title: __('Unit_price'), operate:'BETWEEN'},
                        {field: 'used_price', title: __('Used_price'), operate:'BETWEEN'},



                        {field: 'address_type', title: __('Address_type'), searchList: {"1":__('Address_type 1'),"2":__('Address_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'address_city', title: __('Address_city'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'province', title: __('Province')},
                        {field: 'city', title: __('City')},
                        {field: 'district', 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: 'classes_date_text', title: __('Classes_date_text'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'classes_time_text', title: __('Classes_time_text'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'virtual_num',visible:false, title: __('Virtual_num')},
                        // {field: 'sale',visible:false, title: __('Sale')},

                        {field: 'underline_price',visible:false, title: __('Underline_price'), operate:'BETWEEN'},
                        {field: 'virtual_collect',visible:false, title: __('Virtual_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: 'order.order_no',visible:false, title: __('Order.order_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'manystore.nickname',visible:false, title: __('Manystore.nickname'), operate: 'LIKE'},
                        // {field: 'manystore.avatar',visible:false, title: __('Manystore.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'shop.name',visible:false, title: __('Shop.name'), operate: 'LIKE'},
                        // {field: 'shop.image',visible:false, title: __('Shop.image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'shop.address_city', title: __('Shop.address_city'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'shop.province', title: __('Shop.province')},
                        // {field: 'shop.city', title: __('Shop.city')},
                        // {field: 'shop.district', title: __('Shop.district')},
                        // {field: 'shop.address', title: __('Shop.address'), operate: 'LIKE'},
                        // {field: 'shop.address_detail', title: __('Shop.address_detail'), operate: 'LIKE'},
                        // {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        // {field: 'user.realname', title: __('User.realname'), operate: 'LIKE'},
                        // {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        // {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {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/classes/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/classes/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/classes/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;
});
