Withdraw.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { _decorator, Component, Node, Prefab, instantiate, UITransform, Label, RichText } from 'cc';
  2. import InfiniteCell from '../core/InfiniteList/InfiniteCell';
  3. import { IFDataSource, InfiniteList } from '../core/InfiniteList/InfiniteList';
  4. import { Http } from '../core/net/Http';
  5. import { BitmapFont } from '../core/ui/BitmapFont';
  6. import { WindowManager } from '../core/ui/window/WindowManager';
  7. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  8. import { ConfigData } from '../Data/ConfigData';
  9. import { g } from '../Data/g';
  10. import { ButtonState, WithdrawItem } from './WithdrawItem';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('Withdraw')
  13. export class Withdraw extends Component implements IFDataSource {
  14. @property({ type: Prefab, tooltip: "List子节点预制体" })
  15. public itemPrefab = null;
  16. @property({ type: Node, tooltip: "List节点" })
  17. public list: Node = null;
  18. @property({ type: Http, tooltip: "网络组件" })
  19. public http: Http = null;
  20. @property({ type: BitmapFont, tooltip: "红包数量文本" })
  21. public redBagNum: BitmapFont = null;
  22. @property({ type: Label, tooltip: "预估金额文本" })
  23. public estimateMoney: Label = null;
  24. //子项高度
  25. private itemHeight = null;
  26. private infiniteList: InfiniteList;
  27. private configArr: Array<any>;
  28. private bonusNum = 0;
  29. private geted = null;
  30. async start() {
  31. let prefab = instantiate(this.itemPrefab);
  32. this.itemHeight = prefab.getComponent(UITransform).height;
  33. prefab.destroy();
  34. this.configArr = ConfigData.configMap.get("withdraw");
  35. //获取提现记录
  36. this.geted = await this.queryRecord();
  37. this.infiniteList = this.list.getComponent(InfiniteList);
  38. this.infiniteList.Init(this);
  39. }
  40. /**
  41. * 查询已提现子项
  42. */
  43. async queryRecord() {
  44. let result = await this.http.send("/api/user/getWithdrawNote");
  45. return result;
  46. }
  47. GetCellNumber(): number {
  48. return this.configArr.length;
  49. }
  50. GetCellIdentifer(dataIndex: number): string {
  51. return "WithdrawItem";
  52. }
  53. GetCellSize(dataIndex: number): number {
  54. return this.itemHeight;
  55. }
  56. GetCellView(dataIndex: number, identifier?: string): InfiniteCell {
  57. let prefab = instantiate(this.itemPrefab);
  58. return prefab.getComponent(WithdrawItem);
  59. }
  60. GetCellData?(dataIndex: number) {
  61. //获取服务器数据中最大挡位下标
  62. let maxIndex: number = Number(Object.keys(this.geted.data).pop());
  63. maxIndex = !Number.isNaN(maxIndex) ? maxIndex : -1;
  64. if (dataIndex <= maxIndex) {
  65. if (this.geted.cashCodes[dataIndex] && this.geted.cashCodes[dataIndex] != "") {
  66. this.configArr[dataIndex].state = ButtonState.exchange;
  67. this.configArr[dataIndex].cashCode = this.geted.cashCodes[dataIndex];
  68. } else {
  69. this.configArr[dataIndex].state = ButtonState.geted;
  70. }
  71. } else if (dataIndex == (maxIndex + 1)) {//当前是可领取位
  72. //判断是否到达目标
  73. if (g.userData.bonus >= this.configArr[dataIndex].needBonus) {
  74. this.configArr[dataIndex].state = ButtonState.canget;
  75. } else {
  76. this.configArr[dataIndex].state = ButtonState.unget;
  77. }
  78. } else {
  79. this.configArr[dataIndex].state = ButtonState.unget;
  80. }
  81. return this.configArr[dataIndex];
  82. }
  83. async update() {
  84. if (this.bonusNum != g.userData.bonus) {
  85. this.bonusNum = g.userData.bonus;
  86. this.redBagNum.string = this.bonusNum + "";
  87. // this.estimateMoney.string = `${(this.bonusNum / 10000).toFixed(2)}`;
  88. this.estimateMoney.string = g.userData.bonus / 10000 + "";
  89. this.geted = await this.queryRecord();
  90. this.infiniteList.Reload();
  91. }
  92. }
  93. public close(): void {
  94. }
  95. onDestroy() {
  96. if (!g.userData.noviceReceived) {
  97. WindowManager.open("Prefabs/NewRewardWindow/NewRewardWindow_0", WindowOpenMode.NotCloseAndAdd);
  98. g.userData.noviceReceived = true;
  99. }
  100. }
  101. }