inviteInfo.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. * 绑定邀请码信息
  3. */
  4. import gameToast from "../Network/gameToast"
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. neighborValue: {
  9. default: null,
  10. type: cc.Label
  11. },
  12. neighborConsumValue: {
  13. default: null,
  14. type: cc.Label
  15. },
  16. neighborDirectValue: {
  17. default: null,
  18. type: cc.Label
  19. },
  20. farmerValue: {
  21. default: null,
  22. type: cc.Label
  23. },
  24. farmerConsumValue: {
  25. default: null,
  26. type: cc.Label
  27. },
  28. myInviteValue: {
  29. default: null,
  30. type: cc.Label
  31. },
  32. parentInviteValue: {
  33. default: null,
  34. type: cc.Label
  35. },
  36. inputInviteValue: {
  37. default: '',
  38. visible: false
  39. },
  40. ToastParent: {
  41. default: null,
  42. type: cc.Node,
  43. serializable: true
  44. },
  45. },
  46. // LIFE-CYCLE CALLBACKS:
  47. // onLoad () {},
  48. start() {
  49. },
  50. onOpenInviteInfo() {
  51. if (!GlobalD.dapp) {
  52. console.error("InviteInfo start,dapp未初始化!");
  53. return;
  54. }
  55. this.node.active = true;
  56. this.myInviteValue.string = GlobalD.Dapp.UserInfo.invite_code;
  57. if (GlobalD.Dapp.UserInfo.parent) {
  58. this.parentInviteValue.string = GlobalD.Dapp.UserInfo.parent;
  59. }
  60. // {
  61. // "children_count": 1, // 直推下级数量
  62. // "team_count": 1, // 伞下成员数量(包含直推数量)
  63. // "children_village_chief_count": 1, // 直推村长数量(镇长身份才需要展示)
  64. // "children_cnt_amount": 0, // 直推下级租赁土地消费CNT业绩数量
  65. // "team_cnt_amount": 0 // 伞下团队租赁土地消费CNT数量(含直推数量)
  66. // }
  67. // 获取镇长/村长团队信息(村长或镇长身份才需要)
  68. if (0 === GlobalD.Dapp.UserInfo.agent_level) {
  69. console.log("村民不需要获取团队信息");
  70. return;
  71. }
  72. GlobalD.dapp.teamData().then((data) => {
  73. if (data.err === null) {
  74. // 返回成功,见下面消息体
  75. console.log("==========>" + JSON.stringify(data));
  76. this.neighborValue.string = data.res.children_count;
  77. this.neighborConsumValue.string = data.res.children_cnt_amount;
  78. this.neighborDirectValue.string = data.res.children_village_chief_count;
  79. this.farmerValue.string = data.res.team_count;
  80. this.farmerConsumValue.string = data.res.team_cnt_amount;
  81. } else {
  82. //TODO 服务错误
  83. console.log(data.err)
  84. gameToast.getInstance().show(this.ToastParent, data.err, 3, () => {
  85. console.log("finish toast!");
  86. }, this);
  87. }
  88. })
  89. },
  90. inputInvite(value, e) {
  91. console.log(value);
  92. this.inputInviteValue = value;
  93. },
  94. onBindInviteInfo() {
  95. console.log('绑定的inputInviteValue:' + this.inputInviteValue);
  96. if (!GlobalD.dapp) {
  97. console.error("onBindInviteInfo warn,dapp未初始化!");
  98. return;
  99. }
  100. let _self = this;
  101. GlobalD.dapp.bindParent(this.inputInviteValue).then((data) => {
  102. if (data.err === null) {
  103. // 返回成功,见下面消息体
  104. console.log(data.res)
  105. gameToast.getInstance().show(_self.ToastParent, data.res, 3, () => {
  106. console.log("finish toast!");
  107. }, _self);
  108. } else {
  109. //TODO 服务错误
  110. console.log(data.err)
  111. gameToast.getInstance().show(_self.ToastParent, data.err, 3, () => {
  112. console.log("finish toast!");
  113. }, _self);
  114. }
  115. })
  116. },
  117. onClose() {
  118. this.node.active = false;
  119. },
  120. webCopyString() {
  121. console.log('复制');
  122. var input = GlobalD.Dapp.UserInfo.invite_code + '';
  123. const el = document.createElement('textarea');
  124. el.value = input;
  125. el.setAttribute('readonly', '');
  126. el.style.contain = 'strict';
  127. el.style.position = 'absolute';
  128. el.style.left = '-9999px';
  129. el.style.fontSize = '12pt'; // Prevent zooming on iOS
  130. const selection = getSelection();
  131. var originalRange = false;
  132. if (selection.rangeCount > 0) {
  133. originalRange = selection.getRangeAt(0);
  134. }
  135. document.body.appendChild(el);
  136. el.select();
  137. el.selectionStart = 0;
  138. el.selectionEnd = input.length;
  139. var success = false;
  140. try {
  141. success = document.execCommand('copy');
  142. } catch (err) { }
  143. document.body.removeChild(el);
  144. if (originalRange) {
  145. selection.removeAllRanges();
  146. selection.addRange(originalRange);
  147. }
  148. return success;
  149. },
  150. // update (dt) {},
  151. });