inviteInfo.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. }
  94. })
  95. },
  96. inputInvite(value, e) {
  97. console.log(value);
  98. this.inputInviteValue = value;
  99. },
  100. onBindInviteInfo() {
  101. console.log('绑定的inputInviteValue:' + this.inputInviteValue);
  102. if (!GlobalD.dapp) {
  103. console.error("onBindInviteInfo warn,dapp未初始化!");
  104. return;
  105. }
  106. let _self = this;
  107. GlobalD.dapp.bindParent(_self.inputInviteValue).then((data) => {
  108. if (data.err === null) {
  109. // 返回成功,见下面消息体
  110. console.log(data.res)
  111. //绑定成功时候,隐藏输入框,设置父节点
  112. GlobalD.Dapp.UserInfo.parent = data.res;
  113. _self.parentInviteValue.string = GlobalD.Dapp.UserInfo.parent.invite_code;
  114. //如果存在父节点,隐藏输入框
  115. _self.inputContainer.active = false;
  116. GlobalD.GameData.showToast(_self.ToastParent, "绑定成功!", 2);
  117. } else {
  118. //TODO 服务错误
  119. console.log(data.err)
  120. GlobalD.GameData.showToast(_self.ToastParent, "绑定失败!", 2);
  121. }
  122. })
  123. },
  124. onClose() {
  125. this.node.active = false;
  126. },
  127. webCopyString() {
  128. console.log('复制');
  129. var input = GlobalD.Dapp.UserInfo.invite_code + '';
  130. const el = document.createElement('textarea');
  131. el.value = input;
  132. el.setAttribute('readonly', '');
  133. el.style.contain = 'strict';
  134. el.style.position = 'absolute';
  135. el.style.left = '-9999px';
  136. el.style.fontSize = '12pt'; // Prevent zooming on iOS
  137. const selection = getSelection();
  138. var originalRange = false;
  139. if (selection.rangeCount > 0) {
  140. originalRange = selection.getRangeAt(0);
  141. }
  142. document.body.appendChild(el);
  143. el.select();
  144. el.selectionStart = 0;
  145. el.selectionEnd = input.length;
  146. var success = false;
  147. try {
  148. success = document.execCommand('copy');
  149. } catch (err) { }
  150. document.body.removeChild(el);
  151. if (originalRange) {
  152. selection.removeAllRanges();
  153. selection.addRange(originalRange);
  154. }
  155. return success;
  156. },
  157. // update (dt) {},
  158. });