RankPage.js 4.3 KB

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