import { _decorator, Component, Node, Label, Button, RichText, Sprite } from 'cc'; import InfiniteCell from '../core/InfiniteList/InfiniteCell'; import { Http, HttpResponseCode } from '../core/net/Http'; import { BitmapFont } from '../core/ui/BitmapFont'; import { WindowManager } from '../core/ui/window/WindowManager'; import { WindowOpenMode } from '../core/ui/window/WindowOpenMode'; import { Utils } from '../core/utils/Utils'; import { g } from '../Data/g'; import { platform } from '../Data/platform'; const { ccclass, property } = _decorator; @ccclass('WithdrawItem') export class WithdrawItem extends InfiniteCell { @property({ type: Http, tooltip: "HTTP网络请求" }) public http: Http = null; @property({ type: BitmapFont, tooltip: "金额" }) public money: BitmapFont = null; @property({ type: BitmapFont, tooltip: "红包券" }) public redbagNum: BitmapFont = null; @property({ type: Sprite, tooltip: "已经领取按钮" }) public geted: Sprite = null; @property({ type: Button, tooltip: "领取按钮" }) public get: Button = null; @property({ type: Button, tooltip: "领取按钮" }) public exchange: Button = null; @property({ type: Button, tooltip: "不可领取按钮" }) public unget: Button = null; public itemMoney = 0; public itemRedbag = 0; private cashCode = ""; //子项数据注入 UpdateContent(data: any): void { this.money.string = data.money + "元"; this.redbagNum.string = `${data.needBonus}`; this.state = data.state; this.itemMoney = data.money; this.itemRedbag = data.needBonus; if (data.cashCode) { this.cashCode = data.cashCode; } } set state(state: ButtonState) { this.get.node.active = this.unget.node.active = this.geted.node.active = this.exchange.node.active = false; switch (state) { case ButtonState.canget: this.get.node.active = true; break; case ButtonState.geted: this.geted.node.active = true; break; case ButtonState.unget: this.unget.node.active = true; break; case ButtonState.exchange: this.exchange.node.active = true; break; } } /** * 提现点击 */ async onWithdrawClick() { let result = await this.http.send("/api/user/withdraw", { type: this.dataIndex != 0 ? 3 : 4, index: this.dataIndex }); if (result.code === 0 && !result.message) { platform.reportThinking("envelope_decrease", JSON.stringify({ previous_number: g.userData.bonus, decrease_number: this.itemRedbag, current_number: g.userData.bonus - this.itemRedbag, reasons: "withdraw" })); g.userData.bonus -= this.itemRedbag; if (result.cashCode != "") { this.cashCode = result.cashCode; this.onExchangeButton(); } else { WindowManager.open("Prefabs/DayPrize/DayPrizeTips", WindowOpenMode.NotCloseAndAdd, null); } platform.reportThinking("ad_init", JSON.stringify({ ad_id: "withDraw", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel() })); platform.showRewardVideoAD(); } else if (result.message) { WindowManager.showTips(result.message); } else if (result.code != HttpResponseCode.KeyError) { WindowManager.showTips("网络异常,请稍候再试"); } } public onExchangeButton(): void { WindowManager.open("Prefabs/Withdraw/GZHWithdrawWindow", WindowOpenMode.NotCloseAndAdd, this.cashCode); } } export enum ButtonState { unget, canget, geted, exchange }