| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import { _decorator, Component, Node, Label, ProgressBar, Prefab, instantiate, UITransform } from 'cc';
- import { IFDataSource, InfiniteList } from '../../core/InfiniteList/InfiniteList';
- import { Http } from '../../core/net/Http';
- import { WindowManager } from '../../core/ui/window/WindowManager';
- import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
- import { Utils } from '../../core/utils/Utils';
- import { g } from '../../Data/g';
- import { platform } from '../../Data/platform';
- import { GetType } from '../GetWindow/GetType';
- import { NewRewardItem } from './NewRewardItem';
- const { ccclass, property } = _decorator;
- @ccclass('NewRewardWindow3')
- export class NewRewardWindow3 extends Component implements IFDataSource {
- public static needReLoad = false;
- @property({ type: Label, tooltip: "差值文本" }) lerpLabel: Label;
- @property({ type: Label, tooltip: "倒计时文本" }) countLabel: Label;
- @property({ type: ProgressBar, tooltip: "总进度" }) progress: ProgressBar;
- @property({ type: InfiniteList, tooltip: "列表组件" }) list: InfiniteList;
- @property({ type: Prefab, tooltip: "列表cell预制体" }) cell: Prefab;
- @property({ type: Http, tooltip: "Http组件" }) http: Http;
- private prefabHeight: number;
- private listData = [];
- async start() {
- let prefab = instantiate(this.cell);
- this.prefabHeight = prefab.getComponent(UITransform).height;
- prefab.destroy();
- this.list.Init(this);
- this.reload();
- }
- private async reload() {
- this.listData = [];
- let result = await this.http.send("/api/threeDayTask/threeDayTaskList");
- if (result.code == 0) {
- this.lerpLabel.string = `仅差${(result.data.active.maxValue - result.data.active.value).toFixed(2)}元`
- this.progress.progress = result.data.active.value / result.data.active.maxValue;
- let f = []; let n = []; let get = [];
- for (let i = 0; i < result.data.taskList.length; i++) {
- let obj = {
- id: result.data.taskList[i].id,
- name: result.data.taskList[i].name,
- num: result.data.taskList[i].num,
- progress: result.data.taskList[i].progress,
- state: null
- }
- if (obj.num == obj.progress) {
- obj.state = 2;
- f.push(obj)
- } else if (obj.num > obj.progress) {
- obj.state = 0;
- n.push(obj);
- } else if (obj.num < obj.progress) {
- obj.state = 1;
- get.push(obj);
- }
- }
- this.listData = this.listData.concat(f).concat(n).concat(get);
- if (result.data.active.value == result.data.active.maxValue) {
- if (Date.now() < g.gameData.threedayTaskTime * 1000) {
- let r = await this.http.send("/api/threeDayTask/threeDayActiveBoxReceive");
- if (r.code == 0) {
- platform.umUp("time-limitedTask");//完成限时任务埋点
- 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" }));
- WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: r.data.bonus, type: GetType.RedBag, needBezierEffect: true, particCount: 30 }], this.node);
- }
- }
- }
- }
- this.list.Reload();
- }
- update() {
- if (Date.now() < g.gameData.threedayTaskTime * 1000) {
- this.countLabel.string = Utils.formatCountDown(g.gameData.threedayTaskTime * 1000 - Date.now(), false);
- } else {
- this.countLabel.string = "已失效";
- }
- if (NewRewardWindow3.needReLoad) {
- NewRewardWindow3.needReLoad = false;
- this.reload();
- }
- }
- //#region IFDataSource
- public GetCellData(dataIndex: number): any {
- return this.listData[dataIndex];
- }
- public GetCellNumber(): number {
- return this.listData.length;
- }
- public GetCellSize(index: number): number {
- return this.prefabHeight ? this.prefabHeight : 100;
- }
- public GetCellView(index: number): NewRewardItem {
- let node = instantiate(this.cell);
- return node.getComponent(NewRewardItem);
- }
- public GetCellIdentifer(index: number): string {
- return "NewRewardItem";
- }
- //#endregion
- }
|