RedPackeWithdrawalViewComp.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-03-20 17:53:50
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-04-23 17:29:58
  6. * @Description: 红包提现
  7. */
  8. import { _decorator, Label, Node } from "cc";
  9. import { oops } from "db://oops-framework/core/Oops";
  10. import { DeviceUtil } from "db://oops-framework/core/utils/DeviceUtil";
  11. import { ecs } from "db://oops-framework/libs/ecs/ECS";
  12. import { CCVMParentComp } from "db://oops-framework/module/common/CCVMParentComp";
  13. import { GameEvent } from "../common/config/GameEvent";
  14. import { UIID } from "../common/config/GameUIConfig";
  15. import { ServerHandler } from "../common/manager/ServerHandler";
  16. import List from "../ui/List";
  17. import { RedPackeItemView } from "./RedPackeItemView";
  18. import { smc } from "../common/SingletonModuleComp";
  19. import { Format } from "../utils/Format";
  20. import { DCHandler } from "../common/manager/DCHandler";
  21. const { ccclass, property } = _decorator;
  22. /** 视图层对象 */
  23. @ccclass('RedPackeWithdrawalViewComp')
  24. @ecs.register(`RedPackeWithdrawalViewComp`, false)
  25. export class RedPackeWithdrawalViewComp extends CCVMParentComp {
  26. @property(List)
  27. recordList: List = null!;
  28. @property(Label)
  29. lab_tips: Label = null!;
  30. data: any = {
  31. tasklist: [],
  32. wxCash: 0,
  33. hbCoin: 0,
  34. goldNum: 0
  35. };
  36. start() {
  37. this.setButton();
  38. this.addEvent();
  39. DCHandler.inst.reportData(3000900);
  40. this.data.taskList = smc.game.GameModel.taskList;
  41. this.data.wxCash = smc.game.GameModel.wxCash;
  42. this.data.hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin);
  43. this.data.goldNum = smc.account.AccountModel.goldCoin;
  44. if (this.data.taskList.length > 0) {
  45. this.recordList.numItems = this.data.taskList.length;
  46. }
  47. this.lab_tips.string = `当前收集金砖${this.data.goldNum}块,红包10000元=人民币1元`;
  48. }
  49. addEvent() {
  50. oops.message.on(GameEvent.updateRedPackeTaskList, this.updateList, this);
  51. oops.message.on(GameEvent.updateHbAndWxCoin, this.updateCoin, this);
  52. }
  53. private onListRender(item: Node, idx: number) {
  54. const itemView: RedPackeItemView | null = item.getComponent(RedPackeItemView);
  55. if (itemView) {
  56. itemView.setItem(this.data.taskList[idx], idx);
  57. }
  58. }
  59. updateList() {
  60. // console.log("更新提现记录信息", this.data.wxCash);
  61. this.data.taskList = smc.game.GameModel.taskList;
  62. this.data.wxCash = smc.game.GameModel.wxCash;
  63. this.data.hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin);
  64. this.data.goldNum = smc.account.AccountModel.goldCoin;
  65. this.recordList.numItems = 0;
  66. if (this.data.taskList.length > 0) {
  67. this.recordList.numItems = this.data.taskList.length;
  68. }
  69. this.lab_tips.string = `当前收集金砖${this.data.goldNum}块,红包10000元=人民币1元`;
  70. oops.gui.toast("领取成功");
  71. }
  72. updateCoin() {
  73. console.log("更新红包币和微信币", smc.account.AccountModel.hbCoin, smc.game.GameModel.wxCash);
  74. this.data.wxCash = smc.game.GameModel.wxCash;
  75. this.data.hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin);
  76. //可以提现的那个金额币
  77. }
  78. private btn_back() {
  79. oops.gui.remove(UIID.RedPacketWithdraw);
  80. oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
  81. DCHandler.inst.reportData(3000901);
  82. }
  83. private btn_record() {
  84. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  85. ServerHandler.inst.getRecordList();
  86. DCHandler.inst.reportData(3000902);
  87. } else {
  88. oops.gui.open(UIID.WithdrawRecord);
  89. }
  90. }
  91. private async btn_withdrawal() {
  92. //全部提现
  93. if (this.data.wxCash > 0.1) {
  94. ServerHandler.inst.HbReward();
  95. DCHandler.inst.reportData(3000900, 1001);
  96. } else {
  97. oops.gui.toast("微信官方限制大于0.1元,才能提现~");
  98. DCHandler.inst.reportData(3000900, 1002);
  99. }
  100. }
  101. /** 视图对象通过 ecs.Entity.remove(WechatWithdrawalViewComp) 删除组件是触发组件处理自定义释放逻辑 */
  102. reset() {
  103. this.node.destroy();
  104. }
  105. formatNumber(num: number) {
  106. return Math.round(num * 100) / 100;
  107. }
  108. }