RankPage.js 4.4 KB

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