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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'head_image', title: __('Head_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'classes_lib_id', title: __('Classes_lib_id')},
                        {field: 'time', title: __('Time'),operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'jointype', title: __('Jointype'), searchList: {"1":__('Jointype 1'),"0":__('Jointype 0')}, formatter: Table.api.formatter.normal},
                        {field: 'havetype', title: __('Havetype'), searchList: {"1":__('Havetype 1'),"0":__('Havetype 0')}, formatter: Table.api.formatter.normal},
                        {field: 'schoolclasseslib.title', title: __('Schoolclasseslib.title'), operate: 'LIKE'},
                        {field: 'schoolclasseslib.headimage', title: __('Schoolclasseslib.headimage'), operate: false, 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);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                $("#c-classes_lib_id").data("params", function (obj) {
                    //obj为SelectPage对象
                    return {custom: {shop_id: Config.shop_id}};
                });


                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});