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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
//                        {checkbox: true},
//                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'intromoney', title: __('Intromoney'), operate:'BETWEEN'},
                        {field: 'hexiaomoney', title: __('Hexiaomoney'), operate:'BETWEEN'},
                        {field: 'intro_level', title: __('Intro_level'), searchList: {"-1":__('Intro_level -1'),"0":__('Intro_level 0'),"1":__('Intro_level 1'),"2":__('Intro_level 2'),"3":__('Intro_level 3'),"4":__('Intro_level 4'),"5":__('Intro_level 5')}, formatter: Table.api.formatter.normal},
//                        {field: 'intro_uid', title: __('Intro_uid')},
//                        {field: 'last_jiesuan_date', title: __('Last_jiesuan_date')},

                        {field: 'operate', title: __('Operate'), table: table,
                            buttons:[
                                {
                                    name:'updatemoney',
                                    text:'充值',
                                    title:'充值',
                                    icon:'fa fa-exclamation-circle',
                                    classname:'btn btn-xs btn-info btn-dialog',
                                    url:'userwallet/updatemoney/id/{ids}?dialog=1',
                                    target:'_self',
                                },
                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

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