RedeemNode.ts 4.6 KB

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