123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- mui.ready(function() {
-
-
- var phoneName = document.getElementById("username");
- var setCode = document.getElementById("set-code");
- var obtainCode = document.getElementById("obtain-code");
- var bdButtn = document.getElementById("bdbuttn");
- var phoneCode = false;
- var state;
- var userId;
- mui.plusReady(function() {
-
-
- mui('.maincon').on('keyup', "#username,#set-code", function() {
- hideButtn(phoneName,setCode,bdButtn,"frmactiveok");
- });
-
- obtainCode.addEventListener('tap', function() {
- phoneVal();
- })
-
- bdButtn.addEventListener('tap', function() {
- codeVal();
- })
-
- function phoneVal() {
- var hunPhone = /^1[3|4|5|7|8]\d{9}$/;
- if(hunPhone.test(phoneName.value)) {
- isReg();
- } else {
- plus.nativeUI.toast("请输入正确的手机号码", toastStyle);
- return;
- }
- }
-
- function isReg() {
-
- mui.ajax(baseUrl + '/ajax/isReg?key=' + phoneName.value, {
- dataType: 'json',
- type: 'GET',
- timeout: 10000,
- async: false,
- success: function(data) {
- console.log(data.data);
- if(data.data == false) {
- plus.nativeUI.toast("您的手机已被绑定", toastStyle);
- return;
- } else {
- phoneCode = true;
- if(phoneCode){
- sendAuthentication();
- }
- }
- },
- error: function() {
- plus.nativeUI.toast("服务器链接超时", toastStyle);
- }
- });
- }
-
- function sendAuthentication() {
- userId = plus.storage.getItem('userid');
- mui.ajax(baseUrl + '/ajax/vcWithBind', {
- data: {
- mobilePhone: phoneName.value,
- userid:userId
- },
- dataType: 'json',
- type: 'get',
- async: false,
- timeout: 10000,
- success: function(data) {
- console.log(data.success);
- if(data.success) {
- state = data.data;
- doClick();
- }
- },
- error: function() {
- plus.nativeUI.toast("服务器链接超时", toastStyle);
- return;
- }
- })
- }
-
- function doClick() {
- var getCodeOff = document.getElementById("getcodeoff");
- obtainCode.style.display = "none";
- getCodeOff.style.display = "block";
- getCodeOff.innerHTML = "30s后重新获取";
- var clickTime = new Date().getTime();
- var Timer = setInterval(function() {
- var nowTime = new Date().getTime();
- var second = Math.ceil(30 - (nowTime - clickTime) / 1000);
- if(second > 0) {
- getCodeOff.innerHTML = second + "s后重新获取";
- } else {
- clearInterval(Timer);
- obtainCode.style.display = "block";
- getCodeOff.style.display = "none";
- obtainCode.innerHTML = "获取验证码";
- }
- }, 1000);
- }
-
- function codeVal() {
- mui.ajax(baseUrl + '/ajax/validCode', {
- data: {
- "state": state,
- "vc": setCode.value
- },
- dataType: 'json',
- async: false,
- type: 'POST',
- timeout: 10000,
- success: function(data) {
- if(data.success) {
- if(data.data) {
- bdOK();
- }else{
- plus.nativeUI.toast("验证码不正确", toastStyle);
- return;
- }
- }else{
- console.log(data.msg);
- if(data.msg=="验证超时"){
- plus.nativeUI.toast("验证码超时", toastStyle);
- return;
- }else{
- plus.nativeUI.toast("请填写正确的手机号,验证码", toastStyle);
- return;
- }
-
- }
- },
- error: function() {
- plus.nativeUI.toast("服务器链接超时", toastStyle);
- return;
- }
- })
- }
-
- function bdOK(){
- console.log(state);
- console.log(userId);
- console.log(phoneName.value);
- console.log(setCode.value);
- mui.ajax(baseUrl + '/ajax/bindMobilePhone', {
- data: {
- state:state,
- userid:userId,
- mobilePhone:phoneName.value,
- validateCode:setCode.value
- },
- dataType: 'json',
- type: 'POST',
- async: false,
- timeout: 10000,
- success: function(data) {
- console.log(data.success);
- console.log(data.data);
- if(data.success && data.data) {
- plus.nativeUI.toast("手机绑定成功", toastStyle);
- var securityPage = plus.webview.getWebviewById('../html/security.html');
- mui.fire(securityPage,'xsphone', {
- phonetel:phoneName.value
- });
- mui.back();
- }else{
- plus.nativeUI.toast("手机绑定失败", toastStyle);
- return;
- }
- },
- error: function() {
- plus.nativeUI.toast("服务器链接超时", toastStyle);
- return;
- }
- })
- }
- });
- });
|