RedeemNode.ts 4.6 KB

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