NewRewardWindow_3.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { _decorator, Component, Node, Label, ProgressBar, Prefab, instantiate, UITransform } from 'cc';
  2. import { IFDataSource, InfiniteList } from '../../core/InfiniteList/InfiniteList';
  3. import { Http } from '../../core/net/Http';
  4. import { WindowManager } from '../../core/ui/window/WindowManager';
  5. import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
  6. import { Utils } from '../../core/utils/Utils';
  7. import { g } from '../../Data/g';
  8. import { platform } from '../../Data/platform';
  9. import { GetType } from '../GetWindow/GetType';
  10. import { NewRewardItem } from './NewRewardItem';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('NewRewardWindow3')
  13. export class NewRewardWindow3 extends Component implements IFDataSource {
  14. public static needReLoad = false;
  15. @property({ type: Label, tooltip: "差值文本" }) lerpLabel: Label;
  16. @property({ type: Label, tooltip: "倒计时文本" }) countLabel: Label;
  17. @property({ type: ProgressBar, tooltip: "总进度" }) progress: ProgressBar;
  18. @property({ type: InfiniteList, tooltip: "列表组件" }) list: InfiniteList;
  19. @property({ type: Prefab, tooltip: "列表cell预制体" }) cell: Prefab;
  20. @property({ type: Http, tooltip: "Http组件" }) http: Http;
  21. private prefabHeight: number;
  22. private listData = [];
  23. async start() {
  24. let prefab = instantiate(this.cell);
  25. this.prefabHeight = prefab.getComponent(UITransform).height;
  26. prefab.destroy();
  27. this.list.Init(this);
  28. this.reload();
  29. }
  30. private async reload() {
  31. this.listData = [];
  32. let result = await this.http.send("/api/threeDayTask/threeDayTaskList");
  33. if (result.code == 0) {
  34. this.lerpLabel.string = `仅差${(result.data.active.maxValue - result.data.active.value).toFixed(2)}元`
  35. this.progress.progress = result.data.active.value / result.data.active.maxValue;
  36. let f = []; let n = []; let get = [];
  37. for (let i = 0; i < result.data.taskList.length; i++) {
  38. let obj = {
  39. id: result.data.taskList[i].id,
  40. name: result.data.taskList[i].name,
  41. num: result.data.taskList[i].num,
  42. progress: result.data.taskList[i].progress,
  43. state: null
  44. }
  45. if (obj.num == obj.progress) {
  46. obj.state = 2;
  47. f.push(obj)
  48. } else if (obj.num > obj.progress) {
  49. obj.state = 0;
  50. n.push(obj);
  51. } else if (obj.num < obj.progress) {
  52. obj.state = 1;
  53. get.push(obj);
  54. }
  55. }
  56. this.listData = this.listData.concat(f).concat(n).concat(get);
  57. if (result.data.active.value == result.data.active.maxValue) {
  58. if (Date.now() < g.gameData.threedayTaskTime * 1000) {
  59. let r = await this.http.send("/api/threeDayTask/threeDayActiveBoxReceive");
  60. if (r.code == 0) {
  61. platform.umUp("time-limitedTask");//完成限时任务埋点
  62. platform.reportThinking("envelope_increase", JSON.stringify({ previous_number: g.userData.bonus, increase_number: r.data.bonus, current_number: g.userData.bonus + r.data.bonus, reasons: "threeDayActiveBoxReceive" }));
  63. WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: r.data.bonus, type: GetType.RedBag, needBezierEffect: true, particCount: 30 }], this.node);
  64. }
  65. }
  66. }
  67. }
  68. this.list.Reload();
  69. }
  70. update() {
  71. if (Date.now() < g.gameData.threedayTaskTime * 1000) {
  72. this.countLabel.string = Utils.formatCountDown(g.gameData.threedayTaskTime * 1000 - Date.now(), false);
  73. } else {
  74. this.countLabel.string = "已失效";
  75. }
  76. if (NewRewardWindow3.needReLoad) {
  77. NewRewardWindow3.needReLoad = false;
  78. this.reload();
  79. }
  80. }
  81. //#region IFDataSource
  82. public GetCellData(dataIndex: number): any {
  83. return this.listData[dataIndex];
  84. }
  85. public GetCellNumber(): number {
  86. return this.listData.length;
  87. }
  88. public GetCellSize(index: number): number {
  89. return this.prefabHeight ? this.prefabHeight : 100;
  90. }
  91. public GetCellView(index: number): NewRewardItem {
  92. let node = instantiate(this.cell);
  93. return node.getComponent(NewRewardItem);
  94. }
  95. public GetCellIdentifer(index: number): string {
  96. return "NewRewardItem";
  97. }
  98. //#endregion
  99. }