dappListInfo.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /**
  2. * 生成对应的列表信息
  3. */
  4. var listInfoType = cc.Enum({
  5. none: 0,
  6. cnt: 1,
  7. snb: 2
  8. })
  9. cc.Class({
  10. extends: cc.Component,
  11. properties: {
  12. listInfoPrefab: {
  13. default: null,
  14. type: cc.Prefab,
  15. serializable: true,
  16. },
  17. listContainer: {
  18. default: null,
  19. type: cc.Node
  20. },
  21. value_set: {
  22. default: null,
  23. visible: false
  24. },
  25. scroll_view: { //获取scrollview组件
  26. type: cc.ScrollView,
  27. default: null,
  28. },
  29. HIGH: 80, //每一项的高度
  30. PAGE_NUM: 4, //每一页4个项
  31. listType: {
  32. default: listInfoType.none,
  33. type: cc.Enum(listInfoType),
  34. },
  35. snbData: {
  36. default: null,
  37. visible: false
  38. },
  39. snbPage: 1,
  40. snbLimit: 8,
  41. snbIndex: 0,
  42. cntData: {
  43. default: null,
  44. visible: false
  45. },
  46. cntPage: 1,
  47. cntLimit: 8,
  48. cntIndex: 0,
  49. TitleSPriteNode: {
  50. type: cc.Node,
  51. default: null,
  52. },
  53. snbSprite: {
  54. type: cc.SpriteFrame,
  55. default: null,
  56. },
  57. cntSprite: {
  58. type: cc.SpriteFrame,
  59. default: null,
  60. },
  61. cntOutContainer: {
  62. type: cc.Node,
  63. default: null,
  64. },
  65. outPanelContainer: {
  66. type: cc.Node,
  67. default: null,
  68. },
  69. outCNTValue: {
  70. type: cc.Label,
  71. default: null,
  72. },
  73. opt_item_set: []
  74. },
  75. // LIFE-CYCLE CALLBACKS:
  76. onLoad() {
  77. },
  78. start() {
  79. // this.onOpentList();
  80. this.scroll_view.node.on("scroll-ended", this.on_scroll_ended.bind(this), this);//监听scrollview事件
  81. this.opt_item_set = [];
  82. //每次加载3页
  83. for (var i = 0; i < this.PAGE_NUM * 3; i++) {
  84. let _info = cc.instantiate(this.listInfoPrefab);
  85. _info.active = false;
  86. this.listContainer.addChild(_info);
  87. this.opt_item_set.push(_info);
  88. }
  89. this.start_y = this.listContainer.y;//初始化起始y坐标
  90. this.start_index = 0; //100项数据里面的起始数据记录索引
  91. this.load_recode(this.start_index);
  92. },
  93. //更新cntList
  94. onCntUpdateList(list) {
  95. this.cntData = list;
  96. },
  97. //切换数据
  98. onShowList(type, list, isActive) {
  99. // console.log("onShowList:", type, list);
  100. //获取余额
  101. GlobalD.GameData.onCntCanWithdrawBalance((data) => {
  102. // console.log("站内收益余额:", GlobalD.GameData.CNTDrawBalance);
  103. this.outCNTValue.string = "CNT余额:" + Math.floor(GlobalD.GameData.CNTDrawBalance * 100) / 100;
  104. });
  105. this.node.active = isActive;
  106. if (type == "snbList") {
  107. this.snbData = list;
  108. this.cntIndex = this.start_index;
  109. this.value_set = Object.assign([], this.snbData);
  110. this.start_index = this.snbIndex;
  111. this.listType = listInfoType.snb;
  112. this.TitleSPriteNode.getComponent(cc.Sprite).spriteFrame = this.snbSprite;
  113. this.cntOutContainer.active = false;
  114. } else if (type == "cntList") {
  115. this.cntData = list;
  116. this.snbIndex = this.start_index;
  117. this.value_set = Object.assign([], this.cntData);
  118. this.start_index = this.cntIndex;
  119. this.listType = listInfoType.cnt;
  120. this.TitleSPriteNode.getComponent(cc.Sprite).spriteFrame = this.cntSprite;
  121. this.cntOutContainer.active = true;
  122. }
  123. this.load_recode(this.start_index);
  124. },
  125. load_recode: function (start_index) {
  126. this.start_index = start_index;
  127. if (this.opt_item_set.length <= 0) return;
  128. for (var i = 0; i < this.PAGE_NUM * 3; i++) {
  129. if (this.value_set.length <= i) {
  130. this.opt_item_set[i].active = false;
  131. continue;
  132. }
  133. this.opt_item_set[i].active = true;
  134. let _infoScript = this.opt_item_set[i].getComponent("dappListInfoItem");
  135. let _item = this.value_set[i];
  136. if (this.listType == listInfoType.snb) {
  137. let _temp = {
  138. listItemName: _item.tranName + (_item.tranAmount + _item.tranAmountPart) + "个",
  139. listItemDate: _item.createTime,
  140. remainder: _item.afterSnb + _item.afterSnbPart,
  141. amount: _item.isAdd == 1 ? '+' + (_item.tranSnb + _item.tranSnbPart) : '-' + (_item.tranSnb + _item.tranSnbPart),
  142. }
  143. _infoScript.setInfo(_temp);
  144. } else if (this.listType == listInfoType.cnt) {
  145. let _temp = {
  146. listItemName: "兑换后的cnt数:" + Math.floor(_item.now_amount * 100) / 100,
  147. listItemDate: _item.create_time,
  148. remainder: Math.floor(_item.amount * 100) / 100,
  149. amount: '',
  150. }
  151. _infoScript.setCntInfo(_temp);
  152. }
  153. }
  154. },
  155. load_scroll_recode: function () {
  156. //向下加载数据
  157. //当开始位置比value_set的长度小则代表没加载完
  158. if (this.start_index + this.PAGE_NUM * 3 < this.value_set.length &&
  159. this.listContainer.y >= this.start_y + this.PAGE_NUM * 2 * this.HIGH)//content超过2个PAGE的高度
  160. {
  161. //_autoScrolling在引擎源码中负责处理scrollview的滚动动作
  162. if (this.scroll_view._autoScrolling) { //等自动滚动结束后再加载防止滚动过快,直接跳到非常后的位置
  163. this.scroll_view.elastic = false; //关闭回弹效果 美观
  164. return;
  165. }
  166. var down_loaded = this.PAGE_NUM;
  167. this.start_index += down_loaded;
  168. if (this.start_index + this.PAGE_NUM * 3 > this.value_set.length) {
  169. //超过数据范围的长度
  170. var out_len = this.start_index + this.PAGE_NUM * 3 - this.value_set.length;
  171. down_loaded -= out_len;
  172. this.start_index -= out_len;
  173. }
  174. this.load_recode(this.start_index);
  175. this.listContainer.y -= down_loaded * this.HIGH;
  176. return;
  177. }
  178. //向上加载
  179. if (this.start_index > 0 && this.listContainer.y <= this.start_y) {
  180. if (this.scroll_view._autoScrolling) {
  181. this.scroll_view.elastic = false;
  182. return;
  183. }
  184. var up_loaded = this.PAGE_NUM;
  185. this.start_index -= up_loaded;
  186. if (this.start_index < 0) {
  187. up_loaded += this.start_index;
  188. this.start_index = 0;
  189. }
  190. this.load_recode(this.start_index);
  191. this.listContainer.y += up_loaded * this.HIGH;
  192. }
  193. },
  194. on_scroll_ended: function () {
  195. this.load_scroll_recode();
  196. this.scroll_view.elastic = true; //加载结束后自动滚动回弹开启
  197. },
  198. update(dt) {
  199. this.load_scroll_recode();
  200. },
  201. onClose() {
  202. this.node.active = false;
  203. },
  204. openOutPannel() {
  205. this.outPanelContainer.active = true;
  206. this.outPanelContainer.getComponent("CntInfo").setInfo();
  207. }
  208. });