RedPackeWithdrawalViewComp.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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-28 14:50:50
  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. @property(Label)
  31. lab_hbCoin: Label = null!;
  32. @property(Label)
  33. lab_wxCash: Label = null!;
  34. data: any = {
  35. tasklist: [],
  36. goldNum: 0,
  37. wxCash: 0,
  38. hbCoin: 0
  39. };
  40. start() {
  41. this.setButton();
  42. this.addEvent();
  43. DCHandler.inst.reportData(3000900);
  44. this.data.taskList = smc.game.GameModel.taskList;
  45. let wxCash = smc.game.GameModel.wxCash;
  46. let hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin);
  47. this.data.wxCash = wxCash;
  48. this.data.hbCoin = hbCoin;
  49. this.data.goldNum = smc.account.AccountModel.goldCoin;
  50. if (this.data.taskList.length > 0) {
  51. this.recordList.numItems = this.data.taskList.length;
  52. }
  53. // this.lab_tips.string = `当前收集金砖${this.data.goldNum}块,红包10000元=人民币1元`;
  54. }
  55. addEvent() {
  56. oops.message.on(GameEvent.updateRedPackeTaskList, this.updateList, this);
  57. oops.message.on(GameEvent.updateHbAndWxCoin, this.updateCoin, this);
  58. }
  59. private onListRender(item: Node, idx: number) {
  60. const itemView: RedPackeItemView | null = item.getComponent(RedPackeItemView);
  61. if (itemView) {
  62. itemView.setItem(this.data.taskList[idx], idx);
  63. }
  64. }
  65. updateList() {
  66. this.data.taskList = smc.game.GameModel.taskList;
  67. let wxCash = smc.game.GameModel.wxCash;
  68. let hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin);
  69. // this.lab_wxCash.string = `${wxCash}`;
  70. // this.lab_hbCoin.string = `${hbCoin}`;
  71. this.data.wxCash = wxCash;
  72. this.data.hbCoin = hbCoin;
  73. this.data.goldNum = smc.account.AccountModel.goldCoin;
  74. this.recordList.numItems = 0;
  75. if (this.data.taskList.length > 0) {
  76. this.recordList.numItems = this.data.taskList.length;
  77. }
  78. // this.lab_tips.string = `当前收集金砖${this.data.goldNum}块,红包10000元=人民币1元`;
  79. oops.gui.toast("领取成功");
  80. }
  81. updateCoin() {
  82. console.log("更新红包币和微信币")
  83. let wxCash = smc.game.GameModel.wxCash;
  84. console.log("wxCash", wxCash);
  85. let hbCoin = Format.formatRedPacketCoin(smc.account.AccountModel.hbCoin);
  86. console.log("hbCoin", hbCoin);
  87. this.data.wxCash = wxCash;
  88. this.data.hbCoin = hbCoin;
  89. }
  90. private btn_back() {
  91. oops.gui.remove(UIID.RedPacketWithdraw);
  92. oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
  93. DCHandler.inst.reportData(3000901);
  94. }
  95. private btn_record() {
  96. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  97. ServerHandler.inst.getRecordList();
  98. DCHandler.inst.reportData(3000902);
  99. } else {
  100. oops.gui.open(UIID.WithdrawRecord);
  101. }
  102. }
  103. private async btn_withdrawal() {
  104. //全部提现
  105. if (smc.game.GameModel.wxCash >= 0.1) {
  106. ServerHandler.inst.HbReward();
  107. DCHandler.inst.reportData(3000903, 1001);
  108. } else {
  109. oops.gui.toast("微信官方限制大于0.1元,才能提现~");
  110. DCHandler.inst.reportData(3000903, 1002);
  111. }
  112. }
  113. /** 视图对象通过 ecs.Entity.remove(WechatWithdrawalViewComp) 删除组件是触发组件处理自定义释放逻辑 */
  114. reset() {
  115. this.node.destroy();
  116. }
  117. protected onDestroy(): void {
  118. oops.message.off(GameEvent.updateRedPackeTaskList, this.updateList, this);
  119. oops.message.off(GameEvent.updateHbAndWxCoin, this.updateCoin, this);
  120. }
  121. btn_text() {
  122. const info = { "ssid": "0cee6baebcb1413180e266d733510e38", "props": { "1007": 60, "9001": 5, "1005": 1889260, "1004": 5137068, "8001": 550, "1006": 9, "2001": 11, "1008": 30 }, "changes": { "8001": 500, "1004": -5000000 }, "money": 5.13, "transferStatus": 1, "outTransferNo": "2504281114186442061262848" }
  123. ServerHandler.inst.onHbReward(JSON.stringify(info));
  124. }
  125. }