RedeemNode.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * @description 兑换码界面
  3. * @author kaka
  4. */
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class RichHelpPanel extends cc.Component {
  8. @property(cc.Label)
  9. txtGiftName: cc.Label = null;
  10. @property(cc.Prefab)
  11. videoPre: cc.Prefab = null;
  12. @property(cc.Node)
  13. rds: cc.Node[] = [];
  14. @property(cc.Sprite)
  15. rd_imgs: cc.Sprite[] = [];
  16. @property(cc.Label)
  17. rd_txts: cc.Label[] = [];
  18. @property(cc.EditBox)
  19. inputBox: cc.EditBox = null;
  20. @property(cc.Node)
  21. suc_node: cc.Node = null;
  22. @property(cc.Node)
  23. suc_node_panel: cc.Node = null;
  24. @property(cc.Node)
  25. suc_rds: cc.Node[] = [];
  26. @property(cc.Sprite)
  27. suc_rd_imgs: cc.Sprite[] = [];
  28. @property(cc.Label)
  29. suc_rd_txts: cc.Label[] = [];
  30. videoNode = null;
  31. rewardData: any = null;
  32. update() {
  33. if (gData.redeem.init_redeemData) {
  34. this.InitData();
  35. }
  36. }
  37. lateUpdate() {
  38. gData.redeem.init_redeemData = false;
  39. }
  40. InitData() {
  41. let data = gData.redeem.redeemData.redemption;
  42. this.txtGiftName.string = data.title;
  43. this.rewardData = data.content;
  44. for (let n of this.rds) {
  45. n.active = false;
  46. }
  47. for (let m of this.suc_rds) {
  48. m.active = false;
  49. }
  50. for (let i = 0; i < this.rewardData.length; i++) {
  51. this.rds[i].active = true;
  52. this.suc_rds[i].active = true;
  53. cc.loader.loadRes("game/texture/coin/" + this.rewardData[i].type, cc.SpriteFrame, (err, res) => {
  54. if (err) { console.log("img load err:" + JSON.stringify(err)); }
  55. this.rd_imgs[i].spriteFrame = res;
  56. this.suc_rd_imgs[i].spriteFrame = res;
  57. });
  58. if (this.rewardData[i].type == "10001") {
  59. this.rd_txts[i].string = mk.math.format(this.rewardData[i].count) + "分钟";
  60. this.suc_rd_txts[i].string = mk.math.format(this.rewardData[i].count) + "分钟";
  61. } else {
  62. this.rd_txts[i].string = mk.math.format(this.rewardData[i].count);
  63. this.suc_rd_txts[i].string = mk.math.format(this.rewardData[i].count);
  64. }
  65. }
  66. }
  67. async Click_RedeemBtn() {
  68. console.log("---RedeemCode: " + this.inputBox.string);
  69. if (this.inputBox.string != "") {
  70. let response = await gData.redeem.redeemExchange(this.inputBox.string);
  71. if (response && response.data.code == 1) {
  72. console.log("兑换成功");
  73. this.suc_node_panel.scale = 0;
  74. this.suc_node.active = true;
  75. cc.tween(this.suc_node_panel).to(0.2, { scale: 1 }, { easing: "backOut" }).start();
  76. }
  77. else {
  78. mk.tip.pop(response.data.msg);
  79. }
  80. } else {
  81. mk.tip.pop('请输入兑换码');
  82. }
  83. }
  84. coolTime = false
  85. /** 点击教程 */
  86. async Click_TeachBtn() {
  87. mk.audio.playEffect('button');
  88. if (this.coolTime) {
  89. return
  90. }
  91. this.coolTime = true
  92. console.log('clickTeach')
  93. gData.redCodeData.teachVideoType = 2;
  94. this.videoNode = cc.instantiate(this.videoPre)
  95. this.videoNode.getChildByName('video').on("completed", this.onCompleted, this)
  96. this.node.addChild(this.videoNode)
  97. }
  98. onCompleted() {
  99. this.videoNode.getChildByName('video').off("completed", this.onCompleted, this)
  100. this.videoNode.destroy()
  101. // GameM.audioM.setResumeMusic()
  102. this.coolTime = false
  103. }
  104. /** 点击复制公众号 */
  105. clickCopyOfficial() {
  106. mk.audio.playEffect('button');
  107. // AdM.setClipboard("白羊游戏社")
  108. }
  109. /** 点击复制礼包名 */
  110. clickCopyInfo() {
  111. mk.audio.playEffect('button');
  112. // AdM.setClipboard(this.txtTitle.string)
  113. }
  114. async Click_GetBtn() {
  115. this.suc_node.active = false;
  116. for (let i = 0; i < this.rewardData.length; i++) {
  117. mk.audio.playEffect('rewardClose');
  118. mk.fly.PlayCoinAnim(this.rewardData[i].type, 5, cc.v2(0, -300), cc.v2(0, 0))
  119. }
  120. let response = await gData.redeem.redeemGetRedemption();
  121. // if (response && response.data.code == 1) {
  122. // this.InitData();
  123. // }
  124. // else {
  125. // }
  126. // AdM.onSendEvent('duihuan_success', '兑换码-兑换成功', 'duihuan')
  127. }
  128. }