phoneRegister.html 15.3 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" />
</head>

<body class="forget-password-view phone-register-view">
    <div class="aui-content aui-margin-b-15">
        <header class="aui-bar aui-bar-nav" id="header">
            <a class="aui-btn aui-pull-left" tapmode onclick="closeWin()">
                <span class="aui-iconfont aui-icon-left"></span>
            </a>
            <div class="aui-title">注册</div>
        </header>
        <div class="aui-padded-l-15 aui-padded-r-15 aui-padded-t-15">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label-icon">
                            <img style="height:16px;" src="../image/yonghuming.png" />
                        </div>
                        <div class="aui-list-item-input">
                            <input type="text" id="username" class="aui-font-size-14" placeholder="我的姓名">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label-icon">
                            <img style="height:19px;" src="../image/shouji.png" />
                        </div>
                        <div class="aui-list-item-input">
                            <input type="number" id="phone" class="aui-font-size-14" placeholder="11位手机号码">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item forget-password-code">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label-icon">
                            <img style="height:16px;" src="../image/yanzhengma.png" />
                        </div>
                        <div class="aui-list-item-input">
                            <input type="number" id="phoneCode" class="aui-font-size-14" placeholder="输入验证码">
                        </div>
                    </div>
                    <div onclick="sendSmsCode(this);" class="get-code-btn">
                        获取验证码
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label-icon">
                            <img style="height:16px;" src="../image/mimahui.png" />
                        </div>
                        <div class="aui-list-item-input">
                            <input type="password" id="userpwd" class="aui-font-size-14" placeholder="设置登录密码">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label-icon">
                            <img style="height:16px;" src="../image/mimahui.png" />
                        </div>
                        <div class="aui-list-item-input">
                            <input id="userpwdRep" type="password" class="aui-font-size-14" placeholder="确认登录密码">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label-icon">
                            <img style="height:16px;" src="../image/dizhi.png" />
                        </div>
                        <div class="aui-list-item-input">
                            <input id="addr" type="text" class="aui-font-size-14" readonly placeholder="所属城市">
                        </div>
                        <div onclick="choseCity();" class="aui-pull-right tytx-color-b">
                            选择城市
                        </div>
                    </div>
                </li>
            </ul>
            <span class="submit-btn" onclick="register();">确定</span>
        </div>
    </div>
</body>

