PiggyBank.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { _decorator, Component, Node, Label, Sprite, SpriteFrame, Vec3, director } from 'cc';
  2. import { DataSystem } from '../core/data/DataSystem';
  3. import { Http, HttpResponseCode } from '../core/net/Http';
  4. import { Window } from '../core/ui/window/Window';
  5. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  6. import { WindowSystem } from '../core/ui/window/WindowSystem';
  7. import { UserData } from '../data/UserData';
  8. import { ReportThinking } from '../ReportThinking';
  9. const { ccclass, property, requireComponent } = _decorator;
  10. /**
  11. * 存钱罐
  12. */
  13. @ccclass('PiggyBank')
  14. @requireComponent(Http)
  15. export class PiggyBank extends Component {
  16. @property({ type: Label, tooltip: "数值文本" }) numLabel: Label;
  17. @property({ type: Node, tooltip: "领取按钮节点" }) getBtnNode: Node;
  18. @property({ type: SpriteFrame, tooltip: "特效资源" }) effectIcon: SpriteFrame;
  19. @property({ type: Node, tooltip: "背景" }) bg: Node;
  20. @property({ type: Window, tooltip: "当前窗口" }) myWin: Window;
  21. async start() {
  22. let result = await this.getComponent(Http).send("/api/dailyBonus/getDailyBonus");
  23. if (result && result.code == HttpResponseCode.Success) {
  24. let bonus = result.data.bonus || 0;
  25. this.numLabel.string = bonus;
  26. this.getBtnNode.active = result.data.canGet;
  27. }
  28. else {
  29. this.myWin.close();
  30. }
  31. }
  32. /**领取奖金 */
  33. private async getBouns() {
  34. if (!this.getBtnNode.active) {
  35. this.myWin.close();
  36. return;
  37. }
  38. let result = await this.getComponent(Http).send("/api/dailyBonus/receiveDailyBonus");
  39. if (result && result.code == HttpResponseCode.Success) {
  40. if (result.bonus) {
  41. this.numLabel.string = '0';
  42. let userData = DataSystem.getData(UserData);
  43. ReportThinking.currency_increase('bonus', userData.bonus, result.bonus, userData.bonus + result.bonus, 'piggybank_get')
  44. WindowSystem.open("prefabs/ui/turntable/prizeFly", WindowOpenMode.NotCloseAndAdd, [{ type: 3, num: result.bonus }]);
  45. }
  46. this.myWin.close();
  47. }
  48. }
  49. private onClose() {
  50. this.bg.active = false;
  51. }
  52. }