check_target_phone_frm.html 6.71 KB
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>重新绑定的手机号-发送验证码</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/login/forgetPassword.css"/>
    <style>
      html,
      body{
        background-color: #F4F6F9;
      }
    </style>
</head>
<body>
  <div style="margin-top:20px;margin-left:15px;">
    <i class="aui-iconfont aui-icon-info tip-panel">
    </i>
    <span class="tip-title">为了您的账号安全,请先进行账号验证</span>

  </div>
  <div class="form-panel">
    <div class="aui-list" style="border-radius:16px;">
      <div class="aui-list-item" style="border-bottom: none;background-size: 100% 0px;margin-top:-0.5rem;">
          <div class="aui-list-item-left">
            <img src="../../image/login_icon_pohone.png" style="height:24px;width:24px;margin-top:-0.1rem;"/>
          </div>
          <div class="aui-list-item-center">
            <input id="phone" class="aui-input input-style-normal" type="tel" placeholder="+86 | 请输入新号码" style="height:3.3rem;border-bottom:1px solid #F0F5FF;margin-right:15px;">
          </div>
      </div>
      <div class="aui-list-item" style="margin-top:-1rem;margin-bottom:-1rem;">
          <div class="aui-list-item-left">
            <img src="../../image/login_icon_captcha.png" style="height:24px;width:24px;margin-top:-0.1rem;"/>
          </div>
          <div class="aui-list-item-center">
              <input id="code" class="aui-input input-style-normal" type="text" placeholder="手机验证码" style="height:3.3rem;border-bottom:1px solid #F0F5FF;">
          </div>
          <div class="aui-list-item-right">
            <div class="aui-btn send-code-btn code-btn-disable" tapmode onclick="sendCode();"><span id='sms-text'>获取验证码</span></div>
          </div>
      </div>
    </div>
  </div>
  <div style="margin-left:15px;margin-right:15px;margin-top:15px;">
    <span tapmode onclick="next();" class="next-btn">确认</span>
  </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
    var userId;
    var token;
    apiready = function(){
      api.parseTapmode();
      token = $api.getStorage('userToken');
      userId = $api.getStorage('userID');
      api.sendEvent({
          name: 'changePhoneTitle',
          extra: {
              title: '新号码验证'
          }
      });

    };

    function sendCode() {
      var inputed_phone = $api.trim($api.val($api.byId("phone")));
      if (!checkPhone(inputed_phone)) {
        api.toast({
            msg: "请输入正确的手机号"
        });
        return;
      }else {
        api.ajax({
            url: HOST+'/iot_api/v1/app/send_sms_need_phone_no_exist',
            method: 'post',
            headers: {
              'Content-Type': 'application/json;charset=utf-8',
              'imei': api.deviceId
            },
            data: {
              body: {
                phone: inputed_phone
              }
            }
        }, function(ret, err) {
          if (ret) {
            if (ret.code == 0) {
              api.toast({
                  msg: '验证码发送成功!',
                  duration: 2000,
                  location: 'bottom'
              });
              cid = ret.data.cid;
              console.log(cid);
              cooldown = 60;
              Cooldown();
            } else {
              api.toast({
                  msg: "发送失败," + ajaxCodeCheck(ret.code, ret.msg,"")
              });
            }
          } else {
            api.toast({
                msg: "发送失败,请稍候再试"
            });
          }
        });
      }
    }

    //发送验证码倒数计时器
    function Cooldown() {
      var obj = $api.byId("sms-text");
      $api.html(obj, cooldown+'s后重发');
      if (cooldown <=0) {
        $api.html(obj, '发送验证码');
      }else {
        cooldown = cooldown-1;
        window.setTimeout('Cooldown()',1000);
      }
    }

    function next() {
      var phone_dom = $api.byId("phone");
      var code_dom = $api.byId("code");
      phone_dom.blur();
      code_dom.blur();
      var inputed_phone = $api.trim($api.val($api.byId("phone")));
      var inputed_code = $api.trim($api.val($api.byId("code")));
      if (inputed_code == '') {
        api.toast({
            msg: "请输入正确的手机号"
        });
        return;
      }
      if (!checkPhone(inputed_phone)) {
        api.toast({
            msg: "请输入正确的手机号"
        });
        return;
      }else {
        //进行验证码验证
        console.log(JSON.stringify({
          user_id: userId,
          cid: cid,
          code: inputed_code,
          phone: inputed_phone
        }));
        api.ajax({
            url: HOST + '/iot_api/v1/app/change_phone_user',
            method: 'post',
            headers: {
              'Content-Type': 'application/json;charset=utf-8',
              token: token
            },
            data: {
              body: {
                user_id: userId,
                cid: cid,
                code: inputed_code,
                phone: inputed_phone
              }
            }
        }, function(ret, err) {
          if (ret.code == 0) {
            api.openWin({
                name: 'change_phone_success',
                url: './change_phone_success.html',
                slidBackEnabled: false,
                pageParam: {
                    phone: inputed_phone
                }
            });

            // var ajpush = api.require("ajpush");
            // api.showProgress({
            //     style: 'default',
            //     animationType: 'fade',
            //     title: '正在退出...',
            //     text: '',
            //     modal: true
            // });
            //
            // clearPush(ajpush, function(){
            //   $api.clearStorage();
            //   //补充基础的缓存数据
            //   initHeaderH();
            //   check();
            //   api.hideProgress();
            //
            // })
          }else {
            api.toast({ msg: ret.msg,duration: 2000,location: 'bottom'});
          }
        });
        //---

      }
    }
</script>
</html>