const Api = require('../net/APi') cc.Class({ extends: cc.Component, properties: { avatarSprite: cc.Sprite, avatarBorderSprite: cc.Sprite, rankSprite: cc.Sprite, rankText: cc.RichText, nameText: cc.RichText, genderSprite: cc.Sprite, starCountLabel: cc.Label, starNode: cc.Node, jobLevelStar: cc.Node, jobLevelLabel: cc.Label, jobLevelNameText: cc.RichText, incomeText: cc.RichText, incomeNumberText: cc.RichText, bgFrames: [cc.SpriteFrame], borderFrames: [cc.SpriteFrame], rankFrames: [cc.SpriteFrame], genderFrames: [cc.SpriteFrame], }, // onLoad () {}, setListViewAdapter(adapter) { this.listAdapter = adapter; }, setType(type) { if (type === 0) { this.nameText.node.y = 0; this.starCountLabel.node.active = true; this.starNode.active = true; this.jobLevelStar.active = false; this.jobLevelLabel.node.active = false; this.jobLevelNameText.node.active = false; this.incomeText.node.active = false; this.incomeNumberText.node.active = false; } else { this.nameText.node.y = 20; this.starCountLabel.node.active = false; this.starNode.active = false; this.jobLevelStar.active = true; this.jobLevelLabel.node.active = true; this.jobLevelNameText.node.active = true; this.incomeText.node.active = true; this.incomeNumberText.node.active = true; } }, updateItem(userInfo, itemId) { this.node.getComponent(cc.Sprite).spriteFrame = this.bgFrames[0]; this.avatarBorderSprite.spriteFrame = this.borderFrames[0]; this._itemId = itemId; this.user = userInfo; this._bindData(userInfo); }, bindMySelf(userInfo) { this.node.getComponent(cc.Sprite).spriteFrame = this.bgFrames[1]; this.avatarBorderSprite.spriteFrame = this.borderFrames[1]; this._bindData(userInfo); }, _bindData(userInfo) { switch (userInfo.rank) { case 1: this.rankSprite.node.active = true; this.rankText.node.active = false; this.rankSprite.spriteFrame = this.rankFrames[0]; break; case 2: this.rankSprite.node.active = true; this.rankText.node.active = false; this.rankSprite.spriteFrame = this.rankFrames[1]; break; case 3: this.rankSprite.node.active = true; this.rankText.node.active = false; this.rankSprite.spriteFrame = this.rankFrames[2]; break; default: this.rankSprite.node.active = false; this.rankText.node.active = true; let rankString = userInfo.rank == 0 ? '未上榜' : userInfo.rank; this.rankText.string = `${rankString}`; break; } this.starCountLabel.string = userInfo.stars; this.jobLevelLabel.string = userInfo.jobLevel; this.jobLevelNameText.string = `${userInfo.jobLevelName}`; this.incomeNumberText.string = `${userInfo.salary}`; Api.createImageFromUrl(userInfo.head, (spriteFrame) => { this.avatarSprite.spriteFrame = spriteFrame; }, () => { }); this.genderSprite.spriteFrame = this.genderFrames[userInfo.gender]; this.nameText.string = `` + userInfo.nick; }, start() { }, // update (dt) {}, });