register.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import '../css/bootstrap.less';
  2. import 'bootstrap/dist/js/bootstrap.js';
  3. import 'css/newMenu/public.css';
  4. import 'css/newMenu/header.css'
  5. import '../css/register.css';
  6. import './public.js';
  7. import { DH_NOT_SUITABLE_GENERATOR } from 'constants';
  8. $(function () {
  9. //查看技淘网协议
  10. var hht = $(window).height();
  11. $('.login_').height(hht);
  12. //登陆
  13. var hht = $(window).height();
  14. $('.login').hide();
  15. //点击账号后面那个×,清空账号
  16. $(".log_del").click(function () {
  17. $("#username").focus().val("").css('color','#666');
  18. });
  19. var xieyi = $('#protocol').prop("checked", false);
  20. $('.sub').attr('disabled', true)
  21. $('.sub').css({
  22. background: '#CCCCCC',
  23. border: 'none'
  24. })
  25. $('#protocol').click(function () {
  26. var Cheack_no = $(this).prop('checked')
  27. if (Cheack_no) {
  28. $(this).parent().removeClass('cheackeds_no').addClass('cheackeds');
  29. $('.sub').attr('disabled', false);
  30. $('.sub').css({
  31. background: '#F18101',
  32. border: 'none'
  33. })
  34. } else {
  35. $(this).prop('checked', false)
  36. $(this).parent().addClass('cheackeds_no').removeClass('cheackeds');
  37. $('.sub').attr('disabled', true)
  38. $('.sub').css({
  39. background: '#CCCCCC',
  40. border: 'none'
  41. })
  42. }
  43. })
  44. //手机号码
  45. let oldPhoto='';
  46. $('#photo').attr('disabled', true);
  47. function photo1() {
  48. var pho_pattern = /^1[3|4|5|7|8][0-9]{9}$/;
  49. $("#usePhoto").keyup(function () {
  50. oldPhoto = $(this).val();
  51. if (pho_pattern.test(oldPhoto)) {
  52. $('#photo').attr('disabled', false);
  53. $("#photo").css("color", "#F18101");
  54. } else if (!pho_pattern.test(oldPhoto)) {
  55. $('#photo').attr('disabled', true);
  56. $("#photo").css("color", "#ccc");
  57. }
  58. });
  59. }
  60. photo1();
  61. //手机验证码
  62. function photo_num() {
  63. $('#photo_num').blur(function () {
  64. var phoa = $(this).val();
  65. if (phoa == '') {
  66. $(this).val('验证码不能为空').css({color:'#f00'});
  67. }
  68. })
  69. }
  70. photo_num();
  71. /* 获得焦点处理 */
  72. $('#username,#customerName,#usePhoto').focus(function(){
  73. let val = $(this).val();
  74. if(val.indexOf('用户名')>-1||val.indexOf('下划线')>-1||val.indexOf('客户')>-1||val.indexOf('手机')>-1){
  75. $(this).val('').css({color:'#333'})
  76. }
  77. })
  78. $('#photo_num').focus(function(){
  79. if(($(this).val()).indexOf('验证码')>-1){
  80. $(this).val('')
  81. }
  82. $(this).css({color:'#333'})
  83. })
  84. $('#userpassword,#userpassword2').focus(function(){
  85. let passVal =$(this).val();
  86. if(passVal.indexOf('密码')>-1){
  87. $(this).attr('type','password').val('').css({color:'#333'})
  88. }
  89. })
  90. /*失去焦点处理 */
  91. blurFun();
  92. function blurFun(){
  93. $('#username').blur(function(){
  94. let nameRax = /^[a-zA-Z0-9_-]{6,32}$/;
  95. // if(!$(this).val().trim()){
  96. // $(this).val('请填写用户名').css({color:'#f00'})
  97. // }else if(!nameRax.test($(this).val())){
  98. // $(this).val('1-32位字母/数字/汉字').css({color:'#f00'})
  99. // }
  100. })
  101. $('#userpassword').blur(function () {
  102. var pass_pattern = /^[a-zA-Z\d_]{6,12}$/;
  103. var pass1 = $(this).val().trim();
  104. var tt = $('#userpassword2').val().trim();
  105. if (!pass1|| !pass_pattern.test(pass1)) {
  106. $(this).attr('type',"text")
  107. // $(this).val('请输入6-12位数字母开头密码').css({color:'#f00'});
  108. return;
  109. }else{
  110. $(this).attr('type','password');
  111. };
  112. if (pass1 && tt !== pass1) {
  113. $('#userpassword2').attr('type',"text")
  114. $('#userpassword2').val('两次密码不一致').css({color:'#f00'});
  115. return;
  116. };
  117. });
  118. $('#customerName').blur(function(){
  119. if(!$(this).val().trim()){
  120. $(this).val('请填写客户名称').css({color:'#f00'})
  121. }
  122. });
  123. $('#usePhoto').blur(function(){
  124. if(!$(this).val().trim()){
  125. $(this).val('请填写手机号码').css({color:'#f00'})
  126. }
  127. });
  128. $('#userpassword2').blur(function () {
  129. var orepeat = $(this).val();
  130. var passw = $('#userpassword').val();
  131. if (passw !== orepeat || passw == '') {
  132. $(this).attr('type','text')
  133. $(this).val('两次密码不一致').css({color:'#f00'})
  134. }
  135. });
  136. }
  137. function initVal(){
  138. $('#userpassword2').val('确认密码');
  139. $('#userpassword1').val('请输入密码');
  140. $('#username').val('请输入用户名');
  141. $('#customerName').val('请输入客户名称');
  142. $('#usePhoto').val('请输入手机号码');
  143. $('#photo_num').val('手机验证码');
  144. $('#protocol').prop("checked", false)
  145. $(this).prop('checked', false)
  146. $(this).parent().addClass('cheackeds_no').removeClass('cheackeds');
  147. $('.sub').attr('disabled', true)
  148. $('.sub').css({
  149. background: '#CCCCCC',
  150. border: 'none'
  151. })
  152. }
  153. //表单提交
  154. $("#form_register").submit(function (e) {
  155. e.preventDefault();
  156. var user = $("#username").val(),
  157. usePhoto = $('#usePhoto').val(),
  158. password1 = $("#userpassword").val(),
  159. password2 = $("#userpassword2").val(),
  160. customerType = $('#customerType').val(),
  161. mobileCode = $('#photo_num').val(); //手机验证码
  162. console.log(customerType);
  163. if(user.indexOf('用户名')>-1||password1.indexOf('密码')>-1||password2.indexOf('密码')>-1||usePhoto.indexOf('手机')>-1||mobileCode.indexOf('验证码')>-1){
  164. msg('请填写必填项');
  165. return;
  166. } else {
  167. //$('.loading').show().css({'opacity':'0'}).find('p').html('');
  168. $('.loading').show()
  169. $.ajax({
  170. type: "POST",
  171. dataType: "json",
  172. url: globalConfig.context + "/register",
  173. data: {
  174. "unitName": user,
  175. "password": password1,
  176. "mobile": usePhoto,
  177. "mobileCode": mobileCode,
  178. "type":customerType
  179. },
  180. success: function (rest) {
  181. $('.loading').hide()
  182. if (rest.error && rest.error.length) {
  183. msg(rest.error[0].message);
  184. } else {
  185. setTimeout(()=>{
  186. msg("注册成功,请登录个人中心操作");
  187. initVal();
  188. if($('.header ul li a').hasClass('head_login')){
  189. $('.login').fadeIn(800);
  190. $('#form_register').fadeOut(800)
  191. }
  192. },2000)
  193. }
  194. }
  195. })
  196. }
  197. })
  198. agreement();
  199. function agreement(){
  200. $('.head_login_').click(function(){
  201. $('.login_').show();
  202. })
  203. $('.login_close_').click(function(){
  204. $('.login_').hide();
  205. })
  206. }
  207. var tt = 30;
  208. $('#photo').click(function () {
  209. var ophoto = $('#usePhoto').val().trim();
  210. if (ophoto) {
  211. $.ajax({
  212. type: "GET",
  213. url: globalConfig.context + "/open/getMCode",
  214. data: {
  215. "mobile": ophoto,
  216. "sign": false,
  217. },
  218. success: function (data) {
  219. if (data.error && data.error.length) {
  220. msg(data.error[0].message);
  221. } else {
  222. //验证码倒计时
  223. $('#photo').attr('disabled', true);
  224. var timer = setInterval(function () {
  225. tt -= 1;
  226. $('#photo').val("发送" + '(' + tt + 's' + ')');
  227. $('#photo').css({
  228. color: '#cccccc'
  229. })
  230. if (tt == 0) {
  231. clearInterval(timer);
  232. $('#photo').attr('disabled', false);
  233. tt = 30;
  234. $('#photo').css({
  235. color: '#f18101'
  236. })
  237. $('#photo').val('重新发送');
  238. }
  239. }.bind(this), 1000);
  240. msg('发送成功');
  241. }
  242. return true;
  243. }
  244. });
  245. } else {
  246. msg('请填写手机号码!');
  247. }
  248. });
  249. //提示框渐隐函数
  250. function msg(mess) {
  251. if($('.smg').hasClass('active')){
  252. return ;
  253. }
  254. $('.smg').addClass('active')
  255. $('#msg').val(mess);
  256. setTimeout(function () {
  257. $('.smg').removeClass('active')
  258. $('#msg').val('');
  259. }, 2000)
  260. }
  261. });