123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- var qs = parseQueryString(window.location.href),user_id;
- var request = '';
- $().ready(function(){
- console.log(getCookie('user_id'))
- if(getCookie('user_id')){
- user_id = getCookie('user_id')
- userAuth();//检查用户信息完整性 和 用户信息审核结果
- }
- })
- //取Cookie的值
- function getCookie(name) {
- var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
- if (arr = document.cookie.match(reg)){
- return arr[2];
- }else{
- return false
- }
- }
- //写入到Cookie
- //name:cookie名称 value:cookie值
- function setCookie(name,value){
- var exp = new Date();
- exp.setTime(exp.getTime() + 12 * 60 * 60000);//过期时间 12小时
- // exp.setTime(exp.getTime() + 60 * 10000);//过期时间 10分钟
- document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
- }
-
- function registerButton () {
- //注册
- var phoneNumber = $("#phone").val();
- var codeYzm = $("#yzm").val();
- if(phoneNumber.length != 11){
- showMsg('请正确填写手机号')
- return;
- }
- if(codeYzm.length == 0){
- showMsg('请输入手机验证码')
- return;
- }
- $(".loading").show();
- $.ajax({
- type: 'post',
- url: request + '/api/register',
- data:{
- 'mobile':$("#phone").val(),
- 'code':$("#yzm").val()
- },
- success: function (res) {
- $(".loading").hide();
- console.log(res)
- if(res.status == 200){
- setCookie('user_id',res.user_id)
- if(res.user_info_is_full == 1){
- //用户信息是否完整 0: 不完整 1: 完整
- if(res.user_auth_status == 1){ //1: 审核通过, 2, 审核中, 3审核不通过
- window.location.href = 'mySigning.html?user_id=' + res.user_id
- }else if(res.user_auth_status == 2){
- window.location.href='examine.html?type=' + 1 + '&user_id=' + res.user_id;
- }else if(res.user_auth_status == 3){
- window.location.href='examine.html?type=' + 2 + '&user_id=' + res.user_id + '&reason=' + encodeURI(res.user_auth_deny_cause);
- }
- }else{
- window.location.href = 'perfectInfo.html?user_id=' + res.user_id
- }
- }else{
- showMsg(res.msg)
- }
- },
- fail: function () {
- showMsg('网络错误,请稍后再试~')
- $(".loading").hide();
- }
- })
- }
- function getYzmEvent () {
- //获取验证码
- var phoneNumber = $("#phone").val();
- if(phoneNumber.length != 11){
- showMsg('请正确填写手机号')
- return;
- }
- if($(".inputDiv .yzmButton").attr('class').indexOf('yzmButtonActive') != -1){
- return;
- }
- sendCms();
- }
- function sendCms () {
- //发送验证码
- $(".loading").show();
- $.ajax({
- type: 'post',
- url: request + '/api/register/sendCms',
- data:{
- 'mobile':$("#phone").val(),
- },
- success: function (res) {
- $(".loading").hide();
- console.log(res)
- if(res.status == 200){
- $(".inputDiv .yzmButton").addClass('yzmButtonActive');
- var downCount = 60;
- var time = setInterval(function () {
- $(".inputDiv .yzmButton").html(downCount + 's');
- downCount--;
- if(downCount < 0){
- clearInterval(time);
- $(".inputDiv .yzmButton").removeClass('yzmButtonActive');
- $(".inputDiv .yzmButton").html('获取验证码');
- }
- },1000)
- }else{
- showMsg(res.msg)
- }
- },
- fail: function () {
- showMsg('网络错误,请稍后再试~')
- $(".loading").hide();
- }
- })
- }
- function userAuth () {
- //发送验证码
- $(".loading").show();
- $.ajax({
- type: 'post',
- url: request + '/api/user/auth',
- data:{
- 'user_id':user_id
- },
- success: function (res) {
- $(".loading").hide();
- console.log(res)
- if(res.status == 200){
- if(res.data.user_info_is_full == 1){
- //用户信息是否完整 0: 不完整 1: 完整
- if(res.data.user_auth_status == 1){ //1: 审核通过, 2, 审核中, 3审核不通过
- window.location.href = 'mySigning.html?user_id=' + res.data.user_id
- }else if(res.data.user_auth_status == 2){
- window.location.href='examine.html?type=' + 1 + '&user_id=' + res.data.user_id;
- }else if(res.data.user_auth_status == 3){
- window.location.href='examine.html?type=' + 2 + '&user_id=' + res.data.user_id + '&reason=' + encodeURI(res.data.user_auth_deny_cause);
- }
- }else{
- window.location.href = 'perfectInfo.html?user_id=' + res.data.user_id
- }
- }else{
- showMsg(res.msg)
- }
- },
- fail: function () {
- showMsg('网络错误,请稍后再试~')
- $(".loading").hide();
- }
- })
- }
- //获取地址栏参数
- function parseQueryString(url) {
- var urlObj = {};
- var reg = /([^?=&]+)=([^?=&]+)/g;
- url.replace(reg, function($0, $1, $2) {
- urlObj[$1] = decodeURIComponent($2);
- })
- return urlObj;
- }
- // 展示错误提示信息
- function showMsg(msg) {
- var msgBox = document.getElementsByClassName('alert-info')[0];
- msgBox.getElementsByTagName("p")[0].innerHTML=msg;
- msgBox.style.display="block";
- setTimeout(function() {
- msgBox.style.display="none";
- }, 2000);
- }
|