RedeemNode.ts 4.6 KB

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