FamilyPageHas.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import { _decorator, Component, Node } from "cc";
  2. import BaseUI from "../../scripts/base/BaseUI";
  3. import { MemberManager } from "./MemberManager";
  4. import { InputNameLayer } from "./InputNameLayer";
  5. import EV, { EV_TYPE } from "../../scripts/mgr/EV";
  6. import AB from "../../scripts/base/AB";
  7. import { instantiate } from "cc";
  8. import { RankPlayerDto } from "../../scripts/api/RankM";
  9. import { RankPlayerItem } from "../item/RankPlayerItem";
  10. import { FamilyMemberItem } from "./FamilyMemberItem";
  11. import PayM from "../../scripts/mgr/PayM";
  12. import { Label } from "cc";
  13. import ShareM from "../../scripts/mgr/ShareM";
  14. import { Tips } from "../../scripts/mgr/Tips";
  15. import FamilyM, { FamilyInfo, FamilyMember } from "../../scripts/api/FamilyM";
  16. import UserM from "../../scripts/api/UserM";
  17. import Utils from "../../scripts/utils/Utils";
  18. import { TipsData, TipsLayer } from "../layer/TipsLayer";
  19. import { GoodsId } from "../../scripts/api/GoodsId";
  20. const { ccclass, property } = _decorator;
  21. @ccclass("FamilyPageHas")
  22. export class FamilyPageHas extends BaseUI {
  23. private _data: FamilyInfo;
  24. async editFamilyNotice() {
  25. let notice = await InputNameLayer.show(100);
  26. if (notice == null) {
  27. return;
  28. }
  29. let familyId = UserM.ins.getFamilyId();
  30. if (familyId == null || familyId.length == 0) {
  31. return;
  32. }
  33. let result = await FamilyM.ins.editFamilyNotice(familyId, notice);
  34. if (!result) {
  35. return;
  36. }
  37. Tips.show("Success");
  38. this.setText("lbl_my_family_notice", notice);
  39. }
  40. onShow() {
  41. this.staticUI()
  42. this.familyInfo();
  43. setTimeout(() => {
  44. this.showMembers();
  45. }, 1000);
  46. }
  47. staticUI() {
  48. this.setText("lbl_family_tips_member", Utils.setI18nLabel("Family.FamilyMemberBenefits"));
  49. this.setText("lbl_family_tips_owner", Utils.setI18nLabel("Family.FamilyOwnerBenefits"));
  50. }
  51. protected onLoad(): void {
  52. super.onLoad();
  53. this.FindNode("owner_manage_node").active = false;
  54. EV.ins.on(EV_TYPE.FAMILY_DATA_UPDATE, this.familyInfo, this);
  55. EV.ins.on(EV_TYPE.FAMILY_MEMBER_UPDATE, this.showMembers, this);
  56. }
  57. async familyUI() {
  58. let result = this._data;
  59. this.setText(
  60. "lbl_family_pog",
  61. Utils.formatNumber(Number(result.dailyPog), 1)
  62. );
  63. this.setText("lbl_family_exp", Utils.formatNumber(Number(result.xp), 1));
  64. this.setText(
  65. "lbl_family_game_pass_count",
  66. Utils.formatNumber(Number(result.seasonPassGame), 0)
  67. );
  68. this.setText(
  69. "lbl_people_count",
  70. `${result.memberSize}/${result.totalSize}`
  71. );
  72. this.setText("lbl_my_family_name", result.familyName);
  73. this.setText("lbl_my_family_owner_name", result.ownerDto?.ownerName);
  74. this.setText("lbl_my_family_notice", result.notice);
  75. this.setText(
  76. "lbl_family_reward_box_count",
  77. "x" + Utils.formatNumber(Number(result.boxCount), 0)
  78. );
  79. if (result.ownerDto?.owner) {
  80. this.FindNode("owner_manage_node").active = true;
  81. this.ownerUI();
  82. } else {
  83. this.FindNode("owner_manage_node").active = false;
  84. }
  85. }
  86. ownerUI() {
  87. if (this._data.ownerDto == null) {
  88. return;
  89. }
  90. this.setText(
  91. "lbl_owner_reward_pog",
  92. "x" + Utils.formatNumber(Number(this._data.ownerDto?.rewardPog), 1)
  93. );
  94. }
  95. async familyInfo() {
  96. let self = this;
  97. let familyId = UserM.ins.getFamilyId();
  98. if (familyId == null || familyId.length == 0) {
  99. return;
  100. }
  101. let result: FamilyInfo = await FamilyM.ins.getFamilyInfo(familyId);
  102. if (!result) {
  103. return;
  104. }
  105. this._data = result;
  106. this.familyUI();
  107. }
  108. async showMembers() {
  109. let familyId = UserM.ins.getFamilyId();
  110. if (familyId == null || familyId.length == 0) {
  111. return;
  112. }
  113. let members_layout = this.FindNode("members_layout");
  114. let p = await AB.ins.loadPrefab("prefab/family/FamilyMemberItem");
  115. members_layout.removeAllChildren();
  116. let list: FamilyMember[] = await FamilyM.ins.familyMemberList(familyId);
  117. if (list == null || list.length == 0) {
  118. return;
  119. }
  120. for (let index = 0; index < list.length; index++) {
  121. let item = instantiate(p);
  122. item.active = true;
  123. item.parent = members_layout;
  124. let playerData = list[index];
  125. item.getComponent(FamilyMemberItem).init(playerData);
  126. }
  127. }
  128. protected simpleOnBtnClick(name: string): void {
  129. let self = this;
  130. switch (name) {
  131. case "btn_edit_family_notice":
  132. this.editFamilyNotice();
  133. break;
  134. case "btn_approve":
  135. MemberManager.show(this._data);
  136. break;
  137. case "btn_share_family":
  138. this.shareFamily();
  139. break;
  140. case "btn_family_reward_box":
  141. this.openFamilyRewardBox();
  142. break;
  143. case "btn_family_reward_owner_pog":
  144. this.openFamilyRewardOwnerPog();
  145. break;
  146. case "btn_upgrade_family":
  147. this.upgradeFamily();
  148. break;
  149. }
  150. }
  151. async upgradeFamily() {
  152. let costDiamond = 10;
  153. if (UserM.ins.getGoodsCount(GoodsId.GEM) < costDiamond) {
  154. Tips.show("Not enough diamond");
  155. return;
  156. }
  157. let upgradeCost = `${costDiamond} Diamond`;
  158. let dialogResult = await TipsLayer.showConfirm(
  159. "",
  160. Utils.setI18nLabel("Family.UpgradeFamilyConfirm", ""+upgradeCost)
  161. );
  162. if (!dialogResult) {
  163. return;
  164. }
  165. let result = await FamilyM.ins.upgradeFamily(this._data.familyId);
  166. if (result) {
  167. TipsLayer.showConfirm("", Utils.setI18nLabel("Family.UpgradeFamilySuccess"));
  168. EV.ins.emit(EV_TYPE.FAMILY_DATA_UPDATE);
  169. await UserM.ins.refreshInfo();
  170. }
  171. }
  172. async openFamilyRewardOwnerPog() {
  173. if (this._data.ownerDto == null) {
  174. return;
  175. }
  176. if (this._data.ownerDto.owner == false) {
  177. return;
  178. }
  179. if (this._data.ownerDto.rewardStatus != 1) {
  180. Tips.show("No reward");
  181. return;
  182. }
  183. let result = await FamilyM.ins.claimFamilyRewardOwnerPog(
  184. this._data.familyId
  185. );
  186. if (result) {
  187. this._data.ownerDto.rewardStatus = 0;
  188. this._data.ownerDto.rewardPog = 0;
  189. this.familyUI();
  190. }
  191. }
  192. async openFamilyRewardBox() {
  193. let num = this._data.boxCount;
  194. if (num <= 0) {
  195. Tips.show("No reward");
  196. return;
  197. }
  198. if (num > 10) {
  199. num = 10;
  200. }
  201. let result = await FamilyM.ins.claimFamilyRewardMemberBox(
  202. this._data.familyId,
  203. num
  204. );
  205. if (result) {
  206. console.warn("result", result);
  207. this._data.boxCount = this._data.boxCount - num;
  208. this.familyUI();
  209. }
  210. }
  211. shareFamily() {
  212. Tips.show("Sharing...");
  213. let familyName = this.FindAs("lbl_my_family_name", Label).string;
  214. let familyOwner = this.FindAs("lbl_my_family_owner_name", Label).string;
  215. ShareM.ins.shareFamily(familyName, familyOwner);
  216. }
  217. }