$(function(){function e(e){return e?($("[name] input, [name] select, [name] textarea").each(e.profile?function(){var t=$(this).parent(".input-group").attr("name");("feedback"!==t&&!e.profile[t]||"feedback"===t&&e.profile.has_feedback!==!0)&&$(this).parent(".input-group").show(400)}:function(){$(this).parent(".input-group").show(400)}),void $(".input-group.submit").show()):($(".form .get-code").show(),void $(".input-group").css("display",""))}function t(){if(n($('[name="code"] input')[0],!0))return void e();var t=$('[name="phone"] [subname="phone_number"]').attr("data-phone-number");$('[name="code"] input').parent(".input-group").removeClass("success error");var a=f[[t,$('[name="code"] input').val()]];a?"object"==typeof a?($('[name="code"] input').parent(".input-group").addClass("success").find(".info").text("正确"),e(a)):($('[name="code"] input').parent(".input-group").addClass("error").find(".info").text(a),e()):e()}function n(e,t){var n,a=$(e).val();if((a||"").trim()){var r=$(e).attr("data-pattern");"phone_number"===$(e).attr("subname")&&(a=$(e).attr("data-phone-number")),r&&!new RegExp(r).test(a)&&(n="格式错误")}else $(e).attr("required")&&(n="未填写");return t||n&&($(e).parent(".input-group").hasClass("error")?$(e).parent(".input-group").find(".info").text(n):($(e).parent(".input-group").removeClass("error success").find(".info").text(""),setTimeout(function(){$(e).parent(".input-group").addClass("error").find(".info").text(n)},10))),n}function a(){var e=!0,a={channel:u};return $(".input-group").removeClass("error success"),$("[name] input, [name] select, [name] textarea").each(function(){if($(this).is(":hidden"))return null;var t=$(this).parent(".input-group").attr("name");"phone"===t&&(t=$(this).attr("subname")),n(this)?e=!1:a[t]=$(this).val(),$(this).parent(".input-group").removeClass("error").find(".info").text("")}),l.save(a),a.phone_number&&(a.phone="86"===a.area_number?a.phone_number:a.area_number+a.phone_number),delete a.area_number,delete a.phone_number,t(),e?a:null}function r(){clearInterval(g),h.save(null),$(".input-group.verify-code").removeClass("waiting"),$(".input-group.verify-code").find(".info").text(""),$('[name="phone"] input').attr("readonly",!1),$('[name="phone"] select').removeAttr("disabled")}function o(e){var t=$('[name="phone"] [subname="phone_number"]').attr("data-phone-number");e||(e=Date.now(),h.save({start:e,contact:t}));var n=Math.floor(60-(Date.now()-e)/1e3);if(0>=n)return void r();var a=$(".input-group.verify-code");a.addClass("waiting"),a.find(".countdown").text(n+" 秒后重试"),$('[name="phone"] input').attr("readonly",!0),$('[name="phone"] select').attr("disabled","disabled"),g=setInterval(function(){n=Math.floor(60-(Date.now()-e)/1e3),0>=n?r():a.find(".countdown").text(n+" 秒后重试")},1e3)}function i(){$(".form .submit").removeClass("waiting"),$("[name] input,[name] select").removeAttr("disabled")}var s,u="demo",p={channel:u},c={886:"^8869\\d{8}$",852:"^852[569]\\d{7}$",853:"^8536\\d{7}",86:"^1(\\d[-\\s]?){10}$","default":"^1(\\d){10}$"};$.post("/api/passport/whoami",p,function(e){200===e.status?(s=e.data.profile,$("main .register-panel").show()):$("main .login-panel").show()});var f={},d="sensordata_user_0.1",l={fetch:function(){try{return JSON.parse(sessionStorage[d]||"{}")}catch(e){return{}}},save:function(e){try{e?sessionStorage[d]=JSON.stringify(e):delete sessionStorage[d]}catch(t){}},init:function(){var e=this.fetch();e&&$("[name] input,[name] select").each(function(){var t=$(this).parent(".input-group").attr("name");e[t]&&$(this).val(e[t])})}};l.init();var m="sensordata_verify_0.2",h={fetch:function(){try{return JSON.parse(localStorage[m]||"{}")}catch(e){return{}}},save:function(e){try{e?localStorage[m]=JSON.stringify(e):delete localStorage[m]}catch(t){}},init:function(){var e=this.fetch();e.start&&(e.contact&&$('[name="phone"] input').val(e.contact),o(e.start))}};h.init(),$("[name] input, [name] select, [name] textarea").on("focusout",function(){var e=$(this).attr("name");$(this).parent(".input-group").hasClass("waiting")||"industry"!==e&&n(this)}).on("focusin",function(){$(this).parent(".input-group").hasClass("waiting")||$(this).parent(".input-group").removeClass("error success").find(".info").text("")}).keyup(function(e){13===e.keyCode&&$(this).parent(".input-group").next(".input-group").find("input,select").focus()}),$('[name="code"] input').on("focusout input",function(){if(n(this,!0))return void e();var a=this,r=$('[name="phone"] [subname="phone_number"]').attr("data-phone-number"),o=[r,$('[name="code"] input').val()];if(f[o])return void t();var i=$(a).val();$.getJSON("/api/passport/sms/verify/"+$('[name="phone"] input').val()+"/"+i,function(e){return 200===e.status?(f[o]=e.data,t(),void("undefined"!=typeof sa&&sa.track("verify_cellphone_code",{info:i,result:"正确"}))):(f[o]="错误",t(),void("undefined"!=typeof sa&&sa.track("verify_cellphone_code",{info:i,result:e.desc})))})}),$("[name] input").on("input",function(){$(this).parent(".input-group").removeClass("error success").find(".info").text(""),t()}),$('[name="phone"] input').off("input.phone").on("input.phone",function(e){var n=e.target.value,a=$(".phone-number").children("select").val();$(this).attr("data-phone-number",("86"===a?"":a)+n),t()}),$('[name="phone"] select').off("change.phone").on("change.phone",function(e){var a=e.target.value,r=$(".phone-number").children("input").val();$('[name="phone"] input').attr("data-phone-number",("86"===a?"":a)+r).attr("data-pattern",c[a]||c.default),$('[name="phone"] input').val().length>0&&n($('[name="phone"] input')),t()});var v=$('[name="phone"] input, [name="phone"] select');$('[name="phone"] input').off("focusin.phone").on("focusin.phone",function(){v.addClass("focus-active")}).on("focusout.phone",function(){v.removeClass("focus-active")}),$('[name="phone"] select').off("focusin.area").on("focusin.area",function(){v.addClass("focus-active")}).on("focusout.phone",function(){v.removeClass("focus-active")}),$("[name] select").on("change",function(){$(this).parent(".input-group").removeClass("error success").find(".info").text("")}),$('[name="code"] input').val()&&$('[name="code"] input').trigger("input"),$('[name="industry"] input').on("click",function(){$(".multi-area").toggle()}).on("blur",function(){setTimeout(function(){$(".multi-area").hide(),n($('[name="industry"] input'))},500)}),$(".multi-area label").on("click",function(){var e=$(this).text();$('[name="industry"] input').val(e),$(this).parents(".input-group").removeClass("error success").find(".info").text("")});var g;$(".form .get-code").click(function(){var e=$('[name="phone"] [subname="phone_number"]').attr("data-phone-number");if(n($('[name="phone"] input')[0]))return void("undefined"!=typeof sa&&sa.track("click_send_cellphone",{info:e,result:"手机号格式错误"}));var t={contact:e};try{t.distinct_id=sa.store._state.distinct_id,t.referrerUrl=sa.store._state.props.$latest_referrer,t.referrHostUrl=sa.store._state.props.$latest_referrer_host}catch(a){t.distinct_id="Unknown",t.referrerUrl="Unknown",t.referrHostUrl="Unknown"}$.getJSON("/api/passport/sms/quest_new/"+$('[name="phone"] input').val(),function(t){200===t.status?(f={},o(),$('[name="code"] input').focus()):$(".form .submit").find("input").val(t.desc),"undefined"!=typeof sa&&sa.track("click_send_cellphone",{info:e,result:t.desc})})}),$(".form .submit input").click(function(){var e=a();e&&(e.redirect_uri="https://sfdemo.cloud.sensorsdata.cn/api/oauth/auth?project=default&oauth_type=oauth",e.client_id="sa0jy5y541gvur",e.requestBtn=u,$(".form .submit").addClass("waiting"),$(".form .submit").find("input").val("提交中..."),$("[name] input,[name] select").attr("disabled","disabled"),$.ajax({type:"POST",url:"/api/passport/user/login",data:e,dataType:"json",success:function(t){200===t.status?($(".form .submit").find("input").val("提交成功"),delete e.distinct_id,"undefined"!=typeof sa&&sa.track("formSubmit",$.extend({requestBtn:u,isCreated:!!t.data.created,isSuccess:!0},e)),setTimeout(function(){location.href="#do12"},300)):($(".form .submit").find("input").val(t.desc||"提交失败"),i(),delete e.distinct_id,"undefined"!=typeof sa&&sa.track("errorSubmit",$.extend({requestBtn:u,problem:JSON.stringify(arguments)},e)))},error:function(){$(".form .submit").find("input").val("提交失败"),i(),delete e.distinct_id,"undefined"!=typeof sa&&sa.track("errorSubmit",$.extend({requestBtn:u,problem:JSON.stringify(arguments)},e))}}))})});