UIFirstPack.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { checkResponse } from '@scripts/api/ApiHelper';
  2. import { AppKernel } from '@scripts/app/AppKernel';
  3. import { UIPopup } from '@scripts/framework/ui/UIPopup';
  4. import { IFirstPack } from '@scripts/store/payStore/data';
  5. import { formatGCNum, formatSCNum } from '@scripts/utils/Helper';
  6. import { addBtnClick } from '@scripts/utils/UIHelper';
  7. import { formatVipLv } from '@scripts/utils/VipHelper';
  8. import { _decorator, Button, Component, find, instantiate, Label, Node } from 'cc';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('UIFirstPack')
  11. export class UIFirstPack extends UIPopup {
  12. @property(Label)
  13. lblGC: Label;
  14. @property(Label)
  15. lblSC: Label;
  16. @property(Label)
  17. lblVIP: Label;
  18. @property(Label)
  19. lblButton: Label;
  20. @property(Button)
  21. btnClose: Button;
  22. @property(Button)
  23. btnPay: Button;
  24. @property(Node)
  25. btnDisabled: Node;
  26. @property(Label)
  27. lblDisabled: Label;
  28. @property(Node)
  29. testGears: Node;
  30. private _packInfo: IFirstPack;
  31. protected onCreate(): void | Promise<void> {
  32. addBtnClick(this.btnClose, this.closeSelf, this);
  33. addBtnClick(this.btnPay, this.onBtnPayClick, this);
  34. }
  35. protected async onBeforeOpen(_params: unknown) {
  36. const payStore = AppKernel.stores.payStore;
  37. const res = await payStore.reqFirstPackInfo();
  38. if (!checkResponse(res)) return false;
  39. this._packInfo = res.data;
  40. return !!res.data;
  41. }
  42. private onBtnPayClick() {
  43. }
  44. protected onOpen(_params: unknown): void | Promise<void> {
  45. const data = this._packInfo?.list?.[0];
  46. if (!this._packInfo || !data) {
  47. this.lblGC.string = "";
  48. this.lblSC.string = "";
  49. this.lblVIP.string = "";
  50. this.btnDisabled.active = true;
  51. return;
  52. }
  53. const gc = data.gc + data.gc_reward;
  54. const sc = data.sc + data.sc_reward;
  55. const cp = data.cp + data.cp_reward;
  56. this.lblGC.string = formatGCNum(gc);
  57. this.lblSC.string = formatSCNum(sc);
  58. this.lblVIP.string = cp.toString();
  59. const btn_str = AppKernel.i18n.t("store.buynow", Number(data.money));
  60. this.lblButton.string = btn_str;
  61. this.lblDisabled.string = btn_str;
  62. this.btnDisabled.active = data.purchased;
  63. //// Test
  64. if (!data.purchased) {
  65. for (let i = 0; i < data.gears.length; ++i) {
  66. const gearIdx = i;
  67. const gear = data.gears[i];
  68. const gearPrefab = find("Button", this.testGears);
  69. const gearItem = instantiate(gearPrefab);
  70. gearItem.parent = this.testGears;
  71. gearItem.active = true;
  72. const lblName = find("Label", gearItem).getComponent(Label);
  73. lblName.string = gear.name;
  74. addBtnClick(gearItem, () => {
  75. const payServices = AppKernel.services.paymentServices;
  76. payServices.startPayment(data, gearIdx);
  77. })
  78. }
  79. }
  80. }
  81. }