RedPackeWithdrawalViewComp.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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-24 17:21:52
  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. const hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin);
  64. this.data.hbCoin = Number(hbCoin);
  65. this.data.goldNum = smc.account.AccountModel.goldCoin;
  66. this.recordList.numItems = 0;
  67. if (this.data.taskList.length > 0) {
  68. this.recordList.numItems = this.data.taskList.length;
  69. }
  70. this.lab_tips.string = `当前收集金砖${this.data.goldNum}块,红包10000元=人民币1元`;
  71. oops.gui.toast("领取成功");
  72. }
  73. updateCoin() {
  74. this.data.wxCash = smc.game.GameModel.wxCash;
  75. console.log("111111111111111111111")
  76. const hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin);
  77. console.log("22222222222222222")
  78. this.data.hbCoin = Number(hbCoin);
  79. }
  80. private btn_back() {
  81. oops.gui.remove(UIID.RedPacketWithdraw);
  82. oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
  83. DCHandler.inst.reportData(3000901);
  84. }
  85. private btn_record() {
  86. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  87. ServerHandler.inst.getRecordList();
  88. DCHandler.inst.reportData(3000902);
  89. } else {
  90. oops.gui.open(UIID.WithdrawRecord);
  91. }
  92. }
  93. private async btn_withdrawal() {
  94. //全部提现
  95. if (this.data.wxCash >= 0.1) {
  96. ServerHandler.inst.HbReward();
  97. DCHandler.inst.reportData(3000900, 1001);
  98. } else {
  99. oops.gui.toast("微信官方限制大于0.1元,才能提现~");
  100. DCHandler.inst.reportData(3000900, 1002);
  101. }
  102. }
  103. /** 视图对象通过 ecs.Entity.remove(WechatWithdrawalViewComp) 删除组件是触发组件处理自定义释放逻辑 */
  104. reset() {
  105. this.node.destroy();
  106. }
  107. formatNumber(num: number) {
  108. return Math.round(num * 100) / 100;
  109. }
  110. }