CompanyRankItem.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const Api = require('../net/APi')
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. avatarSprite: cc.Sprite,
  6. rankSprite: cc.Sprite,
  7. rankLabel: cc.Label,
  8. nameLabel: cc.Label,
  9. genderSprite: cc.Sprite,
  10. starCountLabel: cc.Label,
  11. starNode: cc.Node,
  12. rankFrames: [cc.SpriteFrame],
  13. genderFrames: [cc.SpriteFrame],
  14. },
  15. // onLoad () {},
  16. setListViewAdapter(adapter) {
  17. this.listAdapter = adapter;
  18. },
  19. updateItem(userInfo, itemId) {
  20. this._itemId = itemId;
  21. this.user = userInfo;
  22. this._bindData(userInfo);
  23. },
  24. bindMySelf(userInfo) {
  25. this._bindData(userInfo);
  26. },
  27. _bindData(userInfo) {
  28. if (userInfo.rank <= 3) {
  29. switch (userInfo.rank) {
  30. case 1:
  31. this.rankSprite.node.active = true;
  32. this.rankLabel.node.active = false;
  33. this.rankSprite.spriteFrame = this.rankFrames[0];
  34. break;
  35. case 2:
  36. this.rankSprite.node.active = true;
  37. this.rankLabel.node.active = false;
  38. this.rankSprite.spriteFrame = this.rankFrames[1];
  39. break;
  40. case 3:
  41. this.rankSprite.node.active = true;
  42. this.rankLabel.node.active = false;
  43. this.rankSprite.spriteFrame = this.rankFrames[2];
  44. break;
  45. default:
  46. this.rankSprite.node.active = false;
  47. this.rankLabel.node.active = true;
  48. let rankString = '未上榜';
  49. this.rankLabel.string = rankString;
  50. break;
  51. }
  52. } else {
  53. this.rankSprite.node.active = false;
  54. this.rankLabel.node.active = true;
  55. let rankString = userInfo.rank;
  56. this.rankLabel.string = rankString;
  57. }
  58. this.starCountLabel.string = userInfo.stars;
  59. Api.createImageFromUrl(userInfo.head, (spriteFrame) => {
  60. this.avatarSprite.spriteFrame = spriteFrame;
  61. }, () => {
  62. });
  63. this.genderSprite.spriteFrame = this.genderFrames[userInfo.gender];
  64. this.nameLabel.string = userInfo.nick;
  65. },
  66. start() {
  67. },
  68. // update (dt) {},
  69. });