define(['table', 'upload','form','qrcode'], function (Table,Upload,Form) {
    var Withdrawl = {
        //Do setup work hereAction
        index: function () {
            window.networkOption= Config.networkList; 
            window.statuskOption = Config.statusList;
            
            Table.api.init({
                extend: {
                    index_url: 'withdrawl/select',
                    add_url: 'withdrawl/insert',
                    edit_url: 'withdrawl/update',
                    //del_url: 'withdrawl/delete',
                    multi_url: 'withdrawl/multi',
                    //dragsort_url: 'withdrawl/weigh',
                    table: 'withdrawl',
                }
            });

            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: "fee",
                            filter: "number",
                            formatter:Table.api.formatter.number,
                            sortable: true    // 是否排序
                        },
                        {
                            title: "转账金额",
                            field: "recive_amount",
                            filter: "number",
                            formatter:function(v){
                                return Table.api.formatter.number(v/Config.score_to_money_rate)+'元';
                            },
                            sortable: true    // 是否排序
                        },
                        {
                            title: "网络",
                            field: "network",
                            filter: "select",
                            filterOption:"networkOption",
                            formatter:function(v){
                                return window.networkOption[v];
                            }
                        },
                        {
                            title: "账号",
                            field: "address",
                            formatter: function(v,row){
                                if(row.network == 'TRC-20' || row.network == 'BEP-20'){
                                    return Table.api.formatter.address(v,row);
                                }else{
                                    return '<a href="/'+row.address_model.img+'" target="_blank" data-img="'+row.address_model.img+'">'+
                                    row.title+"<br />"+row.address
                                    +'</a>';
                                    return row.title+"<br />"+row.address;//Table.api.formatter.address(v,row);
                                }
                            }
                        },
                        {
                            title: "txid",
                            field: "txid",
                            filter: "string",
                            formatter: Table.api.formatter.txid,
                            visible:false
                        },
                        {
                            title: "转账时间",
                            field: "transfer_at",
                            formatter:Table.api.formatter.datetime,
                            visible:false
                        },
                        {
                            title: "状态",
                            field: "status",
                            sortable: true,
                            formatter:Table.api.formatter.status,
                            searchList:window.statuskOption,
                            operate:false,
                            // formatter: function (v,d) {
                            //     for (let i = 0; i < window.statuskOption.length; i++) {
                            //         if(v===window.statuskOption[i].value){
                            //             return '<span class="status-'+v+'">'+window.statuskOption[i].label+'</span>';
                            //         }
                            //     }
                            // },
                            filter: "select",
                            filterOption:"statuskOption"
                        },
                        {
                            title: "memo",
                            field: "memo",
                            visible: false,
                        },
                        {
                            title: "创建时间",
                            field: "created_at",
                            visible: false,
                        },
                        {
                            title: "更新时间",
                            field: "updated_at",
                            visible: false,
                        },
                        {field: 'operate', title: '操作', table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);
            //当加载数据成功时
            table.on('load-success.bs.table', function (e, data) {
                if(data.code === 0){
                    $('#tongji').html('待提现笔数:'+data.wait_count+'，待提现金额：'+data.wait_amount);
                }
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
            $(document).on('mouseenter','a[data-address],a[data-img]',function(){
                if($('#withdral_helper').length == 0){
                    $('body').append('<div id="withdral_helper"><p></p><div></div></div>');
                }
                var amount = $(this).parents('tr').find('td').eq(4).html();
                $('#withdral_helper').css({
                    top:$(this).offset().top-128,
                    left:$(this).offset().left+50,
                });
                $('#withdral_helper p').html("金额:"+amount);
                $('#withdral_helper div').empty();
                if($(this).data("img")){
                    $('#withdral_helper div').html('<img src="/'+$(this).data("img")+'" />');
                }else{
                    $('#withdral_helper div').qrcode({
                        width: 128,height: 128,
                        text: $(this).data("address")
                    });
                }
                $('#withdral_helper').show();
            }).on('mouseleave','a[data-address]',function(){
                $('#withdral_helper').hide();
            })
        },
        update:function(){
            this.bindevent();
        },
        insert:function(){
            this.bindevent();
        },
        bindevent:function(){
            var form = $('form');
            Form.api.bindevent(form)
        }
    };
    return Withdrawl
});