YzRealNameAuthPanel.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import { utils } from "./Utils";
  2. import { BannerLocation } from "./YZ_Constant";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class YzRealNameAuthPanel extends cc.Component {
  6. edit_real_name: cc.EditBox = null;
  7. edit_id_card: cc.EditBox = null;
  8. realNameAuthPanel: cc.Node = null;
  9. msgNode: cc.Node = null;
  10. exitPanel: cc.Node = null;
  11. toVerifyPanel: cc.Node = null;
  12. offLinePanel: cc.Node = null;
  13. edit_default_color = null;
  14. _isOffLine: boolean = false;
  15. realNameAuthLandscapePanel:cc.Node = null;
  16. onLoad() {
  17. if (utils.otherConfig && utils.otherConfig.group) {
  18. this.node.group = utils.otherConfig.group;
  19. }
  20. let ratio = 0;
  21. if (cc.winSize.height < cc.winSize.width) {
  22. this.realNameAuthPanel = cc.find("Panel/RealNameAuthLandscapePanel", this.node)
  23. // 横屏游戏
  24. ratio = cc.winSize.width / 1920 * 0.75;
  25. } else {
  26. this.realNameAuthPanel = cc.find("Panel/RealNameAuthPanel", this.node)
  27. ratio = cc.winSize.width / 1080;
  28. }
  29. this.exitPanel = cc.find("Panel/ExitPanel", this.node);
  30. this.toVerifyPanel = cc.find("Panel/ToVerifyPanel", this.node);
  31. this.offLinePanel = cc.find("Panel/OfflinePanel", this.node);
  32. this.edit_id_card = this.realNameAuthPanel.getChildByName("editIdCard").getComponent(cc.EditBox);
  33. this.edit_real_name = this.realNameAuthPanel.getChildByName("editRealName").getComponent(cc.EditBox);
  34. this.msgNode = cc.find("Panel/MsgNode", this.node);
  35. this.edit_default_color = this.edit_real_name.fontColor;
  36. if (this.edit_default_color == null) {
  37. this.edit_default_color = new cc.Color(0, 0, 0, 63);
  38. }
  39. cc.find("Panel", this.node).scale = ratio;
  40. if (this._isOffLine) {
  41. this.showOfferLine();
  42. } else {
  43. this.realNameAuthPanel.active = true;
  44. }
  45. }
  46. start() {
  47. // if (cc.winSize.height < cc.winSize.width) {
  48. // utils.adManager.HideBanner(BannerLocation.Home);
  49. // }
  50. }
  51. onDestroy() {
  52. utils.emitRealNameAuthCloseEvent();
  53. }
  54. onExitBtnClickListener() {
  55. utils.showLog("退出游戏!");
  56. utils.GameExit();
  57. }
  58. onBackAuthBtnClickListener() {
  59. this.toVerifyPanel.active = false;
  60. this.exitPanel.active = false;
  61. this.realNameAuthPanel.active = true;
  62. }
  63. showExitPanel() {
  64. this.toVerifyPanel.active = false;
  65. this.realNameAuthPanel.active = false;
  66. this.offLinePanel.active = false;
  67. this.exitPanel.active = true;
  68. }
  69. showOfferLine() {
  70. this.toVerifyPanel.active = false;
  71. this.exitPanel.active = false;
  72. this.realNameAuthPanel.active = false;
  73. this.offLinePanel.active = true;
  74. }
  75. regName = /^[\u4e00-\u9fa5]{2,4}$/;
  76. regIdNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  77. _clickTime: number = 0;
  78. onPostBtnClickListener() {
  79. let nowTime = new Date().getTime();
  80. if ((nowTime - this._clickTime) / 1000 < 2) {
  81. this.showMsg('请勿频繁提交!');
  82. return;
  83. }
  84. this._clickTime = nowTime;
  85. if (!this.regName.test(this.edit_real_name.string)) {
  86. this.showMsg('真实姓名填写有误!');
  87. this.edit_real_name.fontColor = cc.Color.RED;
  88. this.edit_real_name.setFocus();
  89. return false;
  90. }
  91. this.edit_real_name.fontColor = this.edit_default_color;
  92. if (!this.regIdNo.test(this.edit_id_card.string)) {
  93. this.edit_id_card.fontColor = cc.Color.RED;
  94. this.showMsg('身份证号填写有误!');
  95. this.edit_id_card.setFocus();
  96. return false;
  97. }
  98. this.edit_id_card.fontColor = this.edit_default_color;
  99. utils.realNameAuth(this.edit_id_card.string, this.edit_real_name.string, (res, result) => {
  100. utils.showLog("实名认证结束:#result=" + JSON.stringify(result));
  101. if (res) {
  102. if (result) {
  103. let res = JSON.parse(result);
  104. switch (res.code) {
  105. case 1:
  106. this.showMsg(res.msg)
  107. break;
  108. case 0:
  109. if (res.nonage == "0") {
  110. utils.setRealNameAuthLocalData("2")
  111. } else {
  112. utils.setRealNameAuthLocalData("1")
  113. }
  114. utils._isRealNameAuth = true;
  115. if (res.msg) {
  116. this.showMsg(res.msg);
  117. }
  118. this.scheduleOnce(() => {
  119. this.node.destroy();
  120. }, 0.5);
  121. break;
  122. case 2:
  123. utils.setRealNameAuthLocalData("2")
  124. this.showOfferLine();
  125. break;
  126. }
  127. } else {
  128. this.showMsg("请求失败,请重新提交验证!")
  129. }
  130. } else {
  131. this.showMsg("请求失败,请重新提交验证!")
  132. }
  133. })
  134. }
  135. showMsg(str: string) {
  136. let msgNode = cc.instantiate(this.msgNode);
  137. msgNode.getChildByName("msgLabel").getComponent(cc.Label).string = `${str}`;
  138. this.node.addChild(msgNode, cc.macro.MAX_ZINDEX);
  139. msgNode.active = true;
  140. msgNode.runAction(cc.sequence(cc.delayTime(0.8), cc.moveBy(0.3, cc.v2(0, +80)), cc.callFunc(() => {
  141. msgNode.destroy();
  142. })))
  143. }
  144. }