bindPhone.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
  6. <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  7. <meta name="format-detection"content="telephone=no">
  8. <title>index</title>
  9. <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
  10. <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
  11. <link rel="stylesheet" href="../../css/toast.css">
  12. <link rel="stylesheet" href="../../css/projeck.css">
  13. <style media="screen">
  14. body,html{
  15. margin: 0;
  16. background: #ecf0f1;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <!-- <header class="header-login">
  22. <img class="backBtn" src="../../image/btn_back.png" alt="" onclick="backIndex()">
  23. <p class="api_text">绑定手机号</p>
  24. </header> -->
  25. <div class="api_forget_phone">
  26. <div class="api_phone">
  27. <input type="number" name="" value="" placeholder="请输入手机号" class="api_phone_bind">
  28. </div>
  29. <div class="api_phone">
  30. <input type="number" name="" value="" placeholder="验证码" class="api_vali">
  31. <button type="button" class="api_btn_vali" id="verify-sms" onclick="changeTitleOnSendSms()">发送验证码</button>
  32. </div>
  33. <div class="api_bnt" onclick="bindPhoneFun()">绑定</div>
  34. </div>
  35. </body>
  36. </html>
  37. <script type="text/javascript" src="../../script/api.js"></script>
  38. <!-- <script src="../../script/aui-toast.js" charset="utf-8"></script> -->
  39. <!-- <script src="../../script/fastclick.min.js"></script> -->
  40. <script src="../../script/config.js" charset="utf-8"></script>
  41. <script type="text/javascript">
  42. apiready = function () {
  43. $api.fixStatusBar($api.dom('header') );
  44. api.setStatusBarStyle({
  45. style: 'light',
  46. color: 'rgba(0,159,232,0.5)'
  47. });
  48. }
  49. function backIndex() {
  50. api.closeWin();
  51. }
  52. var interval;
  53. function changeTitleOnSendSms() {
  54. var phone = $api.dom('.api_phone_bind').value;
  55. var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
  56. if (!reg.test(phone)) {
  57. api.toast({
  58. msg: '电话号码格式不正确',
  59. duration: 2000,
  60. location: 'top'
  61. });
  62. return false;
  63. }else if (phone == '') {
  64. api.toast({
  65. msg: '电话号码不能为空',
  66. duration: 2000,
  67. location: 'top'
  68. });
  69. return false;
  70. }else {
  71. phoneFun();
  72. interval = setInterval("changeTime()", 1000);
  73. var verify_btn = $api.byId("verify-sms");
  74. verify_btn.style.backgroundColor = "#D9D9D9";
  75. verify_btn.setAttribute('disabled','true');
  76. }
  77. }
  78. //
  79. var remaining_time = 30;
  80. function changeTime() {
  81. var verify_btn = $api.byId("verify-sms");
  82. $api.html(verify_btn, remaining_time + "s后重发");
  83. remaining_time -= 1;
  84. if (remaining_time <= 0) {
  85. window.clearInterval(interval);
  86. remaining_time = 30;
  87. verify_btn.style.backgroundColor = "#009fe8";
  88. verify_btn.removeAttribute('disabled','true');
  89. $api.html(verify_btn, "获取验证码");
  90. // canSms = true;
  91. }
  92. }
  93. function phoneFun() {
  94. var phone = $api.dom('.api_phone_bind');
  95. var phoneValue = $api.val(phone);
  96. $http.requestData(UrlRouter.vcodeApi,'post',{mobile: phoneValue})
  97. .then(ret=>{
  98. if (ret.code === 0) {
  99. api.toast({
  100. msg: '发送成功',
  101. duration: 2000,
  102. location: 'top'
  103. });
  104. }else if (ret.code === 3001) {
  105. api.toast({
  106. msg: '电话号码错误',
  107. duration: 2000,
  108. location: 'top'
  109. });
  110. }else if (ret.code === 3002) {
  111. api.toast({
  112. msg: '发送失败',
  113. duration: 2000,
  114. location: 'top'
  115. })
  116. }
  117. })
  118. .catch(err=>{
  119. api.toast({
  120. msg: '请求超时!',
  121. duration: 2000,
  122. location: 'top'
  123. });
  124. })
  125. }
  126. // 手机号验证
  127. // function checkPhone() {
  128. // var phone = $api.dom('.api_phone_bind').value;
  129. // if (!(/^1[34578]\d{9}$/.test(phone))) {
  130. // return false;
  131. // }
  132. // return true;
  133. // }
  134. // 绑定
  135. function bindPhoneFun() {
  136. var phone = $api.dom('.api_phone_bind').value,
  137. vcode = $api.dom('.api_vali').value;
  138. var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
  139. if (!reg.test(phone)) {
  140. api.toast({
  141. msg: '电话号码格式不正确',
  142. duration: 2000,
  143. location: 'top'
  144. });
  145. return false;
  146. }
  147. if(phone !='' && vcode !=''){
  148. $http.requestDataLoging(UrlRouter.setApi,'post',{mobile: phone,vcode})
  149. .then(ret=>{
  150. if (ret.code === 0) {
  151. api.toast({
  152. msg: '绑定成功',
  153. duration: 2000,
  154. location: 'top'
  155. });
  156. api.sendEvent({
  157. name: 'myEvent',
  158. extra: {
  159. key1: 'value1',
  160. key2: 'value2'
  161. }
  162. });
  163. api.closeWin();
  164. }else if (ret.code === 4002) {
  165. api.toast({
  166. msg: '验证码超时或者错误',
  167. duration: 2000,
  168. location: 'top'
  169. });
  170. }else if (ret.code === 4001) {
  171. api.toast({
  172. msg: '缺少必要参数',
  173. duration: 2000,
  174. location: 'top'
  175. });
  176. }
  177. })
  178. .catch(err=>{
  179. api.toast({
  180. msg: '网络超时',
  181. duration: 2000,
  182. location: 'top'
  183. });
  184. })
  185. }else {
  186. api.toast({
  187. msg: '手机号或验证码不能为空',
  188. duration: 2000,
  189. location: 'top'
  190. });
  191. }
  192. }
  193. </script>