const ListViewAdapter = require('./ListViewAdapter');
cc.Class({
    extends: cc.Component,

    properties: {
        scrollView: cc.ScrollView,
        content: cc.Node,
        prefabRankItem: cc.Node,
        itemScriptName: '',
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.listAdapter = new ListViewAdapter(this.scrollView);
        this.users = [];

        //-------------------------------------test--------------------------------------------------------------------------//
        this.mineScore = {
            nick: "user" + i,
            url: "http://www.psahz.com/uploads/allimg/181006/094Q62X3-2.jpg",
            score: (100 - i * 2)
        };

        this.prefabRankItem.getComponent('RankItem').updateItem(this.mineScore, 0);

        for (i = 0; i < 30; i++) {
            this.user = {
                nick: "user" + i,
                url: "http://www.psahz.com/uploads/allimg/181006/094Q62X3-2.jpg",
                score: (100 - i * 2)
            };

            this.users.push(this.user);
        }

        this.listAdapter.updateItems(this.users, this.prefabRankItem, this.itemScriptName);


        //-------------------------------------test--------------------------------------------------------------------------//


        // BK.QQ.getRankListWithoutRoom(attr, order, rankType, function (errCode, cmd, data) {
        //     BK.Script.log(1, 1, "getRankListWithoutRoom callback  cmd" + cmd + " errCode:" + errCode + "  data:" + JSON.stringify(data));
        //     // 返回错误码信息
        //     if (errCode !== 0) {
        //         BK.Script.log(1, 1, '获取排行榜数据失败!错误码：' + errCode);
        //         return;
        //     }
        //     // 解析数据
        //     if (data) {
        //         for (var i = 0; i < data.data.ranking_list.length; ++i) {
        //             var rd = data.data.ranking_list[i];
        //             // rd 的字段如下:
        //             //var rd = {
        //             //    url: '',            // 头像的 url
        //             //    nick: '',           // 昵称
        //             //    score: 1,           // 分数
        //             //    selfFlag: false,    // 是否是自己
        //             //};
        //         }
        //     }
        // });

    },

    start() {

    },

    update(dt) {
        if (this.listAdapter) {
            this.listAdapter.update(dt);
        }
    },
});
