/* * @Author: mojunshou 1637302775@qq.com * @Date: 2025-03-20 17:53:50 * @LastEditors: mojunshou 1637302775@qq.com * @LastEditTime: 2025-04-23 17:29:58 * @Description: 红包提现 */ import { _decorator, Label, Node } from "cc"; import { oops } from "db://oops-framework/core/Oops"; import { DeviceUtil } from "db://oops-framework/core/utils/DeviceUtil"; import { ecs } from "db://oops-framework/libs/ecs/ECS"; import { CCVMParentComp } from "db://oops-framework/module/common/CCVMParentComp"; import { GameEvent } from "../common/config/GameEvent"; import { UIID } from "../common/config/GameUIConfig"; import { ServerHandler } from "../common/manager/ServerHandler"; import List from "../ui/List"; import { RedPackeItemView } from "./RedPackeItemView"; import { smc } from "../common/SingletonModuleComp"; import { Format } from "../utils/Format"; import { DCHandler } from "../common/manager/DCHandler"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('RedPackeWithdrawalViewComp') @ecs.register(`RedPackeWithdrawalViewComp`, false) export class RedPackeWithdrawalViewComp extends CCVMParentComp { @property(List) recordList: List = null!; @property(Label) lab_tips: Label = null!; data: any = { tasklist: [], wxCash: 0, hbCoin: 0, goldNum: 0 }; start() { this.setButton(); this.addEvent(); DCHandler.inst.reportData(3000900); this.data.taskList = smc.game.GameModel.taskList; this.data.wxCash = smc.game.GameModel.wxCash; this.data.hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin); this.data.goldNum = smc.account.AccountModel.goldCoin; if (this.data.taskList.length > 0) { this.recordList.numItems = this.data.taskList.length; } this.lab_tips.string = `当前收集金砖${this.data.goldNum}块,红包10000元=人民币1元`; } addEvent() { oops.message.on(GameEvent.updateRedPackeTaskList, this.updateList, this); oops.message.on(GameEvent.updateHbAndWxCoin, this.updateCoin, this); } private onListRender(item: Node, idx: number) { const itemView: RedPackeItemView | null = item.getComponent(RedPackeItemView); if (itemView) { itemView.setItem(this.data.taskList[idx], idx); } } updateList() { // console.log("更新提现记录信息", this.data.wxCash); this.data.taskList = smc.game.GameModel.taskList; this.data.wxCash = smc.game.GameModel.wxCash; this.data.hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin); this.data.goldNum = smc.account.AccountModel.goldCoin; this.recordList.numItems = 0; if (this.data.taskList.length > 0) { this.recordList.numItems = this.data.taskList.length; } this.lab_tips.string = `当前收集金砖${this.data.goldNum}块,红包10000元=人民币1元`; oops.gui.toast("领取成功"); } updateCoin() { console.log("更新红包币和微信币", smc.account.AccountModel.hbCoin, smc.game.GameModel.wxCash); this.data.wxCash = smc.game.GameModel.wxCash; this.data.hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin); //可以提现的那个金额币 } private btn_back() { oops.gui.remove(UIID.RedPacketWithdraw); oops.message.dispatchEvent(GameEvent.updateGameState, "playing"); DCHandler.inst.reportData(3000901); } private btn_record() { if (DeviceUtil.isNative && DeviceUtil.isAndroid) { ServerHandler.inst.getRecordList(); DCHandler.inst.reportData(3000902); } else { oops.gui.open(UIID.WithdrawRecord); } } private async btn_withdrawal() { //全部提现 if (this.data.wxCash > 0.1) { ServerHandler.inst.HbReward(); DCHandler.inst.reportData(3000900, 1001); } else { oops.gui.toast("微信官方限制大于0.1元,才能提现~"); DCHandler.inst.reportData(3000900, 1002); } } /** 视图对象通过 ecs.Entity.remove(WechatWithdrawalViewComp) 删除组件是触发组件处理自定义释放逻辑 */ reset() { this.node.destroy(); } formatNumber(num: number) { return Math.round(num * 100) / 100; } }