</html>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/addr.js"></script>
<script type="text/javascript" src="../script/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
    var header = $api.byId('header');
    fixStatusBar_API(header);
    apiready = function() {
      api.setStatusBarStyle({
          style: 'dark',
          color: 'rgba(0,0,0,0)'
      });
      api.parseTapmode();
          // api.openWin({ slidBackEnabled:false,
          //     name: 'index',
          //     url: './html/index.html',
          //     pageParam: {}
          // });
    }

            var sended = false;
            var chose_pro = '';
            var chose_city = '';
            function sendSmsCode(sender) {
                if (sended) {
                    return false;
                }
                var userphone = $api.trim($api.val($api.byId("phone")));
                var phonereg = /^[1][3,4,5,7,8][0-9]{9}$/;
                if (userphone == "" || !phonereg.test(userphone)) {
                    api.toast({
                        msg: "请输入正确的手机号"
                    });
                    return false;
                }
                api.showProgress({
                    style: 'default',
                    animationType: 'fade',
                    title: '请求验证码...',
                    text: '',
                    modal: true
                });
                var counter = 60; //60秒为一个周期
                $.ajax({
                    url: HOST + '/iot_api/v1/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: userphone
                    }),
                    complete: function() {
                        api.hideProgress();
                    },
                    success: function(ret) {
                        if (ret) {
                            if (ret.code == 0) {
                                api.toast({
                                    msg: '验证码发送成功!',
                                    duration: 2000,
                                    location: 'bottom'
                                });
                                cid = ret.data.cid;
                                sended = true;
                                remainder = setInterval(function() {
                                    if (counter == 0) {
                                        sended = false;
                                        $api.html(sender, "获取验证码");
                                        if (remainder) {
                                            clearInterval(remainder);
                                        }

                                    } else {
                                        $api.html(sender, counter + "秒");
                                        counter--;
                                    }

                                }, 1000)
                            } else {
                                api.toast({
                                    msg: "发送失败," + ajaxCodeCheck(ret.code, ret.msg, '请稍后再试')
                                });
                            }
                        }
                    },
                    error: function() {
                        api.toast({
                            msg: "发送失败,请稍候再试"
                        });
                    }
                });

            }

            function choseCity() {
                var UIActionSelector = api.require('UIActionSelector');
                UIActionSelector.open({
                    datas: subjson,
                    layout: {
                        row: 5,
                        col: 3,
                        height: 30,
                        size: 12,
                        sizeActive: 14,
                        rowSpacing: 5,
                        colSpacing: 10,
                        maskBg: 'rgba(0,0,0,0.2)',
                        bg: '#fff',
                        color: '#999',
                        colorActive: '#57A0EC',
                        colorSelected: '#57A0EC'
                    },
                    animation: true,
                    cancel: {
                        text: '取消',
                        size: 12,
                        w: 90,
                        h: 35,
                        bg: '#fff',
                        bgActive: '#ccc',
                        color: '#888',
                        colorActive: '#fff'
                    },
                    ok: {
                        text: '确定',
                        size: 12,
                        w: 90,
                        h: 35,
                        bg: '#5D93E4',
                        bgActive: '#5D93E4',
                        color: '#FFF',
                        colorActive: '#fff'
                    },
                    title: {
                        text: '选择所属城市',
                        size: 12,
                        h: 44,
                        bg: '#eee',
                        color: '#888'
                    },
                    fixedOn: api.frameName
                }, function(ret, err) {
                    if (ret && ret['eventType'] == "ok") {
                        chose_pro = ret['level1'];
                        chose_city = ret['level2'];
                        $api.val($api.byId("addr"), ret['level1'] + " " + ret['level2']);
                    }
                });

            }

            function register() {
                var username = $api.trim($api.val($api.byId("username")));
                if (username == "") {
                    api.toast({
                        msg: "请输入您的姓名"
                    });
                    return false;
                }
                var userphone = $api.trim($api.val($api.byId("phone")));
                var phonereg = /^[1][3,4,5,7,8][0-9]{9}$/;
                if (userphone == "" || !phonereg.test(userphone)) {
                    api.toast({
                        msg: "请输入正确的手机号"
                    });
                    return false;
                }
                var phonecode = $api.trim($api.val($api.byId("phoneCode")));
                if (phonecode == "") {
                    api.toast({
                        msg: "请输入您收到的验证码"
                    });
                    return false;
                }
                var userpwd = $api.val($api.byId("userpwd"));
                if (userpwd == "" || userpwd.length < 6) {
                    api.toast({
                        msg: "密码长度不得少于6位"
                    });
                    return false;
                }
                var userpwdrep = $api.val($api.byId("userpwdRep"));
                if (userpwd != userpwdrep) {
                    api.toast({
                        msg: "两次密码输入不一致"
                    });
                    return false;
                }
                if(chose_pro == '' || chose_city == ''){
                  api.toast({
                      msg: "请选择所属城市"
                  });
                  return false;
                }
                api.showProgress({
                    style: 'default',
                    animationType: 'fade',
                    title: '正在注册中...',
                    text: '',
                    modal: true
                });
                $.ajax({
                    url: HOST + '/iot_api/v1/app/register',
                    type: 'POST',
                    dataType: 'json',
                    headers: {
                        'Content-Type': 'application/json;charset=utf-8',
                        'imei': api.deviceId
                    },
                    data: JSON.stringify({
                        phone: userphone,
                        password: userpwd,
                        name: username,
                        cid: cid,
                        code: phonecode,
                        province: chose_pro,
                        city: chose_city
                    }),
                    complete: function() {
                        api.hideProgress();
                    },
                    success: function(ret) {
                        if (ret) {
                            if (ret.code == 0) {
                                api.toast({
                                    msg: '注册成功,即将跳转到登陆',
                                    duration: 2000,
                                    location: 'bottom'
                                });
                                setTimeout(function() {
                                    // api.openFrame({historyGestureEnabled :false,
                                    //     reload: true,
                                    //     //name: 'index',
                                    //     url: 'login.html',
                                    //     rect: {
                                    //         x: 0,
                                    //         y: 0,
                                    //         w: 'auto',
                                    //         h: 'auto'
                                    //     },
                                    //     allowEdit:true
                                    // });
                                    // api.closeFrame({
                                    //     name: 'login'
                                    // });
                                    // api.closeFrame({
                                    //     name: 'phoneRegister'
                                    // });
                                    api.closeWin({
                                        name: 'phoneRegister'
                                    });


                                }, 2000);

                            } else {
                                api.toast({
                                    msg: "注册失败," + ajaxCodeCheck(ret.code, ret.msg, '请确认注册信息是否正确')
                                });
                            }
                        }
                    },
                    error: function() {
                        api.toast({
                            msg: "注册失败,请稍候再试"
                        });
                    }
                });
            }
</script>