RedPackeWithdrawalViewComp.ts 5.0 KB

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