import { _decorator, Component, Node, Prefab, instantiate, UITransform, Label, RichText } from 'cc'; import InfiniteCell from '../core/InfiniteList/InfiniteCell'; import { IFDataSource, InfiniteList } from '../core/InfiniteList/InfiniteList'; import { Http } from '../core/net/Http'; import { BitmapFont } from '../core/ui/BitmapFont'; import { WindowManager } from '../core/ui/window/WindowManager'; import { WindowOpenMode } from '../core/ui/window/WindowOpenMode'; import { ConfigData } from '../Data/ConfigData'; import { g } from '../Data/g'; import { ButtonState, WithdrawItem } from './WithdrawItem'; const { ccclass, property } = _decorator; @ccclass('Withdraw') export class Withdraw extends Component implements IFDataSource { @property({ type: Prefab, tooltip: "List子节点预制体" }) public itemPrefab = null; @property({ type: Node, tooltip: "List节点" }) public list: Node = null; @property({ type: Http, tooltip: "网络组件" }) public http: Http = null; @property({ type: BitmapFont, tooltip: "红包数量文本" }) public redBagNum: BitmapFont = null; @property({ type: Label, tooltip: "预估金额文本" }) public estimateMoney: Label = null; //子项高度 private itemHeight = null; private infiniteList: InfiniteList; private configArr: Array; private bonusNum = 0; private geted = null; async start() { let prefab = instantiate(this.itemPrefab); this.itemHeight = prefab.getComponent(UITransform).height; prefab.destroy(); this.configArr = ConfigData.configMap.get("withdraw"); //获取提现记录 this.geted = await this.queryRecord(); this.infiniteList = this.list.getComponent(InfiniteList); this.infiniteList.Init(this); } /** * 查询已提现子项 */ async queryRecord() { let result = await this.http.send("/api/user/getWithdrawNote"); return result; } GetCellNumber(): number { return this.configArr.length; } GetCellIdentifer(dataIndex: number): string { return "WithdrawItem"; } GetCellSize(dataIndex: number): number { return this.itemHeight; } GetCellView(dataIndex: number, identifier?: string): InfiniteCell { let prefab = instantiate(this.itemPrefab); return prefab.getComponent(WithdrawItem); } GetCellData?(dataIndex: number) { //获取服务器数据中最大挡位下标 let maxIndex: number = Number(Object.keys(this.geted.data).pop()); maxIndex = !Number.isNaN(maxIndex) ? maxIndex : -1; if (dataIndex <= maxIndex) { if (this.geted.cashCodes[dataIndex] && this.geted.cashCodes[dataIndex] != "") { this.configArr[dataIndex].state = ButtonState.exchange; this.configArr[dataIndex].cashCode = this.geted.cashCodes[dataIndex]; } else { this.configArr[dataIndex].state = ButtonState.geted; } } else if (dataIndex == (maxIndex + 1)) {//当前是可领取位 //判断是否到达目标 if (g.userData.bonus >= this.configArr[dataIndex].needBonus) { this.configArr[dataIndex].state = ButtonState.canget; } else { this.configArr[dataIndex].state = ButtonState.unget; } } else { this.configArr[dataIndex].state = ButtonState.unget; } return this.configArr[dataIndex]; } async update() { if (this.bonusNum != g.userData.bonus) { this.bonusNum = g.userData.bonus; this.redBagNum.string = this.bonusNum + ""; // this.estimateMoney.string = `${(this.bonusNum / 10000).toFixed(2)}`; this.estimateMoney.string = g.userData.bonus / 10000 + ""; this.geted = await this.queryRecord(); this.infiniteList.Reload(); } } public close(): void { } onDestroy() { if (!g.userData.noviceReceived) { WindowManager.open("Prefabs/NewRewardWindow/NewRewardWindow_0", WindowOpenMode.NotCloseAndAdd); g.userData.noviceReceived = true; } } }