register_frm.html 8.64 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>register_frm</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/register.css"/>
      <style>
          html,
          body{
            background-color: #F4F6F9;
          }
      </style>
  </head>
  <body>
    <div class="form-panel">
      <div class="aui-list" style="border-radius:8px;">
        <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/login_icon_user.png" style="height:24px;width:24px;margin-top:-0.2rem;"/>
          </div>
          <div class="aui-list-item-center">
            <input id="register_name" class="aui-input input-style-normal" type="text" placeholder="用户名" style="height:3.3rem;border-bottom:1px solid #F0F5FF;margin-right:15px;">
          </div>
        </div>
        <div class="aui-list-item" style="border-bottom: none;background-size: 100% 0px;margin-top:-1rem;">
            <div class="aui-list-item-left">
              <img src="../../image/login/login_icon_pohone.png" style="height:24px;width:24px;margin-top:-0.2rem;"/>
            </div>
            <div class="aui-list-item-center">
                <input id="register_phone" class="aui-input input-style-normal" type="tel" placeholder="11位手机号" style="height:3.3rem;border-bottom:1px solid #F0F5FF;margin-right:15px;">
            </div>
        </div>
        <div class="aui-list-item" style="border-bottom: none;background-size: 100% 0px;margin-top:-1rem;">
            <div class="aui-list-item-left">
              <img src="../../image/login/login_icon_captcha.png" style="height:24px;width:24px;margin-top:-0.2rem;"/>
            </div>
            <div class="aui-list-item-center">
                <input id="register_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 class="aui-list-item" style="border-bottom: none;background-size: 100% 0px;margin-top:-1rem;">
            <div class="aui-list-item-left">
              <img src="../../image/login/login_icon_password.png" style="height:24px;width:24px;margin-top:-0.2rem;"/>
            </div>
            <div class="aui-list-item-center">
                <input id="register_pwd" class="aui-input input-style-normal" type="text" placeholder="设置登录密码" 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/login_icon_repassword.png" style="height:24px;width:24px;margin-top:-0.2rem;"/>
            </div>
            <div class="aui-list-item-center">
                <input id="register_repwd" class="aui-input input-style-normal" type="text" placeholder="确认登录密码" style="height:3.3rem;border-bottom:1px solid #F0F5FF;margin-right:15px;">
            </div>
        </div>
      </div>
    </div>


    <div style="margin-left:15px;margin-right:15px;margin-top:15px;">
      <span onclick="handleRgister();" id="loginBtn" class="register-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 cooldown = 0;
    var cid;

    apiready = function(){
      api.parseTapmode();
    };


    function sendCode() {
      if (cooldown === 0) {
        getTextCode();
      }
    }

    //获取验证码
    function getTextCode() {
      var input_phone_dom = $api.byId("register_phone");
      input_phone_dom.blur();
      var inputed_phone = $api.trim($api.val($api.byId("register_phone")));
      if (!checkPhone(inputed_phone)) {
        api.toast({
            msg: "请输入正确的手机号"
        });
        return;
      }else {
        $.ajax({
            url: HOST + '/iot_api/v2/app/send_sms_need_phone_no_exist',
            type: 'POST',
            dataType: 'json',
            headers:{
                'Content-Type':'application/json;charset=utf-8',
                'imei':api.deviceId
            },
            data: JSON.stringify({
                phone: inputed_phone
            }),
            success: function(ret) {
              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: "发送失败,请稍候再试"
                });
              }
            },
            error: function() {
              api.toast({msg: ERR_MSG,duration: 2000,location: 'bottom'});
            }
        });
      }
    }

    //发送验证码倒数计时器
    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 handleRgister() {
      var register_name = $api.trim($api.val($api.byId("register_name")));
      var register_phone = $api.trim($api.val($api.byId("register_phone")));
      var register_code = $api.trim($api.val($api.byId("register_code")));
      var register_pwd = $api.trim($api.val($api.byId("register_pwd")));
      var register_repwd = $api.trim($api.val($api.byId("register_repwd")));
      if ( register_name == '' ) {
        api.toast({msg: '请输入您的姓名',duration: 2000,location: 'bottom'});return;
      }
      if (!checkPhone(register_phone)) {
        api.toast({msg: "请输入正确的手机号"});return;
      }
      if ( register_code == '' ) {
        api.toast({msg: '验证码不可为空',duration: 2000,location: 'bottom'});return;
      }
      if ( register_pwd == '' || register_pwd.length < 6) {
        api.toast({msg: '密码长度不得少于6位',duration: 2000,location: 'bottom'});return;
      }
      if ( register_repwd != register_pwd ) {
        api.toast({msg: '两次密码不一致',duration: 2000,location: 'bottom'});return;
      }
      api.showProgress({
        style: 'default',
        animationType: 'zoom',
        title: '正在注册中...',
        text: '',
        modal: true
      });

      $.ajax({
          url: HOST + '/iot_api/v2/app/register',
          type: 'POST',
          dataType: 'json',
          headers:{
              'Content-Type':'application/json;charset=utf-8',
              'imei':api.deviceId
          },
          data: JSON.stringify({
            phone: register_phone,
            password: register_pwd,
            name: register_name,
            cid: cid,
            code: register_code
          }),
          success: function(ret) {
            if (ret.code == 0) {
              api.hideProgress();
              api.toast({msg: '注册成功',duration: 2000,location: 'bottom'});
              api.sendEvent({
                  name: 'showPhone',
                  extra: {
                    phone:  register_phone
                  }
              });
              api.closeWin();
            }else {
              api.toast({msg: '注册失败',duration: 2000,location: 'bottom'});
            }
          },
          error: function() {
              api.toast({msg: ERR_MSG,duration: 2000,location: 'bottom'});
          }
      });      

    }
  </script>
  </html>