define(['table', 'upload','form'], function (Table,Upload,Form) {
    var BalanceLog = {
        //Do setup work hereAction
        index: function () {
            window.filterData['currency'] = {value1:"money",symbol:'=','value2':''};
            Table.api.init({
                extend: {
                    index_url: 'balancelog/select',
                    del_url: 'balancelog/delete?currency=money',
                    multi_url: 'balancelog/multi',
                    table: 'balancelog',
                }
            });
            window.currencyOption= {"money":"余额","score":"待结算","currency2":"未结算"} ;
            window.balanceTypeList=Config.balanceTypeList;
            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'created_at',
                sortOrder: 'desc',
                columns: [
                    [
                        {checkbox: true},
                        {
                            field: 'id',
                            title: 'ID',
                            filter: "string",
                            sortable: true,    // 是否排序
                            width:100,
                            visible:false
                        },
                        {
                            title: "用户",
                            field: "username",
                            filter: "string",
                            sortable: true,    // 是否排序
                            //visible: false,
                        },
                        {
                            title: "货币",
                            field: "currency",
                            filter: "select",
                            filterOption:"currencyOption",
                            visible:false
                        },
                        {
                            title: "金额",
                            field: "amount",
                            filter: "number",
                            formatter:Table.api.formatter.number,
                            sortable: true,    // 是否排序
                        },
                        {
                            title: "变更前",
                            field: "before",
                            formatter:Table.api.formatter.number,
                            filter: "number",
                            sortable: true,    // 是否排序
                        },
                        {
                            title: "变更后",
                            field: "after",
                            formatter:Table.api.formatter.number,
                            filter: "number",
                            sortable: true,    // 是否排序
                        },
                        {
                            title: "类型",
                            field: "type",
                            filter: "select",
                            filterOption:"balanceTypeList",
                            formatter:function(v,row){
                                return Config.balanceTypeList[v];
                            }
                            //visible: false,
                        },
                        {
                            title: "备注",
                            field: "memo",
                            filter: "string",
                            //visible: false,
                        },
                        {
                            title: "创建时间",
                            field: "created_at",
                            filter: "datetime",
                            sortable: true ,   // 是否排序
                            formatter:function(v){
                                return v ? v.split('.')[0] : '';
                            }
                            //visible: false,
                        },
                        {
                            field: 'operate', 
                            title: '操作', 
                            table: table, 
                            events: Table.api.events.operate, 
                            formatter: Table.api.formatter.operate,
                            visible:false
                        }
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);
            // 为表格绑定事件
            Table.api.bindevent(table);
            $('#filter_currency li').on('click',function(){
                var currency = $(this).data('currency');
                $('#filter_currency li').removeClass('active');
                $(this).addClass('active');
                $.fn.bootstrapTable.defaults.extend.del_url = 'balancelog/delete?currency='+currency
                window.filterData['currency']['value1'] = currency;
                table.bootstrapTable('selectPage', 1);
            });
        },
        update:function(){
        },
        insert:function(){
        },
    };
    return BalanceLog
});