WithdrawalRecordViewComp.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-03-21 10:17:49
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-04-22 16:58:49
  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 { CCComp } from "db://oops-framework/module/common/CCComp";
  13. import { UIID } from "../common/config/GameUIConfig";
  14. import { smc } from "../common/SingletonModuleComp";
  15. import List from "../ui/List";
  16. import { Format } from "../utils/Format";
  17. const { ccclass, property } = _decorator;
  18. /** 视图层对象 */
  19. @ccclass('WithdrawalRecordViewComp')
  20. @ecs.register('WithdrawalRecordView', false)
  21. export class WithdrawalRecordViewComp extends CCComp {
  22. /** 视图层逻辑代码分离演示 */
  23. @property(List)
  24. recordList: List = null!;
  25. data: any[] = [];
  26. @property(Node)
  27. noRecord: Node = null!;
  28. @property(Node)
  29. content: Node = null!;
  30. start() {
  31. this.setButton();
  32. // const entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
  33. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  34. const count = smc.game.GameModel.recordList.length;
  35. this.noRecord.active = count <= 0;
  36. this.content.active = count > 0;
  37. if (count > 0) {
  38. this.data = smc.game.GameModel.recordList;
  39. this.recordList.numItems = this.data.length;
  40. }
  41. } else {
  42. const data = {
  43. amount: 0.01,
  44. payMethod: 1, //1支付宝 2微信
  45. createTime: "2025-04-09 18:09:09",
  46. successTime: "2025-04-09 18:09:09",
  47. status: oops.random.getRandomInt(0, 4)
  48. }
  49. for (let i = 0; i < 20; i++) {
  50. data.amount = i;
  51. this.data.push(data);
  52. }
  53. this.recordList.numItems = this.data.length;
  54. }
  55. }
  56. // 列表渲染器
  57. private onListRender(item: Node, idx: number) {
  58. // item.getComponentInChildren(Label)!.string = this.data[idx] + '';
  59. const data = this.data[idx];
  60. let str: string = ""
  61. switch (data.status) {
  62. case 1:
  63. str = "待审核"
  64. break;
  65. case 2:
  66. str = "提现成功"
  67. break
  68. case 3:
  69. str = "提现失败"
  70. break
  71. case 4:
  72. str = "已拒绝"
  73. break
  74. case 5:
  75. str = ""
  76. break
  77. }
  78. const stateLabel = item.getChildByName("lab_state")?.getComponent(Label);
  79. if (stateLabel) stateLabel.string = str;
  80. const timeLabel = item.getChildByName("lab_time")?.getComponent(Label);
  81. if (timeLabel) timeLabel.string = data.createTime;
  82. const moneyLabel = item.getChildByPath("moneyNode/lab_money")?.getComponent(Label);
  83. if (moneyLabel) moneyLabel.string = Format.formatRedPacketCoin(data.amount);
  84. //TS原生随机数0 或者1
  85. const statusNode1 = item.getChildByName("record_state1");
  86. if (statusNode1) statusNode1.active = data.status == 2;
  87. const statusNode2 = item.getChildByName("record_state2");
  88. if (statusNode2) statusNode2.active = data.status != 2;
  89. }
  90. private btn_back() {
  91. oops.gui.remove(UIID.WithdrawRecord)
  92. }
  93. /** 视图对象通过 ecs.Entity.remove(WithdrawalRecordViewComp) 删除组件是触发组件处理自定义释放逻辑 */
  94. reset() {
  95. this.node.destroy();
  96. }
  97. private btn_play() {
  98. if (oops.gui.has(UIID.WithdrawRecord)) {
  99. oops.gui.remove(UIID.WithdrawRecord)
  100. }
  101. if (oops.gui.has(UIID.RedPacketWithdraw)) {
  102. oops.gui.remove(UIID.RedPacketWithdraw)
  103. }
  104. }
  105. //保留两位小数
  106. formatNumber(num: number) {
  107. return Math.round(num * 100) / 100;
  108. }
  109. }