ArtistRankItem.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. artistLevelSprite: cc.Sprite,
  11. jobLevelNameLabel: cc.Label,
  12. incomeLabel: cc.Label,
  13. incomeNumberLabel: cc.Label,
  14. rankFrames: [cc.SpriteFrame],
  15. genderFrames: [cc.SpriteFrame],
  16. jobLevelBgs: [cc.SpriteFrame],
  17. },
  18. // onLoad () {},
  19. setListViewAdapter(adapter) {
  20. this.listAdapter = adapter;
  21. },
  22. updateItem(userInfo, itemId) {
  23. this._itemId = itemId;
  24. this.user = userInfo;
  25. this._bindData(userInfo);
  26. },
  27. bindMySelf(userInfo) {
  28. this._bindData(userInfo);
  29. },
  30. _bindData(userInfo) {
  31. if (userInfo.rank <= 3) {
  32. switch (userInfo.rank) {
  33. case 1:
  34. this.rankSprite.node.active = true;
  35. this.rankLabel.node.active = false;
  36. this.rankSprite.spriteFrame = this.rankFrames[0];
  37. break;
  38. case 2:
  39. this.rankSprite.node.active = true;
  40. this.rankLabel.node.active = false;
  41. this.rankSprite.spriteFrame = this.rankFrames[1];
  42. break;
  43. case 3:
  44. this.rankSprite.node.active = true;
  45. this.rankLabel.node.active = false;
  46. this.rankSprite.spriteFrame = this.rankFrames[2];
  47. break;
  48. default:
  49. this.rankSprite.node.active = false;
  50. this.rankLabel.node.active = true;
  51. let rankString = '未上榜';
  52. this.rankLabel.string = rankString;
  53. break;
  54. }
  55. } else {
  56. this.rankSprite.node.active = false;
  57. this.rankLabel.node.active = true;
  58. let rankString = userInfo.rank;
  59. this.rankLabel.string = rankString;
  60. }
  61. if (userInfo.jobLevel != undefined) {
  62. this.artistLevelSprite.node.active = true;
  63. this.artistLevelSprite.spriteFrame = this.jobLevelBgs[userInfo.jobLevel - 1];
  64. } else {
  65. this.artistLevelSprite.node.active = false;
  66. }
  67. if (userInfo.jobLevelName != undefined) {
  68. this.jobLevelNameLabel.string = userInfo.jobLevelName;
  69. } else {
  70. this.jobLevelNameLabel.string = '';
  71. }
  72. if (userInfo.salary != undefined) {
  73. this.incomeNumberLabel.string = userInfo.salary;
  74. } else {
  75. this.incomeNumberLabel.string = '';
  76. }
  77. Api.createImageFromUrl(userInfo.head, (spriteFrame) => {
  78. this.avatarSprite.spriteFrame = spriteFrame;
  79. }, () => {
  80. });
  81. this.genderSprite.spriteFrame = this.genderFrames[userInfo.gender];
  82. this.nameLabel.string = userInfo.nick;
  83. },
  84. start() {
  85. },
  86. // update (dt) {},
  87. });