| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import { _decorator, Component, Node, Button, Sprite, Animation } from 'cc';
- import { Http } from '../core/net/Http';
- import { WindowManager } from '../core/ui/window/WindowManager';
- import { g } from '../Data/g';
- import { platform } from '../Data/platform';
- const { ccclass, property } = _decorator;
- @ccclass('ElmWindow')
- export class ElmWindow extends Component {
- @property({ type: Http, tooltip: "http组件" }) http: Http;
- @property({ type: Button, tooltip: "兑换按钮" }) exchangeBtn: Button;
- private needBonus = 0;
- async start() {
- let result = await this.http.send("/api/user/getCouponTimes");
- if (result.code == 0) {
- this.needBonus = result.data.needBonus;
- if (result.data.times <= 0) {
- this.disableButton();
- }
- } else {
- WindowManager.showTips("数据获取失败,请稍后再试");
- this.disableButton();
- }
- }
- public async onExchange() {
- if (g.userData.bonus >= this.needBonus) {
- platform.umUp("elmClick");//饿了么埋点
- let result = await this.http.send("/api/user/getCoupon");
- if (result.code == 0) {
- g.userData.bonus -= result.data.needBonus;
- platform.openWXApplets(result.data.ghid, result.data.path);
- this.disableButton();
- } else {
- WindowManager.showTips("数据获取失败,请稍后再试");
- }
- } else {
- WindowManager.showTips("红包不足");
- }
- }
- private disableButton(): void {
- this.exchangeBtn.interactable = false;
- this.exchangeBtn.node.getComponent(Sprite).grayscale = true;
- this.exchangeBtn.getComponent(Animation).stop();
- }
- }
|