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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},

                        {field: 'id', title: __('Group_id')},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'parent_id', title: __('Parent_id'), operate: 'BETWEEN', sortable: true},
                        {field: 'balance', title: __('Balance'), operate: 'BETWEEN', sortable: true},
                        {field: 'freeze', title: __('Freeze'), operate: 'BETWEEN', sortable: true},
                        {field: 'task_num', title: __('Task'), formatter: Table.api.formatter.search},

                        {field: 'id', title: __('Recharge'), operate: 'BETWEEN', sortable: true},
                        {field: 'id', title: __('Withdrawal'), operate: 'BETWEEN', sortable: true},
                        {field: 'id', title: __('Income'), operate: 'BETWEEN', sortable: true},

                        {field: 'invitation_code', title: __('Invitation_code'), formatter: Table.api.formatter.search},
                        {field: 'is_agent', title: __('Is_agent'), searchList: {1: __('Yes'), 0: __('No')}, formatter: Table.api.formatter.status},
                        {field: 'user_type', title: __('User_type'), formatter: Table.api.formatter.status, searchList: {0: __('Dummy'), 1: __('Real person')}},
                        {field: 'is_lock', title: __('Status'), formatter: Table.api.formatter.status, searchList: {0: __('Normal'), 1: __('Locking')}},
                        
                        
                     
                        {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 () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});