RedPackeWithdrawalViewComp.ts 4.2 KB

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