| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import { _decorator, Component, Node, Label, Sprite, SpriteFrame, Vec3, director } from 'cc';
- import { DataSystem } from '../core/data/DataSystem';
- import { Http, HttpResponseCode } from '../core/net/Http';
- import { Window } from '../core/ui/window/Window';
- import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
- import { WindowSystem } from '../core/ui/window/WindowSystem';
- import { UserData } from '../data/UserData';
- import { ReportThinking } from '../ReportThinking';
- const { ccclass, property, requireComponent } = _decorator;
- /**
- * 存钱罐
- */
- @ccclass('PiggyBank')
- @requireComponent(Http)
- export class PiggyBank extends Component {
- @property({ type: Label, tooltip: "数值文本" }) numLabel: Label;
- @property({ type: Node, tooltip: "领取按钮节点" }) getBtnNode: Node;
- @property({ type: SpriteFrame, tooltip: "特效资源" }) effectIcon: SpriteFrame;
- @property({ type: Node, tooltip: "背景" }) bg: Node;
- @property({ type: Window, tooltip: "当前窗口" }) myWin: Window;
- async start() {
- let result = await this.getComponent(Http).send("/api/dailyBonus/getDailyBonus");
- if (result && result.code == HttpResponseCode.Success) {
- let bonus = result.data.bonus || 0;
- this.numLabel.string = bonus;
- this.getBtnNode.active = result.data.canGet;
- }
- else {
- this.myWin.close();
- }
- }
- /**领取奖金 */
- private async getBouns() {
- if (!this.getBtnNode.active) {
- this.myWin.close();
- return;
- }
- let result = await this.getComponent(Http).send("/api/dailyBonus/receiveDailyBonus");
- if (result && result.code == HttpResponseCode.Success) {
- if (result.bonus) {
- this.numLabel.string = '0';
- let userData = DataSystem.getData(UserData);
- ReportThinking.currency_increase('bonus', userData.bonus, result.bonus, userData.bonus + result.bonus, 'piggybank_get')
- WindowSystem.open("prefabs/ui/turntable/prizeFly", WindowOpenMode.NotCloseAndAdd, [{ type: 3, num: result.bonus }]);
- }
- this.myWin.close();
- }
- }
- private onClose() {
- this.bg.active = false;
- }
- }
|