Nenhuma Descrição

login.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. var id = '';//产品id
  2. var countDown = '',count_down = '';
  3. var qs = parseQueryString(window.location.href);
  4. $().ready(function () {
  5. if(qs.id){
  6. id = qs.id
  7. }
  8. })
  9. //点击获取验证码
  10. function getYzmEvent () {
  11. var myreg = /^[0-9]{11}$/;
  12. if (!myreg.test($("#phone").val())) {
  13. //手机号码未填写及填写不正确
  14. showMsg('请正确填写手机号')
  15. return;
  16. }
  17. $("#mask").css({'visibility': 'visible'});
  18. $('#picCode .modal-inner img').attr("src", "/user/VerifyImage/getImageCode?phone=" + $("#phone").val())
  19. // registerEvent();
  20. }
  21. /* 点击更换图片验证码*/
  22. function getChangeCodeImg(){
  23. $('#picCode .modal-inner img').attr("src", "/user/VerifyImage/getImageCode?phone=" + $("#phone").val());
  24. }
  25. /*//关闭弹层*/
  26. function closePanel(){
  27. $('#mask').css({'visibility': 'hidden'});
  28. $("#imgYzm").val('');
  29. }
  30. // 输入图片验证码后点击确定请求短信验证码
  31. function goResPanel(){
  32. if($("#imgYzm").val() == ''){
  33. showMsg('请输入图片验证码')
  34. return;
  35. }
  36. registerSecond();
  37. }
  38. //发送短信验证码
  39. function registerSecond () {
  40. $.ajax({
  41. type:"post",
  42. url:"/user/user/registerSecond",
  43. dataType:'json',
  44. data:{
  45. phone:$("#phone").val(),
  46. smstype:1,
  47. qrcode:2,
  48. image_code:$("#imgYzm").val()
  49. },
  50. success:function (res){
  51. console.log(res)
  52. if(res && res.errno == 0){
  53. closePanel();
  54. countDown = res.rst.wait_time;
  55. count_down = countDown;
  56. var that = this;
  57. $("#getYzm").attr("disabled","true").css('background','#ccc');
  58. $("#getYzm").html(count_down);
  59. count_down = count_down-1;
  60. var time = setInterval(function () {
  61. $("#getYzm").html(count_down);
  62. count_down--;
  63. if(count_down < 0){
  64. $("#getYzm").removeAttr("disabled")
  65. .html('获取')
  66. .css('background','#32BD60');
  67. clearInterval(time);
  68. count_down = countDown;
  69. }
  70. },1000)
  71. }else{
  72. showMsg(res.err)
  73. }
  74. }
  75. });
  76. }
  77. //发送短信验证码
  78. //function registerEvent () {
  79. // $.ajax({
  80. // type:"post",
  81. // url:"/user/user/register",
  82. // dataType:'json',
  83. // data:{
  84. // phone:$("#phone").val(),
  85. // smstype:1,
  86. // qrcode:2,
  87. // source:'40013'
  88. // },
  89. // success: function (res){
  90. // console.log(res)
  91. // if(res && res.errno == 0){
  92. // countDown = res.rst.wait_time;
  93. // count_down = countDown;
  94. // var that = this;
  95. // $("#getYzm").attr("disabled","true").css('background','#ccc');
  96. // $("#getYzm").html(count_down);
  97. // count_down = count_down-1;
  98. // var time = setInterval(function () {
  99. // $("#getYzm").html(count_down);
  100. // count_down--;
  101. // if(count_down < 0){
  102. // $("#getYzm").removeAttr("disabled")
  103. // .html('获取')
  104. // .css('background','#32BD60');
  105. // clearInterval(time);
  106. // count_down = countDown;
  107. // }
  108. // },1000)
  109. // }else{
  110. // showMsg(res.err)
  111. // }
  112. // }
  113. // });
  114. //}
  115. //登录
  116. function loginEvent () {
  117. var myreg = /^[0-9]{11}$/;
  118. if (!myreg.test($("#phone").val())) {
  119. //手机号码未填写及填写不正确
  120. showMsg('请正确填写手机号')
  121. return;
  122. }
  123. if($("#yzm").val() == ""){
  124. showMsg('请输入短信验证码')
  125. return;
  126. }
  127. loginCodeEvent();
  128. }
  129. //短信验证码登录
  130. function loginCodeEvent () {
  131. $.ajax({
  132. type:"post",
  133. url:"/user/user/loginCode",
  134. dataType:'json',
  135. data:{
  136. phone:$("#phone").val(),
  137. code:$("#yzm").val(),
  138. source:'40013'
  139. },
  140. success:function(res) {
  141. console.log(res)
  142. if(res && res.errno == 0){
  143. window.location.href = './details.html?id=' + id;
  144. }else{
  145. showMsg(res.err)
  146. }
  147. }
  148. });
  149. }
  150. //提示信息
  151. function showMsg(msg) {
  152. var msg = msg;
  153. var msgBox = $('.alert-info');
  154. msgBox.children('p').text(msg);
  155. msgBox.show();
  156. setTimeout(function() {
  157. msgBox.hide();
  158. }, 2000);
  159. }
  160. //获取地址栏参数
  161. function parseQueryString(url) {
  162. var urlObj = {};
  163. var reg = /([^?=&]+)=([^?=&]+)/g;
  164. url.replace(reg, ($0, $1, $2) => {
  165. urlObj[$1] = decodeURIComponent($2);
  166. })
  167. return urlObj;
  168. }