ManagePlayerItem.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { _decorator, Component, Node } from "cc";
  2. import BaseUI from "../../scripts/base/BaseUI";
  3. import { Tips } from "../../scripts/mgr/Tips";
  4. import { TipsData, TipsLayer } from "../layer/TipsLayer";
  5. import Utils from "../../scripts/utils/Utils";
  6. import FamilyM, { FamilyInfo } from "../../scripts/api/FamilyM";
  7. import UserM from "../../scripts/api/UserM";
  8. import EV, { EV_TYPE } from "../../scripts/mgr/EV";
  9. const { ccclass, property } = _decorator;
  10. export enum ManagePlayerItemType {
  11. APPROVE = 0,
  12. MEMBERS = 1,
  13. }
  14. export class ManagePlayerItemData {
  15. type: ManagePlayerItemType;
  16. userId: string;
  17. userName: string;
  18. reason: string;
  19. status: number;
  20. totalXp: number;
  21. dailyXp: number;
  22. }
  23. @ccclass("ManagePlayerItem")
  24. export class ManagePlayerItem extends BaseUI {
  25. private type: ManagePlayerItemType = null!;
  26. private _familyInfo: FamilyInfo;
  27. private _data: ManagePlayerItemData;
  28. init(
  29. type: ManagePlayerItemType,
  30. data: ManagePlayerItemData,
  31. familyInfo: FamilyInfo
  32. ) {
  33. this.type = type;
  34. this._familyInfo = familyInfo;
  35. this._data = data;
  36. this.setText("lbl_user_name", "" + data.userName);
  37. this.initType(type);
  38. this.initUI(data);
  39. }
  40. initUI(data: ManagePlayerItemData) {
  41. if (this.type == ManagePlayerItemType.APPROVE) {
  42. let reason = data.reason;
  43. this.setText("lbl_approve_info", reason);
  44. } else if (this.type == ManagePlayerItemType.MEMBERS) {
  45. let totalXp = data.totalXp;
  46. if (totalXp < data.dailyXp) {
  47. totalXp = data.dailyXp;
  48. }
  49. this.setText(
  50. "lbl_exp_value",
  51. "today:" +
  52. Utils.formatNumber(data.dailyXp, 1) +
  53. " total:" +
  54. Utils.formatNumber(totalXp, 1)
  55. );
  56. }
  57. }
  58. initType(type: ManagePlayerItemType) {
  59. if (type == ManagePlayerItemType.APPROVE) {
  60. this.setText("lbl_manager_name", "" + "Approve");
  61. } else if (type == ManagePlayerItemType.MEMBERS) {
  62. this.setText("lbl_manager_name", "" + "Remove");
  63. if (this.isOwner()) {
  64. this.FindNode("btn_manage_one").active = false;
  65. }
  66. }
  67. this.FindNode("exp").active = type == ManagePlayerItemType.MEMBERS;
  68. this.FindNode("lbl_approve_info").active =
  69. type == ManagePlayerItemType.APPROVE;
  70. }
  71. protected simpleOnBtnClick(name: string): void {
  72. switch (name) {
  73. case "btn_manage_one":
  74. if (this.type == ManagePlayerItemType.APPROVE) {
  75. // FamilyM.ins.agreeJoinFamily(UserM.ins.getFamilyId(), this.data);
  76. this.agreeJoinFamily();
  77. } else if (this.type == ManagePlayerItemType.MEMBERS) {
  78. this.remove();
  79. }
  80. break;
  81. }
  82. }
  83. async agreeJoinFamily() {
  84. let result = await FamilyM.ins.agreeJoinFamily(
  85. this._familyInfo.familyId,
  86. this._data.userId
  87. );
  88. if (result) {
  89. Tips.show("Agree join success");
  90. EV.ins.emit(EV_TYPE.FAMILY_MEMBER_UPDATE);
  91. this.node.destroy();
  92. }
  93. }
  94. private isOwner(): boolean {
  95. return this._familyInfo.ownerDto?.ownerId == this._data?.userId;
  96. }
  97. async remove() {
  98. let self = this;
  99. if (this.isOwner()) {
  100. return;
  101. }
  102. TipsLayer.showConfirm(
  103. "",
  104. Utils.setI18nLabel("Family.RemoveConfirmContent")
  105. ).then((success) => {
  106. if (success) {
  107. FamilyM.ins
  108. .kickFamilyMember(this._familyInfo.familyId, this._data.userId)
  109. .then((result) => {
  110. if (result) {
  111. Tips.show(Utils.setI18nLabel("Family.RemoveMemberSuccess"));
  112. EV.ins.emit(EV_TYPE.FAMILY_MEMBER_UPDATE);
  113. self.node.destroy();
  114. }
  115. });
  116. }
  117. });
  118. }
  119. }