No Description

findpwd1.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //手机找回密码
  2. mui.ready(function() {
  3. /*定义全局变量*/
  4. var userPhone = document.getElementById("userPhone");
  5. var userCode = document.getElementById("userCode");
  6. var nextPage = document.getElementById("nextPage");
  7. var obtainCode = document.getElementById("obtain-code");
  8. var phoneCode = false;
  9. var state = "";
  10. var num;
  11. mui.plusReady(function(){
  12. /*校验提交按钮显示状态*/
  13. mui('.frmbox').on('keyup', "#userPhone,#userCode", function() {
  14. hideButtn(userPhone,userCode,nextPage,"frmactiveok");
  15. });
  16. /*下一步按钮*/
  17. nextPage.addEventListener('tap', function() {
  18. codeVal();
  19. })
  20. /*点击获取验证码*/
  21. obtainCode.addEventListener('tap', function() {
  22. phoneVal();
  23. })
  24. /*校验手机号*/
  25. function phoneVal() {
  26. var hunPhone = /^1[3|4|5|7|8]\d{9}$/;
  27. if(hunPhone.test(userPhone.value)) {
  28. isReg();
  29. } else {
  30. plus.nativeUI.toast("请输入正确的手机号码", toastStyle);
  31. return;
  32. }
  33. }
  34. /*校验用户名是否注册*/
  35. function isReg() {
  36. mui.ajax(baseUrl + '/ajax/isReg?key=' + userPhone.value, {
  37. dataType: 'json', //数据格式类型
  38. type: 'GET', //http请求类型
  39. async: false,
  40. success: function(data) {
  41. console.log(data.data);
  42. if(data.data == false) {
  43. phoneCode = true;
  44. if(phoneCode){
  45. sendAuthentication();
  46. }
  47. } else {
  48. plus.nativeUI.toast("该手机号码未注册账户,请先注册", toastStyle);
  49. return;
  50. }
  51. },
  52. error: function() {
  53. plus.nativeUI.toast("服务器链接超时", toastStyle);
  54. }
  55. });
  56. }
  57. /*手机发送验证码*/
  58. function sendAuthentication() {
  59. mui.ajax(baseUrl + '/ajax/vcWithRP', {
  60. data: {
  61. mobilePhone: userPhone.value
  62. },
  63. dataType: 'json', //数据格式类型
  64. type: 'GET', //http请求类型
  65. async: false,
  66. success: function(data) {
  67. if(data.success) {
  68. state = data.data;
  69. doClick();
  70. return;
  71. }
  72. },
  73. error: function() {
  74. plus.nativeUI.toast("服务器链接超时", toastStyle);
  75. return;
  76. }
  77. })
  78. }
  79. /*30s后重新获取验证码*/
  80. function doClick() {
  81. var getCodeOff = document.getElementById("getcodeoff");
  82. obtainCode.style.display = "none";
  83. getCodeOff.style.display = "block";
  84. getCodeOff.innerHTML = "30s后重新获取";
  85. var clickTime = new Date().getTime();
  86. var Timer = setInterval(function() {
  87. var nowTime = new Date().getTime();
  88. var second = Math.ceil(30 - (nowTime - clickTime) / 1000);
  89. if(second > 0) {
  90. getCodeOff.innerHTML = second + "s后重新获取";
  91. } else {
  92. clearInterval(Timer);
  93. obtainCode.style.display = "block";
  94. getCodeOff.style.display = "none";
  95. obtainCode.innerHTML = "获取验证码";
  96. }
  97. }, 1000);
  98. }
  99. /*校验验证码*/
  100. function codeVal() {
  101. mui.ajax(baseUrl + '/ajax/validCode', {
  102. data: {
  103. "state": state,
  104. "vc": userCode.value
  105. },
  106. dataType: 'json', //数据格式类型
  107. async: false,
  108. type: 'POST', //http请求类型
  109. success: function(data) {
  110. console.log(data.success);
  111. console.log(data.data);
  112. if(data.success) {
  113. if(data.data) {
  114. mui.openWindow({
  115. url: 'setpass.html',
  116. id: 'setpass.html',
  117. extras: {
  118. phoneName: userPhone.value,
  119. setCode: userCode.value,
  120. state: state,
  121. num:1
  122. }
  123. });
  124. }else{
  125. plus.nativeUI.toast("验证码不正确", toastStyle);
  126. return;
  127. }
  128. }else{
  129. console.log(data.msg);
  130. if(data.msg=="验证超时"){
  131. plus.nativeUI.toast("验证码超时", toastStyle);
  132. return;
  133. }else{
  134. plus.nativeUI.toast("请填写正确的手机号,验证码", toastStyle);
  135. return;
  136. }
  137. }
  138. },
  139. error: function() {
  140. plus.nativeUI.toast("服务器链接超时", toastStyle);
  141. return;
  142. }
  143. })
  144. }
  145. });
  146. });