RedeemNode.ts 5.0 KB

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