ShangCardLayer.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import SoundMgr from "../base/SoundMgr";
  2. import Tool from "../base/Tool";
  3. var baseLayer = require('BaseLayer');
  4. cc.Class({
  5. extends: baseLayer,
  6. properties: {
  7. labT: cc.Label,
  8. labTime: cc.Label,
  9. labJi: cc.Label,
  10. labY: cc.Label,
  11. itemPre: cc.Node,
  12. conNode: cc.Node,
  13. ruleNode: cc.Node,
  14. acNode: cc.Node,
  15. },
  16. // LIFE-CYCLE CALLBACKS:
  17. // onLoad () {},
  18. start () {
  19. this.tData = [6, 30, 68, 98, 198, 328, 648];
  20. this.lerpTime = 20;
  21. this.curIndex = 0;
  22. this.acNode.getComponent('RechargeActivity').setType(2, this);
  23. this.daoshiji();
  24. this.schedule(this.daoshiji, 1, cc.macro.REPEAT_FOREVER);
  25. this.setData();
  26. },
  27. setData(){
  28. this.labT.string = `x${123}`;
  29. this.labTime.string = '';
  30. this.labJi.string = '204万';
  31. this.labY.string = this.tData[this.curIndex] + '元 立即激活';
  32. this.initItems();
  33. },
  34. initItems(){
  35. this.conNode.removeAllChildren();
  36. for(let i=0; i < 7; i++){
  37. let temp = cc.instantiate(this.itemPre);
  38. temp.setParent(this.conNode);
  39. temp.name = `${i}`;
  40. temp.active = true;
  41. temp.getChildByName('lab').getComponent(cc.Label).string = '1234';
  42. temp.getChildByName('labTitle').getComponent(cc.Label).string = '标题呀';
  43. temp.getChildByName('bar').getComponent(cc.Sprite).fillRange = 0.6;
  44. temp.getChildByName('labBar').getComponent(cc.Label).string = '12/88';
  45. let gonode = temp.getChildByName('btnGo');
  46. gonode.active = false;
  47. Tool.addBtnListener(gonode, this.node, 'ShangCardLayer', 'onClickGo', i);
  48. let getnode = temp.getChildByName('btnGet');
  49. getnode.active = true;
  50. Tool.addBtnListener(getnode, this.node, 'ShangCardLayer', 'onClickGet', i);
  51. let done = temp.getChildByName('done');
  52. done.active = false;
  53. }
  54. },
  55. onClickArrow(event, xx){
  56. if(xx == 'left'){
  57. this.curIndex -= 1;
  58. this.curIndex = this.curIndex <=0 ? 0 : this.curIndex;
  59. }else{
  60. this.curIndex += 1;
  61. this.curIndex = this.curIndex >= this.tData.length ? (this.tData.length -1) : this.curIndex;
  62. }
  63. this.setData();
  64. },
  65. daoshiji(){
  66. if(this.lerpTime <= 1){
  67. this.labTime.node.active = false;
  68. this.unschedule(this.daoshiji);
  69. return;
  70. }
  71. this.labTime.node.active = true;
  72. this.lerpTime -= 1;
  73. this.labTime.string = Tool.timesBySec2(this.lerpTime);
  74. },
  75. onClickGo(event, customEventData){
  76. SoundMgr.playClick();
  77. console.log('go: ', customEventData);
  78. },
  79. onClickGet(event, customEventData){
  80. SoundMgr.playClick();
  81. console.log('get: ', customEventData);
  82. },
  83. onClickJi(){
  84. SoundMgr.playClick();
  85. },
  86. onClickRule(){
  87. SoundMgr.playClick();
  88. this.ruleNode.active = !this.ruleNode.active;
  89. },
  90. });