//页面逻辑
 (function(){
     /*公共变量*/
 var date = Date.parse(new Date());
 //加密
hash = hex_md5(""+'Y0UKA@2018'+date);
var validCode = true;//验证码标记
var time = 60;//倒计时
var telephoneReg = new RegExp(/^(1[3,4,5,7,8]{1}[\d]{9})/) ;   
//验证手机号
function validPhone(ele){
   var flag = true;
   if(!(/^1[34578]\d{9}$/.test(ele.val()))){
       alert("手机号错误啊！！")
       flag = false;
   }else{
       flag = true;
   }
   return flag;
}
  //点击获取手机验证码
 $(".wrap").on("click","#captchaButton",function(){
   var flag =true;
   var phone = $("#phone").val();
   if(!phone){
       alert("手机号不能为空！")
       flag = false;
   }else{
       flag = validPhone($("#phone"));
   }
   var code = $(this);
   if(flag){
       var content = {
           subMerchantCode:'',
           timestamp:date,
           sign:hash,
           mobile:phone,
           function:'1'
       }
       if(validCode){
           validCode = false;
            $.ajax({
                 url: 'http://39.107.124.166:8080/youka-api/api/user/getIdentifyCode',
                 data: content,
                 dataType: 'json',
                 type: 'POST',
                 success:function(data){
                     console.info("验证码")
                    console.info(data)
                   if(data.status == '2000'){
                       var t = setInterval(function() {
                           time--;
                           code.html(time + "s");
                           if (time == 0) {
                               clearInterval(t);
                               code.html("重新获取");
                               time = 60;
                               validCode = true;
                           }
                       }, 1000);
                   }
                 },
                error: function(data){  
                    
                } 

            });
   }
   }
});
       
    //点击提交按钮验证信息
    $("#submit").on("click",function(){
        var phone = $("#phone").val();
        var password = $("#password").val();
        var yzm = $("#yzm").val();
        if(phone == ""){
            alert("请输入手机号！");
            return false;
        }else if(!telephoneReg.test(phone)){
            alert("请输入正确的手机号！");
        }else if(password == ""){
            alert("请输入密码！");
            return false;
        }else if(password.length>12 || password.length<6){
            alert("请设置6-12位长度密码！");
            return false;
        }else if(yzm == ""){
            alert("请输入验证码！");
            return false;
        }else{
            var content = {
               subMerchantCode:'',
               timestamp:date,
               sign:hash,
               mobile:phone,
               newPassword:password,
               identityCode:yzm,
               function:'1',
//               recommendedMobile:''
           }
//           var params = {
//               'content':JSON.stringify(content)
//           };
            console.info("提交")
            console.info(content)
            $.ajax({
                 type: 'POST',
                 url: 'http://39.107.124.166:8080/youka-api/api/user/signUp',
                 data: content,
                 dataType: 'json',
                 success:function(data){
                    console.info(data)
                 },
                error: function(data){  
                    console.info("错误")
                    console.info(data)
                } 
            });
        }
    });
    
 })();