PiggyBank.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { _decorator, Component, Node, Label, find } from 'cc';
  2. import { Http, HttpResponseCode } from '../../core/net/Http';
  3. import { Window } from '../../core/ui/window/Window';
  4. import { g } from '../../Data/g';
  5. import { UIEffect } from '../UIEffect';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('PiggyBank')
  8. export class PiggyBank extends Component {
  9. @property({ type: Label, tooltip: "数值文本" }) numLabel: Label;
  10. @property({ type: Node, tooltip: "领取按钮节点" }) getBtnNode: Node;
  11. @property({ type: Node, tooltip: "背景" }) bg: Node;
  12. @property({ type: Window, tooltip: "当前窗口" }) myWin: Window;
  13. async start() {
  14. let result = await this.getComponent(Http).send("/api/dailyBonus/getDailyBonus");
  15. if (result && result.code == HttpResponseCode.Success) {
  16. let bonus = result.data.bonus || 0;
  17. this.numLabel.string = bonus;
  18. this.getBtnNode.active = result.data.canGet;
  19. }
  20. else {
  21. this.myWin.close();
  22. }
  23. }
  24. /**领取奖金 */
  25. private async getBouns() {
  26. if (!this.getBtnNode.active) {
  27. this.myWin.close();
  28. return;
  29. }
  30. let result = await this.getComponent(Http).send("/api/dailyBonus/receiveDailyBonus");
  31. if (result && result.code == HttpResponseCode.Success) {
  32. if (result.bonus) {
  33. this.numLabel.string = '0';
  34. g.userData.bonus += result.bonus;
  35. find("Canvas/UI").getComponent(UIEffect).showBezierRedBagEffect(0, null, 1);
  36. //WindowSystem.open("prefabs/ui/turntable/prizeFly", WindowOpenMode.NotCloseAndCover, [{ type: 3, num: result.bonus }]);
  37. }
  38. this.myWin.close();
  39. }
  40. }
  41. private onClose() {
  42. this.bg.active = false;
  43. }
  44. }