inviteInfo.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. inputContainer:{
  47. default:null,
  48. type:cc.Node,
  49. serializable:true
  50. }
  51. },
  52. // LIFE-CYCLE CALLBACKS:
  53. // onLoad () {},
  54. start() {
  55. },
  56. onOpenInviteInfo() {
  57. if (!GlobalD.dapp) {
  58. console.error("InviteInfo start,dapp未初始化!");
  59. return;
  60. }
  61. this.node.active = true;
  62. this.myInviteValue.string = GlobalD.Dapp.UserInfo.invite_code;
  63. if (GlobalD.Dapp.UserInfo.parent) {
  64. this.parentInviteValue.string = GlobalD.Dapp.UserInfo.parent.invite_code;
  65. //如果存在父节点,隐藏输入框
  66. this.inputContainer.active = false;
  67. }
  68. // {
  69. // "children_count": 1, // 直推下级数量
  70. // "team_count": 1, // 伞下成员数量(包含直推数量)
  71. // "children_village_chief_count": 1, // 直推村长数量(镇长身份才需要展示)
  72. // "children_cnt_amount": 0, // 直推下级租赁土地消费CNT业绩数量
  73. // "team_cnt_amount": 0 // 伞下团队租赁土地消费CNT数量(含直推数量)
  74. // }
  75. // 获取镇长/村长团队信息(村长或镇长身份才需要)
  76. // if (0 === GlobalD.Dapp.UserInfo.agent_level) {
  77. // console.log("村民不需要获取团队信息");
  78. // return;
  79. // }
  80. GlobalD.dapp.teamData().then((data) => {
  81. console.log("teamData:" + JSON.stringify(data));
  82. if (data.err === null) {
  83. // 返回成功,见下面消息体
  84. this.neighborValue.string = data.res.children_count;
  85. this.neighborConsumValue.string = data.res.children_cnt_amount;
  86. this.neighborDirectValue.string = data.res.children_village_chief_count;
  87. this.farmerValue.string = data.res.team_count;
  88. this.farmerConsumValue.string = data.res.team_cnt_amount;
  89. } else {
  90. //TODO 服务错误
  91. console.log(data.err)
  92. GlobalD.GameData.showToast(this.ToastParent, data.err, 3, () => {
  93. console.log("finish toast!");
  94. });
  95. }
  96. })
  97. },
  98. inputInvite(value, e) {
  99. console.log(value);
  100. this.inputInviteValue = value;
  101. },
  102. onBindInviteInfo() {
  103. console.log('绑定的inputInviteValue:' + this.inputInviteValue);
  104. if (!GlobalD.dapp) {
  105. console.error("onBindInviteInfo warn,dapp未初始化!");
  106. return;
  107. }
  108. let _self = this;
  109. GlobalD.dapp.bindParent(_self.inputInviteValue).then((data) => {
  110. if (data.err === null) {
  111. // 返回成功,见下面消息体
  112. console.log(data.res)
  113. //绑定成功时候,隐藏输入框,设置父节点
  114. GlobalD.Dapp.UserInfo.parent = data.res;
  115. _self.parentInviteValue.string = GlobalD.Dapp.UserInfo.parent.invite_code;
  116. //如果存在父节点,隐藏输入框
  117. _self.inputContainer.active = false;
  118. GlobalD.GameData.showToast(_self.ToastParent, "绑定成功!", 3, () => {
  119. console.log("finish toast!");
  120. });
  121. } else {
  122. //TODO 服务错误
  123. console.log(data.err)
  124. GlobalD.GameData.showToast(_self.ToastParent, "绑定失败!", 3, () => {
  125. console.log("finish toast!");
  126. });
  127. }
  128. })
  129. },
  130. onClose() {
  131. this.node.active = false;
  132. },
  133. webCopyString() {
  134. console.log('复制');
  135. var input = GlobalD.Dapp.UserInfo.invite_code + '';
  136. const el = document.createElement('textarea');
  137. el.value = input;
  138. el.setAttribute('readonly', '');
  139. el.style.contain = 'strict';
  140. el.style.position = 'absolute';
  141. el.style.left = '-9999px';
  142. el.style.fontSize = '12pt'; // Prevent zooming on iOS
  143. const selection = getSelection();
  144. var originalRange = false;
  145. if (selection.rangeCount > 0) {
  146. originalRange = selection.getRangeAt(0);
  147. }
  148. document.body.appendChild(el);
  149. el.select();
  150. el.selectionStart = 0;
  151. el.selectionEnd = input.length;
  152. var success = false;
  153. try {
  154. success = document.execCommand('copy');
  155. } catch (err) { }
  156. document.body.removeChild(el);
  157. if (originalRange) {
  158. selection.removeAllRanges();
  159. selection.addRange(originalRange);
  160. }
  161. return success;
  162. },
  163. // update (dt) {},
  164. });