$('.form_date').datetimepicker({
    language: 'zh-CN',
    weekStart: 1,
    todayBtn: 1,
    autoclose: 1,
    todayHighlight: 1,
    startView: 2,
    minView: 2,
    forceParse: 0
});

$('#tab_order').bootstrapTable({
    locale: 'zh-CN', //中文支持
    singleSelect: true,
    columns: [{checkbox: false}],
    pagination: true, //是否开启分页（*）
    pageNumber: 1, //初始化加载第一页，默认第一页
    pageSize: 20, //每页的记录行数（*）
    pageList: [2, 3, 4], //可供选择的每页的行数（*）
    sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
    queryParamsType: "",
    columns: [
        {
            field: 'cpOrderId',
            title: '订单id',
            align: 'center',
            valign: 'middle',
            sortable: true
        },
        {
            field: 'uid',
            title: '用户id',
            align: 'center',
            valign: 'middle',
            sortable: true
        },
        {
            field: 'amount',
            title: '金额（元）',
            align: 'center',
            valign: 'middle',
            sortable: true,
            formatter: function (value, row, index) {
                var amount = (value / 100);
                return amount.toFixed(2);
            }
        },
        {
            field: 'product_id',
            title: '物品id',
            align: 'center',
            valign: 'middle',
            sortable: true
        },
        {
            field: 'product_count',
            title: '物品数量',
            align: 'center',
            valign: 'middle',
            sortable: true
        },
        {
            field: 'close_ts',
            title: '支付时间',
            align: 'center',
            valign: 'middle',
            sortable: true,
			formatter: function (value, row, index) {
                var unixTimestamp = new Date(value * 1000);
                return unixTimestamp.toLocaleString();
            }
        },
        {
            field: 'channel',
            title: '平台',
            align: 'center',
            valign: 'middle',
            sortable: true
        },
        {
            field: 'zoneid',
            title: '区服',
            align: 'center',
            valign: 'middle',
            sortable: true
        },
    ]
});

function searchOrder() {
    var platform = $('#inputPlatform').val();
    var startTime = $('#date-text').val();
    var endTime = $('#date-text1').val();

    var url = getProviderUrl("order");
    url += "?platform=" + platform;
    url += "&startTime=" + startTime;
    url += "&endTime=" + endTime;

    $('#tab_order').bootstrapTable('refresh', {url: url});
    
    url = getProviderUrl("orderChart");
    var params = {};
    params.platform = platform;
    params.startTime = startTime;
    params.endTime = endTime;
    
    $.post(url, params,function(data){
        $('#totalPrize').text("总充值：" + data.totalPrize + "元");
        Canvas2(data.data,data.labels);
    }, 'json');

}

var chart = null;

function Canvas2(datas,labels) {
    var lineChartData = {
        labels: labels,
        datasets: [
            {
                fillColor: "rgba(220,220,220,0.2)",
                strokeColor: "rgba(220,220,220,1)",
                pointColor: "rgba(220,220,220,1)",
                pointStrokeColor: "#fff",
                pointHighlightFill: "#fff",
                pointHighlightStroke: "rgba(220,220,220,1)",
                data: datas
            }
        ]
    }
    $('#orderCanvas').attr("width",$('#orderCanvasParent').width());
    var ctx = document.getElementById("orderCanvas").getContext("2d");
    if(chart != null){
        chart.destroy();
    }
    chart = new Chart(ctx).Line(lineChartData);
}


