listWholecountryManger.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. item: cc.Prefab,
  29. },
  30. // LIFE-CYCLE CALLBACKS:
  31. onLoad () {
  32. // console.log("排行页面看见");
  33. },
  34. //排行榜
  35. start() {
  36. this.typelist = 2;
  37. let ranklist = this.ranklist = UtilsPrefabs.getNode("ranklist", this.node);
  38. //左面
  39. let ranklist_back = this.ranklist_back = UtilsPrefabs.getNode("ranklist_back", this.node);
  40. //右面
  41. let ranklist_next = this.ranklist_next = UtilsPrefabs.getNode("ranklist_next", this.node);
  42. // let NewButton = UtilsPrefabs.getNode("New Button", this.node);
  43. // var i = "https://ss0.bdstatic.com/" +
  44. // "70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/" +
  45. // "u=3356744803,2445309553&fm=26&gp=0.jpg"
  46. // utils.loadHttpSpriteFrame(i, NewButton.getComponent(cc.Sprite));
  47. // item/ranklist_bg
  48. //返回到结算页面
  49. let backbutton = this.backbutton = UtilsPrefabs.getNode("backbutton", this.node);
  50. UtilsPrefabs.setOn(ranklist_back, function () {
  51. this.ranklist_backCallback();
  52. }.bind(this));
  53. UtilsPrefabs.setOn(ranklist_next, function () {
  54. this.ranklist_nextCallback();
  55. }.bind(this));
  56. UtilsPrefabs.setOn(this.backbutton, function () {
  57. if (this.backButtonClick != null) {
  58. this.backButtonClick();
  59. }
  60. }.bind(this));
  61. this.listDataPage = 0;
  62. this.morePagea = 1;
  63. this.listDataPageCout = 5;
  64. this.setListData();
  65. this.checkRankListCount();
  66. },
  67. //检查 排行榜长度如果不够长 就不显示下一页
  68. checkRankListCount : function(){
  69. //左右按钮 如果小于 每页 规定的 数字 就不显示
  70. if (RankingListData.listdata1.length<=this.listDataPageCout) {
  71. this.ranklist_next.active = false;
  72. this.ranklist_back.active = false;
  73. }
  74. let ranklist_bg = UtilsPrefabs.getNode("ranklist_bg", this.node);
  75. this.checkRanking(RankingListData.myRank,ranklist_bg);
  76. this.setItemData(RankingListData.myRank,ranklist_bg);
  77. },
  78. setbackButtonClickListeniner : function (backButtonClick) {
  79. this.backButtonClick = backButtonClick;
  80. },
  81. backButtonClick : function () {
  82. },
  83. ranklist_backCallback: function () {
  84. this.addCurr(false);
  85. },
  86. ranklist_nextCallback: function () {
  87. this.addCurr(true);
  88. },
  89. setListData: function () {
  90. this.listDataPagearr = [];
  91. let tempArr = [];
  92. let tempi = 0;
  93. for (var i = 0; i < RankingListData.listdata1.length; i++) {
  94. tempArr.push(RankingListData.listdata1[i]);
  95. if (tempArr.length >= this.listDataPageCout || i == RankingListData.listdata1.length-1) {
  96. this.listDataPagearr.push(tempArr);
  97. tempArr = [];
  98. }
  99. // console.log("计数",tempArr ,tempArr.length);
  100. }
  101. // console.log("分段数组是什么",this.listDataPagearr);
  102. // let tag = true;
  103. //
  104. // let tempArr = [];
  105. // while (tag){
  106. // temp.list[x]
  107. // }
  108. //
  109. this.setItemDataList(this.listDataPage);
  110. this.isShowButton();
  111. },
  112. setItemDataList : function(page){
  113. for (var i = 0; i <this.ranklist.children.length ; i++) {
  114. this.ranklist.children[i].destroy();
  115. }
  116. for (var i = 0; i < this.listDataPagearr[page].length; i++) {
  117. let temp = this.listDataPagearr[page][i];
  118. let x = i;
  119. // UtilsPrefabs
  120. // .init(this.ranklist)
  121. // .addPrefabsName("item/ranklist_bg", null, x, function (node) {
  122. let item = this.getItem(this.ranklist);
  123. this.checkRanking(temp,item);
  124. this.setItemData(temp,item);
  125. // }.bind(this));
  126. }
  127. },
  128. getItem : function(layout){
  129. let node = cc.instantiate(this.item);
  130. node.parent = layout;
  131. return node;
  132. },
  133. checkRanking: function (data,node) {
  134. let Medal = UtilsPrefabs.getNode("Medal", node);
  135. // console.log("都有啥" ,Medal);
  136. let ranklist_gold = UtilsPrefabs.getNode("ranklist_gold", Medal);
  137. let ranklist_silver = UtilsPrefabs.getNode("ranklist_silver", Medal);
  138. let ranklist_copper = UtilsPrefabs.getNode("ranklist_copper", Medal);
  139. let num = UtilsPrefabs.getNode("num", Medal);
  140. ranklist_gold.active = false;
  141. ranklist_silver.active = false;
  142. ranklist_copper.active = false;
  143. if (num!=null) {
  144. num.active = false;
  145. }
  146. switch (data.rank) {
  147. case 1:
  148. ranklist_gold.active = true;
  149. break;
  150. case 2:
  151. ranklist_silver.active = true;
  152. break;
  153. case 3:
  154. ranklist_copper.active = true;
  155. break;
  156. default:
  157. if (num!=null) {
  158. num.active = true;
  159. num.getComponent(cc.Label).string = data.rank;
  160. }
  161. break;
  162. }
  163. },
  164. setItemData : function (data,node) {
  165. let ranklist_ic = UtilsPrefabs.getNode("ranklist_ic", node);
  166. let playername = UtilsPrefabs.getNode("playername", node);
  167. let Score = UtilsPrefabs.getNode("Score", node);
  168. // ranklist_ic.width = 76;
  169. // ranklist_ic.height = 76;
  170. utils.loadHttpSpriteFrame(data.portraits, ranklist_ic.getComponent(cc.Sprite));
  171. // console.log("你把个时候",ranklist_ic);
  172. playername.getComponent(cc.Label).string = data.nickName;
  173. Score.getComponent(cc.Label).string = data.score;
  174. },
  175. //增加或者减少 索引的时候
  176. addCurr : function(b){
  177. // console.log("增加 减少",b,"当前索引",this.curr,"总长度是",this.listview.children.length);
  178. if (b) {
  179. if (this.listDataPage < this.listDataPagearr.length-1) {
  180. this.listDataPage++;
  181. }
  182. if (this.listDataPage == this.listDataPagearr.length-1) {
  183. utils.isMobile(function () {
  184. this.morePagea++;
  185. Manager.getRanking( this.typelist,this.morePagea,0,10)
  186. }.bind(this));
  187. }
  188. }else{
  189. if (this.listDataPage > 0) {
  190. this.listDataPage--;
  191. }
  192. }
  193. this.setItemDataList(this.listDataPage);
  194. this.isShowButton();
  195. },
  196. //是否显示 上一页或者下一页的 按钮
  197. isShowButton : function(){
  198. // console.log("现在是",this.listDataPage);
  199. if (this.listDataPage == 0) {
  200. this.ranklist_back.active = false;
  201. this.ranklist_next.active = true;
  202. }else if (this.listDataPage == this.listDataPagearr.length-1) {
  203. this.ranklist_back.active = true;
  204. this.ranklist_next.active = false;
  205. }else{
  206. this.ranklist_back.active = true;
  207. this.ranklist_next.active = true;
  208. }
  209. },
  210. // update (dt) {},
  211. });