RankPage.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. const RankApi = require('../net/RankApi');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. content: cc.Node,
  6. myNode: cc.Node,
  7. allRankSpriteFrame: [cc.SpriteFrame],
  8. friendRankSpriteFrame: [cc.SpriteFrame],
  9. secondTabSpriteFrame: [cc.SpriteFrame],
  10. topDivider: cc.Node,
  11. allRankTab: cc.Sprite,
  12. friendRankTab: cc.Sprite,
  13. companyTab: cc.Sprite,
  14. artistTab: cc.Sprite,
  15. companyText: cc.RichText,
  16. artistText: cc.RichText,
  17. srcollView: cc.ScrollView,
  18. },
  19. onLoad() {
  20. this.node.height = cc.view.getVisibleSize().height;
  21. this.contentY = this.content.y;
  22. this.content.y = this.content.height - cc.view.getVisibleSize().height;
  23. this.currentTab = 0;
  24. this.secondTab = 0;
  25. this.myScript = this.myNode.getComponent('RankItem');
  26. this.rankListScript = this.srcollView.getComponent('RankList');
  27. this.show();
  28. },
  29. onEnable() {
  30. this.allRankSelected();
  31. },
  32. allRankSelected() {
  33. // this.allRankTab.node.x = 480;
  34. // this.friendRankTab.node.x = 496;
  35. this.allRankTab.node.zIndex = 99;
  36. this.friendRankTab.node.zIndex = 0;
  37. this.allRankTab.spriteFrame = this.allRankSpriteFrame[1];
  38. this.friendRankTab.spriteFrame = this.friendRankSpriteFrame[0];
  39. this.currentTab = 0;
  40. this.data = null
  41. this.companyTabSelected();
  42. this.getData();
  43. },
  44. friendRankSelected() {
  45. // this.allRankTab.node.x = 496;
  46. // this.friendRankTab.node.x = 480;
  47. this.allRankTab.node.zIndex = 0;
  48. this.friendRankTab.node.zIndex = 99;
  49. this.allRankTab.spriteFrame = this.allRankSpriteFrame[0];
  50. this.friendRankTab.spriteFrame = this.friendRankSpriteFrame[1];
  51. this.currentTab = 1;
  52. this.data = null
  53. this.companyTabSelected();
  54. this.getData();
  55. },
  56. companyTabSelected() {
  57. this.secondTab = 0;
  58. this.topDivider.x = -140;
  59. this.companyTab.spriteFrame = this.secondTabSpriteFrame[1];
  60. this.artistTab.spriteFrame = this.secondTabSpriteFrame[0];
  61. this.setSelectedText(this.companyText, '经济公司');
  62. this.setDefaultText(this.artistText, '艺人');
  63. if (this.data) {
  64. this.bindData(this.data.companyRank);
  65. }
  66. },
  67. artistTabSelected() {
  68. this.secondTab = 1;
  69. this.topDivider.x = 140;
  70. this.companyTab.spriteFrame = this.secondTabSpriteFrame[0];
  71. this.artistTab.spriteFrame = this.secondTabSpriteFrame[1];
  72. this.setDefaultText(this.companyText, '经济公司');
  73. this.setSelectedText(this.artistText, '艺人');
  74. if (this.data) {
  75. this.bindData(this.data.artistRank);
  76. }
  77. },
  78. setDefaultText(richText, message) {
  79. richText.node.color = new cc.Color(161, 105, 33);
  80. richText.string = `<outline color=#A16921 width=1><b>${message}<b></outline>`
  81. },
  82. setSelectedText(richText, message) {
  83. richText.node.color = new cc.Color(255, 244, 222);
  84. richText.string = `<outline color=#c47005 width=2><b>${message}<b></outline>`
  85. },
  86. show() {
  87. this.content.y = -cc.view.getVisibleSize().height;
  88. let s = cc.sequence(cc.moveTo(0.2, 0, this.contentY + 20).easing(cc.easeCubicActionOut()), cc.moveBy(0.05, 0, -20));
  89. this.content.runAction(s);
  90. this.scheduleOnce(() => {
  91. }, 0.2);
  92. },
  93. close() {
  94. if (this.node && this.node.parent) {
  95. let self = this;
  96. let finish = cc.callFunc(() => {
  97. self.node.destroy();
  98. }, this)
  99. this.content.runAction(cc.sequence(cc.moveTo(0.2, 0, -cc.view.getVisibleSize().height).easing(cc.easeCubicActionIn()), finish));
  100. }
  101. },
  102. getData() {
  103. let promise = null;
  104. if (this.currentTab === 0) {
  105. promise = RankApi.getAllRankPromise();
  106. } else {
  107. promise = RankApi.getFriendRankPromise();
  108. }
  109. this.scheduleOnce(() => {
  110. promise.then(res => {
  111. this.data = res.data;
  112. this.bindData(this.data.companyRank);
  113. }).catch((code, msg) => {
  114. console.log(code)
  115. });
  116. }, 0.3);
  117. },
  118. bindData(pageData) {
  119. this.srcollView.stopAutoScroll();
  120. this.srcollView.scrollToTop(0);
  121. this.myScript.setType(this.secondTab);
  122. this.myScript.bindMySelf(pageData.me);
  123. this.rankListScript.bindData(pageData.ranks);
  124. },
  125. });