RankItem.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const Api = require('../net/APi')
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. avatarSprite: cc.Sprite,
  6. avatarBorderSprite: cc.Sprite,
  7. rankSprite: cc.Sprite,
  8. rankText: cc.RichText,
  9. nameText: cc.RichText,
  10. genderSprite: cc.Sprite,
  11. starCountLabel: cc.Label,
  12. starNode: cc.Node,
  13. jobLevelStar: cc.Node,
  14. jobLevelLabel: cc.Label,
  15. jobLevelNameText: cc.RichText,
  16. incomeText: cc.RichText,
  17. incomeNumberText: cc.RichText,
  18. bgFrames: [cc.SpriteFrame],
  19. borderFrames: [cc.SpriteFrame],
  20. rankFrames: [cc.SpriteFrame],
  21. genderFrames: [cc.SpriteFrame],
  22. },
  23. // onLoad () {},
  24. setListViewAdapter(adapter) {
  25. this.listAdapter = adapter;
  26. },
  27. setType(type) {
  28. if (type === 0) {
  29. this.nameText.node.y = 0;
  30. this.starCountLabel.node.active = true;
  31. this.starNode.active = true;
  32. this.jobLevelStar.active = false;
  33. this.jobLevelLabel.node.active = false;
  34. this.jobLevelNameText.node.active = false;
  35. this.incomeText.node.active = false;
  36. this.incomeNumberText.node.active = false;
  37. } else {
  38. this.nameText.node.y = 20;
  39. this.starCountLabel.node.active = false;
  40. this.starNode.active = false;
  41. this.jobLevelStar.active = true;
  42. this.jobLevelLabel.node.active = true;
  43. this.jobLevelNameText.node.active = true;
  44. this.incomeText.node.active = true;
  45. this.incomeNumberText.node.active = true;
  46. }
  47. },
  48. updateItem(userInfo, itemId) {
  49. this.node.getComponent(cc.Sprite).spriteFrame = this.bgFrames[0];
  50. this.avatarBorderSprite.spriteFrame = this.borderFrames[0];
  51. this._itemId = itemId;
  52. this.user = userInfo;
  53. this._bindData(userInfo);
  54. },
  55. bindMySelf(userInfo) {
  56. this.node.getComponent(cc.Sprite).spriteFrame = this.bgFrames[1];
  57. this.avatarBorderSprite.spriteFrame = this.borderFrames[1];
  58. this._bindData(userInfo);
  59. },
  60. _bindData(userInfo) {
  61. switch (userInfo.rank) {
  62. case 1:
  63. this.rankSprite.node.active = true;
  64. this.rankText.node.active = false;
  65. this.rankSprite.spriteFrame = this.rankFrames[0];
  66. break;
  67. case 2:
  68. this.rankSprite.node.active = true;
  69. this.rankText.node.active = false;
  70. this.rankSprite.spriteFrame = this.rankFrames[1];
  71. break;
  72. case 3:
  73. this.rankSprite.node.active = true;
  74. this.rankText.node.active = false;
  75. this.rankSprite.spriteFrame = this.rankFrames[2];
  76. break;
  77. default:
  78. this.rankSprite.node.active = false;
  79. this.rankText.node.active = true;
  80. let rankString = userInfo.rank == 0 ? '未上榜' : userInfo.rank;
  81. this.rankText.string = `<outline color=#692e0e width=2><b>${rankString}</b></outline>`;
  82. break;
  83. }
  84. this.starCountLabel.string = userInfo.stars;
  85. this.jobLevelLabel.string = userInfo.jobLevel;
  86. this.jobLevelNameText.string = `<b>${userInfo.jobLevelName}</b>`;
  87. this.incomeNumberText.string = `<outline color=#ffffff width=2><b>${userInfo.salary}</b></outline>`;
  88. Api.createImageFromUrl(userInfo.head, (spriteFrame) => {
  89. this.avatarSprite.spriteFrame = spriteFrame;
  90. }, () => {
  91. });
  92. this.genderSprite.spriteFrame = this.genderFrames[userInfo.gender];
  93. this.nameText.string = `<img src=gender/>` + userInfo.nick;
  94. },
  95. start() {
  96. },
  97. // update (dt) {},
  98. });