import { _decorator, Component, Node, Label } from 'cc'; import { RewardVideoSystem } from '../../ad/RewardVideoSystem'; import { DataSystem } from '../../core/data/DataSystem'; import { Http, HttpResponseCode, ResponseType } from '../../core/net/Http'; import { HttpSystem } from '../../core/net/HttpSystem'; import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode'; import { WindowSystem } from '../../core/ui/window/WindowSystem'; import { ConfigData } from '../../data/ConfigData'; import { platform } from '../../data/jsb/platform'; import { UserData } from '../../data/UserData'; import { ReportThinking } from '../../ReportThinking'; const { ccclass, property } = _decorator; /** * 元宝兑换页 * @author 郑聂华 */ @ccclass('DiamondExchangeUI') export class DiamondExchangeUI extends Component { @property({ type: Label, displayName: '文本_红包', tooltip: "文本_红包" }) txtRb: Label = null; @property({ type: Label, displayName: '文本_元宝', tooltip: "文本_元宝" }) txtDiamond: Label = null; @property({ type: Node, displayName: '箭头' }) arrawNode: Node = null; @property({ type: Node, displayName: '红包节点' }) redBagNode: Node = null; @property({ type: Node, displayName: '广告图标' }) adIcon: Node = null; @property({ type: Label, displayName: '文本_已兑换次数' }) txtTimes: Label = null; /**兑换配置 {exchangeBonus:1,exchangeDiamond:2,times:1,type:"bonus"}*/ private exChangeCfg: any; private usedExchangeTimes: number; /**最高兑换次数*/ private limitNum: number; private enterType: number; onParam(param) { this.enterType = parseInt(param); } start() { this.initPanel(); } /**界面初始化*/ private async initPanel() { let result = await this.getComponent(Http).send("/api/recruit/GetExchange"); if (result && result.code == HttpResponseCode.Success) { this.limitNum = Object.keys(result.data.config).length; this.usedExchangeTimes = result.data.hadExchangedTimes; this.exChangeCfg = this.usedExchangeTimes == this.limitNum ? result.data.config[this.limitNum + ""] : result.data.config[(this.usedExchangeTimes + 1) + ""]; //this.limitNum = result.data.config["bonus"].times + result.data.config["video"].times; //this.usedExchangeTimes = this.limitNum - (result.data.freeTimes + result.data.videoTimes); //if (result.data.freeTimes > 0) { this.exChangeCfg = result.data.config["bonus"]; } //else { this.exChangeCfg = result.data.config["video"]; } this.txtRb.string = this.exChangeCfg.exchangeBonus + ""; this.txtDiamond.string = this.exChangeCfg.exchangeDiamond + ""; this.txtTimes.string = this.usedExchangeTimes + "/" + this.limitNum; //剩余次数数据待定 this.adIcon.active = this.exChangeCfg.type == "video"; this.arrawNode.active = this.exChangeCfg.type == "bonus"; this.redBagNode.active = this.exChangeCfg.type == "bonus"; } } /**红包兑换*/ private async exchangeByBonus() { let result = await this.getComponent(Http).send("/api/recruit/Exchange", { type: "bonus" }); if (result && result.code == HttpResponseCode.Success) { let userData = DataSystem.getData(UserData); ReportThinking.currency_decrease('bonus', userData.bonus, this.exChangeCfg.exchangeBonus, userData.bonus - this.exChangeCfg.exchangeBonus, 'exchange'); DataSystem.getData(UserData).bonus -= this.exChangeCfg.exchangeBonus; //DataSystem.getData(UserData).diamond += this.exChangeCfg.exchangeDiamond; ReportThinking.currency_increase('diamond', userData.diamond, this.exChangeCfg.exchangeDiamond, this.exChangeCfg.exchangeDiamond + userData.diamond, 'exchange'); WindowSystem.close(this.node); WindowSystem.open("prefabs/ui/turntable/prizeFly", WindowOpenMode.NotCloseAndAdd, [{ type: this.enterType, num: this.exChangeCfg.exchangeDiamond }]); WindowSystem.showTips("兑换成功"); } else { WindowSystem.showTips("兑换失败"); } } /**视频免费获取*/ private async exchangeByVideo() { let resultAd = await this.getComponent(Http).send("/api/ad/watchVideoAD"); if (resultAd && resultAd.code == HttpResponseCode.Success) { //可以观看视频 ReportThinking.ad_init('exchange_diamond'); let adData = await RewardVideoSystem.show(); if (adData) { let result = await this.getComponent(Http).send("/api/recruit/Exchange", { type: "video", adData: adData.obj }); if (result && result.code == HttpResponseCode.Success) { ReportThinking.ad_end('exchange_diamond'); let userData = DataSystem.getData(UserData); //DataSystem.getData(UserData).diamond += this.exChangeCfg.exchangeDiamond; WindowSystem.close(this.node); ReportThinking.currency_increase('diamond', userData.diamond, this.exChangeCfg.exchangeDiamond, this.exChangeCfg.exchangeDiamond + userData.diamond, 'exchange_video'); WindowSystem.open("prefabs/ui/turntable/prizeFly", WindowOpenMode.NotCloseAndAdd, [{ type: this.enterType, num: this.exChangeCfg.exchangeDiamond }]); WindowSystem.showTips("兑换成功"); } else { WindowSystem.showTips("兑换失败"); } } else { WindowSystem.showTips("观看视频失败"); } } } private onClickExchange() { if (this.exChangeCfg.type == "bonus") { if (this.usedExchangeTimes < this.limitNum && DataSystem.getData(UserData).bonus >= this.exChangeCfg.exchangeBonus) { this.exchangeByBonus(); } else { if (this.usedExchangeTimes >= this.limitNum) { WindowSystem.showTips("兑换次数用完"); return; } DataSystem.getData(UserData).bonus < this.exChangeCfg.exchangeBonus && WindowSystem.showTips("红包币不足"); } } else { if (this.usedExchangeTimes < this.limitNum) { this.exchangeByVideo(); } else { WindowSystem.showTips("兑换次数用完"); } } } }