index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. layui.use(["layer", "form"], function(){
  2. $ = layui.$;
  3. form = layui.form;
  4. layer = layui.layer;
  5. //点击发送验证码
  6. $(document).on("click", ".getCode", (e) => {
  7. let tel = $("input[name=tel]").val();
  8. if(tel == null || tel == ""){
  9. layer.msg("请输入手机号", {icon: 2});
  10. return false;
  11. }
  12. if(!(/^1[3456789]\d{9}$/.test(tel))){
  13. layer.msg("手机号格式不正确", {icon: 2});
  14. return false;
  15. }
  16. //发送验证码
  17. $.ajax({
  18. url: "https://www.tuyatrip.com/api/supplier/checkTele",
  19. type: "get",
  20. data: {
  21. "phone": tel
  22. },
  23. dataType: "json",
  24. success: (data) => {
  25. if(data.msg == "500"){
  26. layer.alert(data.errMsg, {icon: 2});
  27. } else {
  28. layer.alert("发送成功", {icon: 1});
  29. let time = 60;
  30. let timer = "";
  31. clearInterval(timer);
  32. timer = setInterval(function () {
  33. if (time > 0) {
  34. $('.code-btn').html(time + "S");
  35. $(".code-btn").removeClass("getCode");
  36. time--;
  37. } else {
  38. $('.code-btn').html("获取验证码");
  39. time = 60;
  40. $(".code-btn").addClass("getCode");
  41. clearInterval(timer);
  42. }
  43. }, 1000);
  44. }
  45. },
  46. error: () => {
  47. layer.closeAll("loading");
  48. layer.alert("网络错误 请联系管理员");
  49. }
  50. });
  51. });
  52. //注册登录
  53. $(".login-btn").on("click", (e) =>{
  54. let captcha = $("input[name=captcha]").val();
  55. let tel = $("input[name=tel]").val();
  56. if(captcha == null || captcha == ""){
  57. layer.msg("验证码不能为空", {icon: 2});
  58. return false;
  59. }
  60. if(tel == null || tel == ""){
  61. layer.msg("请输入手机号", {icon: 2});
  62. return false;
  63. }
  64. if(!(/^1[3456789]\d{9}$/.test(tel))){
  65. layer.msg("手机号格式不正确", {icon: 2});
  66. return false;
  67. }
  68. if($("input[name=termsSelect]").prop("checked") == false){
  69. layer.msg("请点击同意协议", {icon: 2});
  70. return false;
  71. }
  72. //登录
  73. $.ajax({
  74. url: "https://www.tuyatrip.com/api/supplier/updateUser",
  75. type: "get",
  76. data: {
  77. "phone": tel,
  78. "captcha": captcha
  79. },
  80. dataType: "json",
  81. success: (data) => {
  82. if(data.msg == "500"){
  83. layer.msg(data.errMsg, {icon: 2});
  84. return false;
  85. } else if(data.msg == "100"){
  86. window.location.href="/page/registered/" + tel;
  87. }
  88. localStorage.setItem("token", data.data.token);
  89. window.location.href="/page/index"
  90. },
  91. error: () => {
  92. layer.closeAll("loading");
  93. layer.alert("网络错误 请联系管理员");
  94. }
  95. });
  96. });
  97. $.ajax({
  98. url: "/json/wave.json",
  99. type: "get",
  100. data: {},
  101. dataType: "json",
  102. success: (data) => {
  103. var anim = lottie.loadAnimation({
  104. container: document.querySelector(".lottie"), // 容器
  105. renderer: "svg",
  106. loop: true,
  107. autoplay: true,
  108. animationData: data, //如果使用的是JSON
  109. });
  110. },
  111. error: () => {
  112. layer.closeAll("loading");
  113. layer.alert("网络错误 请联系管理员");
  114. }
  115. });
  116. })