GemRechargeLayer.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { _decorator, Component, Node } from "cc";
  2. import BaseUI from "../../scripts/base/BaseUI";
  3. import { Hall } from "../hall/Hall";
  4. import { instantiate } from "cc";
  5. import { DiamondRechargeItem } from "../item/DiamondRechargeLayerItem";
  6. import RechargeM, { RechargeDto } from "../../scripts/api/RechargeM";
  7. import { Event } from "cc";
  8. import UserM from "../../scripts/api/UserM";
  9. import { GoodsId } from "../../scripts/api/GoodsId";
  10. import Utils from "../../scripts/utils/Utils";
  11. import EV, { EV_TYPE } from "../../scripts/mgr/EV";
  12. const { ccclass, property } = _decorator;
  13. @ccclass("GemRechargeLayer")
  14. export class GemRechargeLayer extends BaseUI {
  15. static async show() {
  16. let layer = await Hall.ins.showLayer("prefab/layer/GemRechargeLayer");
  17. layer.getComponent(GemRechargeLayer).init();
  18. }
  19. protected onLoad(): void {
  20. super.onLoad();
  21. EV.ins.on(EV_TYPE.USER_GOOD_REFRESH, this.refreshGemValue, this);
  22. }
  23. private refreshGemValue() {
  24. this.setText(
  25. "lbl_gem_balance",
  26. Utils.formatNumber(UserM.ins.getGoodsCount(GoodsId.GEM), 0)
  27. );
  28. }
  29. async init() {
  30. this.refreshGemValue();
  31. let content = this.FindNode("content");
  32. let tpl = content.children[0];
  33. tpl.active = false;
  34. let list = await this.getDataList();
  35. for (let i = 0; i < list.length; i++) {
  36. let item = instantiate(tpl);
  37. item.parent = content;
  38. item.active = true;
  39. item.getComponent(DiamondRechargeItem).init(list[i]);
  40. }
  41. }
  42. async getDataList(): Promise<RechargeDto[]> {
  43. let result = await RechargeM.ins.getRechargeList();
  44. // result.push(...(await RechargeM.ins.getRechargeList()));
  45. return result;
  46. }
  47. protected onBtnClick(name: string, event: Event, customEventData: any): void {
  48. super.onBtnClick(name, event, customEventData);
  49. switch (name) {
  50. }
  51. }
  52. }