RedeemNode.ts 4.4 KB

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