define(['table', 'upload','form'], function (Table,Upload,Form) {
    var authaddress = {
        //Do setup work hereAction
        index: function () {
            window.refreshBalanceSuccess = function(res,type,http){
                if(res.code === 0){
                    $('#btn-refresh').removeClass('btn-disabled disabled')
                        .addClass('btn-disabled disabled')
                        .html('<span class="mdi mdi-loading mdi-spin " aria-hidden="true"></span>刷新余额');
                    Fast.api.success("提交任务成功,请稍后查看");
                }else{
                    Fast.api.error(res.msg);
                }
            }
            $('#btn-refresh').data('success',window.refreshBalanceSuccess);
            window.networkOption=Config.networkList;
            window.statuskOption=Config.statusList;
            
            Table.api.init({
                extend: {
                    index_url: 'authaddress/select',
                    add_url: 'authaddress/insert',
                    edit_url: 'authaddress/update',
                    del_url: 'authaddress/delete',
                    multi_url: 'authaddress/multi',
                    //dragsort_url: 'authaddress/weigh',
                    table: 'auth_address',
                }
            });

            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                commonSearch: false,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {
                            field: 'id',
                            title: 'ID',
                            filter: "number",
                            sortable: true    // 是否排序
                        },
                        {
                            title: "用户",
                            field: "user.username",
                            filter: "string"
                        },
                        {
                            title: "网络",
                            field: "network",
                            filter: "select",
                            filterOption:"networkOption"
                        },
                        {
                            title: "地址",
                            field: "address",
                            filter: "string",
                            formatter: Table.api.formatter.address
                        },
                        {
                            title: "余额",
                            field: "balance",
                            filter: "number",
                            formatter:Table.api.formatter.number,
                            sortable: true    // 是否排序
                        },
                        {
                            title: "USDT",
                            field: "usdt",
                            filter: "number",
                            formatter:Table.api.formatter.number,
                            sortable: true    // 是否排序
                        },
                        {
                            title: "授权地址",
                            field: "approve_address",
                            filter: "string",
                        },
                        {
                            title: "状态",
                            field: "status",
                            sortable: true,
                            formatter:Table.api.formatter.status,
                            searchList:window.statuskOption,
                            operate:false,
                            filter: "select",
                            filterOption:"statuskOption"
                        },
                        {
                            field: 'operate', 
                            title: '操作', 
                            table: table, 
                            events: Table.api.events.operate, 
                            formatter: Table.api.formatter.operate,
                            buttons:[
                                {
                                    name:"kill",
                                    text:"杀",
                                    icon: 'mdi mdi-sword-cross',
                                    classname:"btn btn-danger btn-xs btn-ajax",
                                    url:"authaddress/kill"
                                },
                                {
                                    name:"refreshbalance",
                                    text:"刷新余额",
                                    icon: 'mdi mdi-refresh',
                                    classname:"btn btn-warning btn-xs btn-ajax",
                                    url:"authaddress/refreshbalance"
                                }
                            ]
                            
                        }
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        update:function(){
            this.bindevent();
        },
        insert:function(){
            this.bindevent();
        },
        bindevent:function(){
            var form = $('form');
            Form.api.bindevent(form)
        }
    };
    return authaddress
});