cc.Class({
    extends: cc.Component,

    properties: {
        rankLabel: cc.Label,
        rankSprite: cc.Sprite,
        avatar: cc.Sprite,
        nameLabel: cc.Label,
        scoreLabel: cc.Label,
        rankSpriteList: [cc.SpriteFrame],
    },

    onLoad() {
        this._itemId = 0;
    },

    start() {

    },

    updateItem(data, itemId) {
        this._itemId = itemId;

        if (data.rank < 3) {
            this.rankSprite.node.active = true;
            this.rankLabel.node.active = false;
            this.rankSprite.spriteFrame = this.rankSpriteList[this._itemId];
        } else {
            this.rankSprite.node.active = false;
            this.rankLabel.node.active = true;
            this.rankLabel.string = this._itemId + 1;
        }

        this.scoreLabel.string = data.score;
        this.nameLabel.string = data.nick;

        cc.loader.load({
            url: data.url,
            type: 'jpg'
        }, (err, texture) => {
            if (err === undefined || err === null) {
                this.avatar.spriteFrame = new cc.SpriteFrame(texture);
            } else {
                console.log(err);
            }
        });
    }

    // update (dt) {},
});