RedPackeWithdrawalViewComp.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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-21 16:30:05
  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. const { ccclass, property } = _decorator;
  21. /** 视图层对象 */
  22. @ccclass('RedPackeWithdrawalViewComp')
  23. @ecs.register(`RedPackeWithdrawalViewComp`, false)
  24. export class RedPackeWithdrawalViewComp extends CCVMParentComp {
  25. @property(List)
  26. recordList: List = null!;
  27. @property(Label)
  28. lab_tips: Label = null!;
  29. data: any = {
  30. tasklist: [],
  31. wxCash: 0,
  32. hbCoin: 0,
  33. goldNum: 0
  34. };
  35. start() {
  36. this.setButton();
  37. this.addEvent();
  38. // const data = {
  39. // title: `每日消除100次即可领取`,
  40. // current: 1,
  41. // total: 100,
  42. // state: 0,
  43. // goods: [
  44. // {
  45. // type: 1001,
  46. // num: 100
  47. // }
  48. // ]
  49. // }
  50. // for (let i = 0; i < 10; i++) {
  51. // this.data.push(data);
  52. // }
  53. // oops.log.logView(this.data, "this.data");
  54. // this.recordList.numItems = this.data.length;
  55. // oops.log.logView(this.recordList.numItems, "this.recordList.numItems");
  56. // this
  57. this.data.taskList = smc.game.GameModel.taskList;
  58. this.data.wxCash = smc.game.GameModel.wxCash;
  59. this.data.hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin);
  60. this.data.goldNum = smc.account.AccountModel.goldCoin;
  61. if (this.data.taskList.length > 0) {
  62. this.recordList.numItems = this.data.taskList.length;
  63. }
  64. this.lab_tips.string = `当前收集金砖${this.data.goldNum}块,红包10000元=人民币1元`;
  65. }
  66. addEvent() {
  67. oops.message.on(GameEvent.updateRedPackeTaskList, this.updateList, this);
  68. oops.message.on(GameEvent.updateHbAndWxCoin, this.updateCoin, this);
  69. }
  70. private onListRender(item: Node, idx: number) {
  71. const itemView: RedPackeItemView | null = item.getComponent(RedPackeItemView);
  72. if (itemView) {
  73. itemView.setItem(this.data.taskList[idx], idx);
  74. }
  75. }
  76. updateList() {
  77. // console.log("更新提现记录信息", this.data.wxCash);
  78. this.data.taskList = smc.game.GameModel.taskList;
  79. this.data.wxCash = Format.formatWxCoin(smc.game.GameModel.wxCash);
  80. this.data.hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin);
  81. this.data.goldNum = smc.account.AccountModel.goldCoin;
  82. this.recordList.numItems = 0;
  83. if (this.data.taskList.length > 0) {
  84. this.recordList.numItems = this.data.taskList.length;
  85. }
  86. this.lab_tips.string = `当前收集金砖${this.data.goldNum}块,红包10000元=人民币1元`;
  87. oops.gui.toast("领取成功");
  88. }
  89. updateCoin() {
  90. this.data.wxCash = Format.formatWxCoin(smc.game.GameModel.wxCash);
  91. this.data.hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin);
  92. }
  93. private btn_back() {
  94. oops.gui.remove(UIID.RedPacketWithdraw);
  95. oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
  96. }
  97. private btn_record() {
  98. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  99. ServerHandler.inst.getRecordList();
  100. } else {
  101. oops.gui.open(UIID.WithdrawRecord);
  102. }
  103. }
  104. private btn_withdrawal() {
  105. //全部提现
  106. if (this.data.wxCash > 0.1) {
  107. //红包提现
  108. ServerHandler.inst.HbReward();
  109. } else {
  110. oops.gui.toast("微信官方限制大于0.1元,才能提现~");
  111. }
  112. }
  113. /** 视图对象通过 ecs.Entity.remove(WechatWithdrawalViewComp) 删除组件是触发组件处理自定义释放逻辑 */
  114. reset() {
  115. this.node.destroy();
  116. }
  117. formatNumber(num: number) {
  118. return Math.round(num * 100) / 100;
  119. }
  120. }