bindPhone.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. var token;
  43. var toast = new auiToast();
  44. apiready = function () {
  45. $api.fixStatusBar($api.dom('header') );
  46. api.setStatusBarStyle({
  47. style: 'light',
  48. color: 'rgba(0,159,232,0.5)'
  49. });
  50. var info = $api.getStorage('data');
  51. token = JSON.parse(info).data.access_token;
  52. }
  53. function backIndex() {
  54. api.closeWin();
  55. }
  56. var interval;
  57. function changeTitleOnSendSms() {
  58. var phone = $api.dom('.api_phone_bind').value;
  59. var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
  60. if (!reg.test(phone)) {
  61. api.toast({
  62. msg: '电话号码格式不正确',
  63. duration: 2000,
  64. location: 'top'
  65. });
  66. return false;
  67. }else if (phone == '') {
  68. api.toast({
  69. msg: '电话号码不能为空',
  70. duration: 2000,
  71. location: 'top'
  72. });
  73. return false;
  74. }else {
  75. phoneFun(token);
  76. interval = setInterval("changeTime()", 1000);
  77. var verify_btn = $api.byId("verify-sms");
  78. verify_btn.style.backgroundColor = "#D9D9D9";
  79. verify_btn.setAttribute('disabled','true');
  80. }
  81. }
  82. //
  83. var remaining_time = 30;
  84. function changeTime() {
  85. var verify_btn = $api.byId("verify-sms");
  86. $api.html(verify_btn, remaining_time + "s后重发");
  87. remaining_time -= 1;
  88. if (remaining_time <= 0) {
  89. window.clearInterval(interval);
  90. remaining_time = 30;
  91. verify_btn.style.backgroundColor = "#009fe8";
  92. verify_btn.removeAttribute('disabled','true');
  93. $api.html(verify_btn, "获取验证码");
  94. // canSms = true;
  95. }
  96. }
  97. function phoneFun(token) {
  98. var phone = $api.dom('.api_phone_bind');
  99. var phoneValue = $api.val(phone);
  100. api.ajax({
  101. url: UrlRouter.vcodeApi,
  102. method: 'post',
  103. headers : {
  104. "Authorization":"Bearer "+ token
  105. },
  106. data: {
  107. values: {
  108. mobile: phoneValue
  109. }
  110. }
  111. },function(ret, err){
  112. if (ret) {
  113. if (ret.code === 3001) {
  114. api.toast({
  115. msg: '电话号码错误',
  116. duration: 2000,
  117. location: 'top'
  118. });
  119. }else if (ret.code === 0) {
  120. api.toast({
  121. msg: '发送成功',
  122. duration: 2000,
  123. location: 'top'
  124. });
  125. }
  126. } else if (ret.code === 3002) {
  127. api.toast({
  128. msg: '发送失败',
  129. duration: 2000,
  130. location: 'top'
  131. })
  132. }else {
  133. api.toast({
  134. msg: '请求超时!',
  135. duration: 2000,
  136. location: 'top'
  137. });
  138. }
  139. });
  140. }
  141. // 手机号验证
  142. // function checkPhone() {
  143. // var phone = $api.dom('.api_phone_bind').value;
  144. // if (!(/^1[34578]\d{9}$/.test(phone))) {
  145. // return false;
  146. // }
  147. // return true;
  148. // }
  149. // 绑定
  150. function bindPhoneFun() {
  151. var phone = $api.dom('.api_phone_bind').value,
  152. vcode = $api.dom('.api_vali').value;
  153. var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
  154. if (!reg.test(phone)) {
  155. api.toast({
  156. msg: '电话号码格式不正确',
  157. duration: 2000,
  158. location: 'top'
  159. });
  160. return false;
  161. }
  162. if(phone !='' && vcode !=''){
  163. toast.loading({
  164. title: "加载中",
  165. duration: 2000
  166. });
  167. api.ajax({
  168. url: UrlRouter.setApi,
  169. method: 'post',
  170. headers : {
  171. "Authorization":"Bearer "+ token
  172. },
  173. data: {
  174. values: {
  175. mobile: phone,
  176. vcode: vcode
  177. }
  178. }
  179. },
  180. function(ret, err){
  181. if (ret) {
  182. if (ret.code === 0) {
  183. api.toast({
  184. msg: '绑定成功',
  185. duration: 2000,
  186. location: 'top'
  187. });
  188. api.sendEvent({
  189. name: 'myEvent',
  190. extra: {
  191. key1: 'value1',
  192. key2: 'value2'
  193. }
  194. });
  195. toast.hide();
  196. api.closeWin();
  197. }else if (ret.code === 4002) {
  198. api.toast({
  199. msg: '验证码超时或者错误',
  200. duration: 2000,
  201. location: 'top'
  202. });
  203. toast.hide();
  204. }else if (ret.code === 4001) {
  205. api.toast({
  206. msg: '缺少必要参数',
  207. duration: 2000,
  208. location: 'top'
  209. });
  210. }
  211. toast.hide();
  212. } else {
  213. api.toast({
  214. msg: '网络超时',
  215. duration: 2000,
  216. location: 'top'
  217. });
  218. }
  219. toast.hide();push
  220. });
  221. }else {
  222. api.toast({
  223. msg: '手机号或验证码不能为空',
  224. duration: 2000,
  225. location: 'top'
  226. });
  227. }
  228. }
  229. </script>