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.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'gold', title: __('Gold')},
                        {field: 'vip_endtime', title: __('Vip_endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {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',
                                    /*hidden:function(row){
                                     return row.status==100 ? false : false;
                                     }*/
                                }
                            ],
                            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;
});