MyApplet.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const HomeApi = require('../net/HomeApi');
  2. const AlertManager = require('../utils/AlertManager');
  3. const GameModule = require("../utils/GameModule");
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. btnSpriteFrame: [cc.SpriteFrame],
  8. gainButton: cc.Button
  9. },
  10. // LIFE-CYCLE CALLBACKS:
  11. onLoad () {
  12. if (Global.isMineEnter) {
  13. this.gainButton.interactable = true;
  14. this.gainButton.getComponent(cc.Sprite).spriteFrame = this.btnSpriteFrame[1];
  15. } else {
  16. this.gainButton.interactable = false;
  17. this.gainButton.getComponent(cc.Sprite).spriteFrame = this.btnSpriteFrame[0];
  18. }
  19. },
  20. start () {
  21. },
  22. gainAward() {
  23. GameModule.audioMng.playClickButton();
  24. this.gainButton.interactable = false;
  25. HomeApi.getAppletAward((respondData) => {
  26. GameModule.audioMng.playGetAward();
  27. if (respondData.diamond) {
  28. let showText = `钻石 x ${respondData.diamond}`;
  29. AlertManager.showActGiftAlert('diamond', showText);
  30. GameModule.userInfo.updateUserRes({
  31. diamond: parseInt(respondData.diamond)
  32. });
  33. } else {
  34. Global.commonAlert.showCommonErrorAlert("领取奖励成功");
  35. }
  36. GameGlobal.appletAward = true;
  37. this.node.destroy();
  38. GameEvent.fire('Gain_My_Applet');
  39. }, (code, msg) => {
  40. this.gainButton.interactable = true;
  41. Global.commonAlert.showCommonErrorAlert("领取失败");
  42. });
  43. },
  44. closeView() {
  45. GameModule.audioMng.playClickButton();
  46. this.node.destroy();
  47. }
  48. // update (dt) {},
  49. });