index.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. //登录
  69. $.ajax({
  70. url: "https://www.tuyatrip.com/api/supplier/updateUser",
  71. type: "get",
  72. data: {
  73. "phone": tel,
  74. "captcha": captcha
  75. },
  76. dataType: "json",
  77. success: (data) => {
  78. if(data.msg == "500"){
  79. layer.msg(data.errMsg, {icon: 2});
  80. return false;
  81. } else {
  82. window.location.href="/page/registered/" + tel;
  83. }
  84. localStorage.setItem("token", data.data.token);
  85. window.location.href="/page/index"
  86. },
  87. error: () => {
  88. layer.closeAll("loading");
  89. layer.alert("网络错误 请联系管理员");
  90. }
  91. });
  92. });
  93. })