InviteWindow.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { _decorator, Component, ProgressBar, Label } from 'cc';
  2. import { Http } from '../../core/net/Http';
  3. import { BitmapFont } from '../../core/ui/BitmapFont';
  4. import { WindowManager } from '../../core/ui/window/WindowManager';
  5. import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
  6. import { g } from '../../Data/g';
  7. import { platform } from '../../Data/platform';
  8. import { ChildItem } from './ChildItem';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('InviteWindow')
  11. export class InviteWindow extends Component {
  12. @property({ type: Http, tooltip: "http组件" }) http: Http;
  13. @property({ type: BitmapFont, tooltip: "金额文本" }) moneyLabel: BitmapFont;
  14. @property({ type: [ChildItem], tooltip: "泡泡集合" }) paopaos: Array<ChildItem> = [];
  15. @property({ type: ProgressBar, tooltip: "我的金额进度条" }) moneyProgress: ProgressBar;
  16. @property({ type: Label, tooltip: "约等于文本" }) aboutLabel: Label;
  17. private memberData: any;
  18. private parentData: { nickName: string, avatar: string, uid: string } = { nickName: "", avatar: "", uid: "" };
  19. private nowReceive = -1;
  20. private revenueData = [];
  21. // private testData = { "code": 0, "data": { "memberDatas": { "g1Members": [{ "userID": 100034, "avatar": "", "nickname": "测试32", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }, { "userID": 100043, "avatar": "", "nickname": "测试31", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }, { "userID": 100044, "avatar": "", "nickname": "测试32", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }, { "userID": 100201, "avatar": "", "nickname": "测试100201", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }, { "userID": 100211, "avatar": "", "nickname": "测试100211", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }], "g2Members": [{ "userID": 100046, "avatar": "", "nickname": "测试34", "revenueAmount": 0, "gameWithdrawAmount": 0 }, { "userID": 100202, "avatar": "", "nickname": "测试100202", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }, { "userID": 100212, "avatar": "", "nickname": "测试100212", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }], "g3Members": [{ "userID": 100203, "avatar": "", "nickname": "测试100203", "revenueAmount": 0.1, "gameWithdrawAmount": 0 }, { "userID": 100213, "avatar": "", "nickname": "测试100213", "revenueAmount": 0, "gameWithdrawAmount": 0 }], "g4Members": [{ "userID": 100204, "avatar": "", "nickname": "测试100204", "revenueAmount": 0, "gameWithdrawAmount": 0 }, { "userID": 100214, "avatar": "", "nickname": "测试100214", "revenueAmount": 0, "gameWithdrawAmount": 0 }], "g5Members": [{ "userID": 100205, "avatar": "", "nickname": "测试100205", "revenueAmount": 0, "gameWithdrawAmount": 0 }], "parentUin": "", "parentAvatar": "", "parentNickname": "" } } }
  22. async start() {
  23. let result = await this.http.send("/api/fission/GetFission", {});
  24. if (result.code == 0) {
  25. this.memberData = result.data.memberDatas;//this.testData.data.memberDatas;//
  26. this.parentData = { nickName: result.data.memberDatas.parentNickname, avatar: result.data.memberDatas.parentAvatar, uid: result.data.memberDatas.parentUin };
  27. for (let i = 1; i < 6; i++) {
  28. let gData = this.memberData[`g${i}Members`];
  29. for (let j = 0; j < gData.length; j++) {
  30. if (gData[j].revenueAmount > 0) {
  31. this.revenueData.push(gData[j]);
  32. }
  33. }
  34. }
  35. this.onChildTweenOver();
  36. }
  37. }
  38. update() {
  39. if (this.nowReceive != g.userData.contribution) {
  40. this.nowReceive = g.userData.contribution;
  41. this.moneyLabel.string = !!g.userData.contribution ? g.userData.contribution + "" : "0";
  42. this.moneyProgress.progress = (g.userData.contribution / 10000 / 10) <= 1 ? (g.userData.contribution / 10000 / 10) : 1;
  43. this.aboutLabel.string = `约${(g.userData.contribution / 10000).toFixed(2)}元`;
  44. }
  45. }
  46. public onChildTweenOver(): void {
  47. for (let i = 0; i < this.paopaos.length; i++) {
  48. if (!this.paopaos[i].node.active && this.revenueData.length > 0) {
  49. this.paopaos[i].setData(this.revenueData.shift());
  50. }
  51. }
  52. }
  53. public async oneKeyGet() {
  54. let canOneKey = false;
  55. for (let i = 0; i < this.paopaos.length; i++) {
  56. if (this.paopaos[i].node.active) {
  57. canOneKey = true;
  58. break;
  59. }
  60. }
  61. if (canOneKey) {
  62. let result = await this.http.send("/api/fission/ReceiveFission", { receiveUserID: 0 });
  63. if (result.code == 0) {
  64. platform.reportThinking("invite", JSON.stringify({ current_amount: g.userData.contribution, after_amount: g.userData.contribution + result.data.addTotalContribution }));
  65. g.userData.contribution += result.data.addTotalContribution;
  66. this.revenueData = [];
  67. for (let i = 0; i < this.paopaos.length; i++) {
  68. if (this.paopaos[i].node.active) {
  69. await this.paopaos[i].getComponent(ChildItem).doTween();
  70. }
  71. }
  72. }
  73. } else {
  74. WindowManager.showTips("暂时没有贡献可领取");
  75. }
  76. }
  77. public async withDraw() {
  78. if (g.userData.contribution >= 0.3 * 10000) {
  79. let result = await this.http.send("/api/user/withdraw", { type: 1 });
  80. if (result.code === 0 && !result.message) {
  81. WindowManager.showTips("提现成功");
  82. g.userData.contribution = 0;
  83. } else if (result.message) {
  84. WindowManager.showTips(result.message);
  85. }
  86. else {
  87. WindowManager.showTips("网络异常,请稍候再试");
  88. }
  89. } else {
  90. WindowManager.showTips("提现金额不足0.3元");
  91. }
  92. }
  93. public moreFriend(): void {
  94. WindowManager.open("Prefabs/InviteWindow/ChildrenListWindow", WindowOpenMode.NotCloseAndAdd, this.memberData);
  95. }
  96. public myTeacher(): void {
  97. if (this.parentData.uid != "") {
  98. WindowManager.open("Prefabs/InviteWindow/InviteTeacherWIndow", WindowOpenMode.NotCloseAndAdd, this.parentData);
  99. } else {
  100. WindowManager.showTips("您没有上级");
  101. }
  102. }
  103. public async share() {
  104. let result = await this.http.send("/api/app/share", {});
  105. if (result.code == 0) {
  106. platform.reportThinking("invite", JSON.stringify({ upper_class: this.parentData.uid }));
  107. platform.wxShare(result.data.url, result.data.title, result.data.descroption);
  108. } else {
  109. WindowManager.showTips("分享信息获取失败,请稍后再试");
  110. }
  111. }
  112. }