listWholecountryManger.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 = 1;
  37. let ranklist = this.ranklist = UtilsNode.getNode("ranklist", this.node);
  38. //左面
  39. let ranklist_back = this.ranklist_back = UtilsNode.getNode("ranklist_back", this.node);
  40. //右面
  41. let ranklist_next = this.ranklist_next = UtilsNode.getNode("ranklist_next", this.node);
  42. // let NewButton = UtilsNode.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 = UtilsNode.getNode("backbutton", this.node);
  50. UtilsNode.setOn(ranklist_back, function () {
  51. this.ranklist_backCallback();
  52. }.bind(this));
  53. UtilsNode.setOn(ranklist_next, function () {
  54. this.ranklist_nextCallback();
  55. }.bind(this));
  56. UtilsNode.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. this.nextActive = false
  67. },
  68. _init : function(){
  69. this.listDataPage = 0;
  70. this.morePagea = 1;
  71. console.log("listWholecountryManger 索引",this.listDataPage,this.morePagea);
  72. },
  73. //检查 排行榜长度如果不够长 就不显示下一页
  74. checkRankListCount : function(){
  75. //左右按钮 如果小于 每页 规定的 数字 就不显示
  76. if (RankingListData.listdata1.length<=this.listDataPageCout) {
  77. this.ranklist_next.active = false;
  78. this.ranklist_back.active = false;
  79. }
  80. let ranklist_bg = UtilsNode.getNode("ranklist_bg", this.node);
  81. this.checkRanking(RankingListData.myRank,ranklist_bg);
  82. this.setItemData(RankingListData.myRank,ranklist_bg);
  83. },
  84. setbackButtonClickListeniner : function (backButtonClick) {
  85. this.backButtonClick = backButtonClick;
  86. },
  87. backButtonClick : function () {
  88. },
  89. ranklist_backCallback: function () {
  90. this.addCurr(false);
  91. },
  92. ranklist_nextCallback: function () {
  93. this.addCurr(true);
  94. },
  95. setListData: function (num) {
  96. if (this.CallBack0) {
  97. this.CallBack0(num)
  98. }
  99. this.listDataPagearr = [];
  100. let tempArr = [];
  101. let tempi = 0;
  102. for (var i = 0; i < RankingListData.listdata1.length; i++) {
  103. tempArr.push(RankingListData.listdata1[i]);
  104. if (tempArr.length >= this.listDataPageCout || i == RankingListData.listdata1.length-1) {
  105. this.listDataPagearr.push(tempArr);
  106. tempArr = [];
  107. }
  108. // console.log("计数",tempArr ,tempArr.length);
  109. }
  110. console.log("分段数组是什么",this.listDataPagearr);
  111. // let tag = true;
  112. //
  113. // let tempArr = [];
  114. // while (tag){
  115. // temp.list[x]
  116. // }
  117. //
  118. this.setItemDataList(this.listDataPage);
  119. this.isShowButton();
  120. },
  121. setCallBack0 (CallBack0){
  122. this.CallBack0 = CallBack0
  123. },
  124. setItemDataList : function(page){
  125. // console.log("全国列表",this.ranklist.children);
  126. for (var i = 0; i <this.ranklist.children.length ; i++) {
  127. this.ranklist.children[i].destroy();
  128. }
  129. // console.log("一会要进去几次","全国原本的清空了",this.ranklist.children[i]);
  130. for (var i = 0; i < this.listDataPagearr[page].length; i++) {
  131. let temp = this.listDataPagearr[page][i];
  132. let x = i;
  133. // UtilsNode
  134. // .init(this.ranklist)
  135. // .addPrefabsName("item/ranklist_bg", null, x, function (node) {
  136. let item = this.getItem(this.ranklist);
  137. this.checkRanking(temp,item);
  138. this.setItemData(temp,item);
  139. // }.bind(this));
  140. }
  141. // setTimeout(function () {
  142. //
  143. // }.bind(this),1)
  144. },
  145. getItem : function(layout){
  146. let node = rankItems.getItem();
  147. node.parent = layout;
  148. return node;
  149. },
  150. checkRanking: function (data,node) {
  151. let Medal = UtilsNode.getNode("Medal", node);
  152. // console.log("都有啥" ,Medal);
  153. let ranklist_gold = UtilsNode.getNode("ranklist_gold", Medal);
  154. let ranklist_silver = UtilsNode.getNode("ranklist_silver", Medal);
  155. let ranklist_copper = UtilsNode.getNode("ranklist_copper", Medal);
  156. let num = UtilsNode.getNode("num", Medal);
  157. ranklist_gold.active = false;
  158. ranklist_silver.active = false;
  159. ranklist_copper.active = false;
  160. if (num!=null) {
  161. num.active = false;
  162. }
  163. switch (data.rank) {
  164. case 1:
  165. ranklist_gold.active = true;
  166. break;
  167. case 2:
  168. ranklist_silver.active = true;
  169. break;
  170. case 3:
  171. ranklist_copper.active = true;
  172. break;
  173. default:
  174. if (num!=null) {
  175. num.active = true;
  176. num.getComponent(cc.Label).string = data.rank;
  177. }
  178. break;
  179. }
  180. },
  181. setItemData : function (data,node) {
  182. let ranklist_ic = UtilsNode.getNode("ranklist_ic", node);
  183. let playername = UtilsNode.getNode("playername", node);
  184. let Score = UtilsNode.getNode("Score", node);
  185. // ranklist_ic.width = 76;
  186. // ranklist_ic.height = 76;
  187. // console.log("现在要设置 图片了",data.portraits);
  188. utils.loadHttpSpriteFrame(data.portraits, ranklist_ic.getComponent(cc.Sprite));
  189. // console.log("你把个时候",ranklist_ic);
  190. playername.getComponent(cc.Label).string = data.nickName;
  191. Score.getComponent(cc.Label).string = data.score;
  192. },
  193. //增加或者减少 索引的时候
  194. addCurr : function(b){
  195. // console.log("增加 减少",b,"当前索引",this.curr,"总长度是",this.listview.children.length);
  196. if (b) {
  197. if (this.listDataPage < this.listDataPagearr.length-1) {
  198. this.listDataPage++;
  199. this.setItemDataList(this.listDataPage);
  200. this.isShowButton();
  201. }
  202. if (this.listDataPage == this.listDataPagearr.length-1) {
  203. this.morePagea++;
  204. utils.isMobile(function () {
  205. manager_android_js.getRanking( this.typelist,this.morePagea,0,10)
  206. }.bind(this));
  207. Log.info("现在要添加数据了 全国");
  208. utils.isWeb(function () {
  209. if (!this.nextActive) {
  210. RankingListData.setAdd1();
  211. var temp = 5
  212. if (this.morePagea > 2) {
  213. temp = 0
  214. }
  215. this.setListData(temp);
  216. }
  217. }.bind(this))
  218. this.setCallBack0(function (num) {
  219. Log.info("那边回调 是什么 全国 长度",num);
  220. if (num == 0) {
  221. this.nextActive = true
  222. }
  223. }.bind(this));
  224. }
  225. }else{
  226. if (this.listDataPage > 0) {
  227. this.listDataPage--;
  228. this.setItemDataList(this.listDataPage);
  229. this.isShowButton();
  230. }
  231. }
  232. //
  233. },
  234. //是否显示 上一页或者下一页的 按钮
  235. isShowButton : function(){
  236. // console.log("现在是",this.listDataPage);
  237. if (this.listDataPage == 0) {
  238. this.ranklist_back.active = false;
  239. if (this.listDataPagearr.length > 0) {
  240. this.ranklist_next.active = true;
  241. }else{
  242. this.ranklist_next.active = false;
  243. }
  244. }else if (this.listDataPage == this.listDataPagearr.length-1) {
  245. this.ranklist_back.active = true;
  246. if (this.nextActive) {
  247. this.ranklist_next.active = false;
  248. }
  249. //
  250. }else{
  251. this.ranklist_back.active = true;
  252. this.ranklist_next.active = true;
  253. }
  254. },
  255. // update (dt) {},
  256. });