const Api = require('../net/APi') cc.Class({ extends: cc.Component, properties: { avatarSprite: cc.Sprite, rankSprite: cc.Sprite, rankLabel: cc.Label, nameLabel: cc.Label, genderSprite: cc.Sprite, starCountLabel: cc.Label, starNode: cc.Node, rankFrames: [cc.SpriteFrame], genderFrames: [cc.SpriteFrame], }, // onLoad () {}, setListViewAdapter(adapter) { this.listAdapter = adapter; }, updateItem(userInfo, itemId) { this._itemId = itemId; this.user = userInfo; this._bindData(userInfo); }, bindMySelf(userInfo) { this._bindData(userInfo); }, _bindData(userInfo) { if (userInfo.rank <= 3) { switch (userInfo.rank) { case 1: this.rankSprite.node.active = true; this.rankLabel.node.active = false; this.rankSprite.spriteFrame = this.rankFrames[0]; break; case 2: this.rankSprite.node.active = true; this.rankLabel.node.active = false; this.rankSprite.spriteFrame = this.rankFrames[1]; break; case 3: this.rankSprite.node.active = true; this.rankLabel.node.active = false; this.rankSprite.spriteFrame = this.rankFrames[2]; break; default: this.rankSprite.node.active = false; this.rankLabel.node.active = true; let rankString = '未上榜'; this.rankLabel.string = rankString; break; } } else { this.rankSprite.node.active = false; this.rankLabel.node.active = true; let rankString = userInfo.rank; this.rankLabel.string = rankString; } this.starCountLabel.string = userInfo.stars; Api.createImageFromUrl(userInfo.head, (spriteFrame) => { this.avatarSprite.spriteFrame = spriteFrame; }, () => { }); this.genderSprite.spriteFrame = this.genderFrames[userInfo.gender]; this.nameLabel.string = userInfo.nick; }, start() { }, // update (dt) {}, });