var AutoLoad = require('autoload')
var _ = require('underscore')

class pageTestChart {
    constructor() {
        this.pageNum = 3
        this.pageSize = 20
        this.autoload
        this.chartTpl = __inline('../../tpl/testchart.tmpl')
        this.$chartWrap = $('.game-chart-tbl tbody')
        this.init()
    }

    init() {
        this.autoload = new AutoLoad('.page-testchart', this.getData.bind(this))
    }

    getData() {
        var self = this
        $.ajax({
            url: 'http://ku.newgame.duowan.com/index.php?r=api/Getnewgamebeta&type=jsonp&',
            data: { pageNum: self.pageNum, pageSize: self.pageSize },
            dataType: 'jsonp',
            success: function (data) {
                if (data.list instanceof Array) {
                    self.renderChart(data.list)
                    self.pageNum++
                } else {
                    self.autoload.end()
                }
                self.autoload.done()
            },
            err: function (err) {
                console.log(err)
            }
        })
    }

    renderChart(list) {
        var $append = $(this.chartTpl({
            charts: list
        }))
        this.$chartWrap.append($append)
    }
}

class Util {
    constructor() {

    }

    static formatTime(str) {
        var timeArr = str.split('-')

        return timeArr.slice(1).join('-')
    }
}

$(() => {
    new pageTestChart
})