GemRechargeLayer.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. import { HistoryRecharge } from "./HistoryRecharge";
  13. const { ccclass, property } = _decorator;
  14. @ccclass("GemRechargeLayer")
  15. export class GemRechargeLayer extends BaseUI {
  16. static async show() {
  17. let layer = await Hall.ins.showLayer("prefab/layer/GemRechargeLayer");
  18. layer.getComponent(GemRechargeLayer).init();
  19. }
  20. protected onLoad(): void {
  21. super.onLoad();
  22. EV.ins.on(EV_TYPE.USER_GOOD_REFRESH, this.refreshGemValue, this);
  23. }
  24. private refreshGemValue() {
  25. this.setText(
  26. "lbl_gem_balance",
  27. Utils.formatNumber(UserM.ins.getGoodsCount(GoodsId.GEM), 0)
  28. );
  29. }
  30. async init() {
  31. this.refreshGemValue();
  32. let content = this.FindNode("content");
  33. let tpl = content.children[0];
  34. tpl.active = false;
  35. let list = await this.getDataList();
  36. for (let i = 0; i < list.length; i++) {
  37. let item = instantiate(tpl);
  38. item.parent = content;
  39. item.active = true;
  40. item.getComponent(DiamondRechargeItem).init(list[i]);
  41. }
  42. }
  43. async getDataList(): Promise<RechargeDto[]> {
  44. let result = await RechargeM.ins.getRechargeList();
  45. // result.push(...(await RechargeM.ins.getRechargeList()));
  46. return result;
  47. }
  48. protected simpleOnBtnClick(name: string): void {
  49. switch (name) {
  50. case "btn_history":
  51. HistoryRecharge.show();
  52. break;
  53. }
  54. }
  55. }