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, artistLevelSprite: cc.Sprite, jobLevelNameLabel: cc.Label, incomeLabel: cc.Label, incomeNumberLabel: cc.Label, rankFrames: [cc.SpriteFrame], genderFrames: [cc.SpriteFrame], jobLevelBgs: [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; } if (userInfo.jobLevel != undefined) { this.artistLevelSprite.node.active = true; this.artistLevelSprite.spriteFrame = this.jobLevelBgs[userInfo.jobLevel - 1]; } else { this.artistLevelSprite.node.active = false; } if (userInfo.jobLevelName != undefined) { this.jobLevelNameLabel.string = userInfo.jobLevelName; } else { this.jobLevelNameLabel.string = ''; } if (userInfo.salary != undefined) { this.incomeNumberLabel.string = userInfo.salary; } else { this.incomeNumberLabel.string = ''; } Api.createImageFromUrl(userInfo.head, (spriteFrame) => { this.avatarSprite.spriteFrame = spriteFrame; }, () => { }); this.genderSprite.spriteFrame = this.genderFrames[userInfo.gender]; this.nameLabel.string = userInfo.nick; }, start() { }, // update (dt) {}, });