import { _decorator, Component, Node, RichText, Label, Sprite, SpriteFrame, Button, EventHandler, game } from 'cc';
import InfiniteCell from '../core/InfiniteList/InfiniteCell';
import { Http } from '../core/net/Http';
import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
import { OpenWindow } from '../core/ui/window/OpenWindow';
import { WindowManager } from '../core/ui/window/WindowManager';
import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
import { ConfigData } from '../Data/ConfigData';
import { g } from '../Data/g';
import { platform } from '../Data/platform';
import { LoginWaitWin } from '../Windows/LoginWaitWin';
import { NoviceWindow } from '../Windows/NoviceWindow';
const { ccclass, property } = _decorator;
@ccclass('DiamondWithItem')
export class DiamondWithItem extends InfiniteCell {
@property({ tooltip: "神石消耗文本", type: RichText }) public diamond: RichText;
@property({ tooltip: "兑换金额文本", type: Label }) public money: Label;
@property({ tooltip: "提现按钮", type: Node }) public withBtn: Node;
@property({ tooltip: "提现图标", type: Node }) public withIcon: Node;
@property({ tooltip: "已提现图标", type: Node }) public withendIcon: Node;
@property({ tooltip: "http服务", type: Http }) public http: Http;
public withdrawGrade = 0;//提现档次
public needDiamond = 0;//兑换所需消耗神石
public backFun: EventHandler;
start() {
g.gameData.isPlayVideo = false;
}
/**
* 界面初始化
* @param data item数据
*/
public UpdateContent(data: any) {
this.diamond.string = "消耗" + data.needDiamond + "神石";
this.money.string = data.needDiamond / ConfigData.configMap.get("systemConfig").moneyRate + "元";
this.withdrawGrade = data.grade;
this.needDiamond = data.needDiamond;
this.backFun = data.backFun;
if (g.gameData.diamondWithdrawGrade == (this.withdrawGrade - 1)) {
this.withIcon.active = true;
this.withendIcon.active = false;
if (g.userData.diamond >= data.needDiamond) {
this.withBtn.getComponent(Button).interactable = true;
this.withIcon.getComponent(Sprite).grayscale = false;//置灰
} else {
this.withBtn.getComponent(Button).interactable = false;
this.withIcon.getComponent(Sprite).grayscale = true;//置灰
}
} else if (g.gameData.diamondWithdrawGrade < (this.withdrawGrade - 1)) {
this.withBtn.getComponent(Button).interactable = false;
this.withIcon.active = true;
this.withendIcon.active = false;
this.withIcon.getComponent(Sprite).grayscale = true;//置灰
} else {
this.withBtn.getComponent(Button).interactable = false;
this.withIcon.active = false;
this.withendIcon.active = true;
}
}
public isSend = false;
/**
* 神石提现
*/
public async with() {
if (g.gameData.diamondWithdrawGrade == (this.withdrawGrade - 1)) {
if (g.gameData.isPlayVideo) {
return;
}
g.gameData.isPlayVideo = true;
//#region 打开加载等待界面
// let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover);
//#endregion
let date = await this.http.send("/api/wealth/Withdraw", { type: 3, grade: this.withdrawGrade });
// _window.getComponent(LoginWaitWin).close();//关闭加载等待界面
if (date.code === 0 && !date.message) {
//提现成功
if (NoviceWindow.isNovicing) {
NoviceWindow.isNovicing = false;
}
g.gameData.diamondWithdrawGrade = date.grade;
g.userData.diamond -= this.needDiamond;
platform.volcanicReport('withdrawForDiamond');
WindowManager.showTips("提现成功,72小时内到账");
this.backFun.emit([]);
} else if (date.message) {
WindowManager.showTips(date.message);
} else {
WindowManager.showTips("网络异常,请稍候再试");
}
g.gameData.isPlayVideo = false;
} else {
WindowManager.showTips("当前不可领取");
}
}
}