Student.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // 表单初始化
  2. FromInit('form.form-validation-win');
  3. $(function()
  4. {
  5. // 学生关联-短信验证码获取
  6. $('.verify-submit, .verify-submit-win').on('click', function()
  7. {
  8. var $this = $(this);
  9. var $verify_win = $('#verify-win');
  10. var $form = $('form.form-validation-win');
  11. var $accounts = $form.find('select[name="accounts"]');
  12. var $verify = $('#verify-img-value');
  13. var verify = '';
  14. if($accounts.hasClass('am-field-valid'))
  15. {
  16. // 是否需要先校验图片验证码
  17. if($this.data('verify') == 1)
  18. {
  19. // 开启图片验证码窗口
  20. $verify_win.modal('open');
  21. $verify.focus();
  22. return false;
  23. }
  24. // 验证码窗口操作按钮则更新按钮对象
  25. var is_win = $(this).data('win');
  26. if(is_win == 1)
  27. {
  28. $this = $('.verify-submit');
  29. // 验证码参数处理
  30. verify = $verify.val().replace(/\s+/g, '');
  31. if(verify.length < 6)
  32. {
  33. Prompt($verify.data('validation-message'));
  34. $verify.focus();
  35. return false;
  36. }
  37. }
  38. // 验证码时间间隔
  39. var time_count = parseInt($this.data('time'));
  40. // 按钮交互
  41. $this.button('loading');
  42. if(is_win == 1)
  43. {
  44. $('.verify-submit-win').button('loading');
  45. }
  46. // 发送验证码
  47. $.ajax({
  48. url:$('.verify-submit').data('url'),
  49. type:'POST',
  50. data:{"accounts":$accounts.val(), "verify":verify},
  51. dataType:'json',
  52. success:function(result)
  53. {
  54. if(result.code == 0)
  55. {
  56. var intervalid = setInterval(function()
  57. {
  58. if(time_count == 0)
  59. {
  60. $this.button('reset');
  61. if(is_win == 1)
  62. {
  63. $('.verify-submit-win').button('reset');
  64. }
  65. $this.text($this.data('text'));
  66. $verify.val('');
  67. clearInterval(intervalid);
  68. } else {
  69. var send_msg = $this.data('send-text').replace(/{time}/, time_count--);
  70. $this.text(send_msg);
  71. }
  72. }, 1000);
  73. $verify_win.modal('close');
  74. } else {
  75. $this.button('reset');
  76. if(is_win == 1)
  77. {
  78. $('.verify-submit-win').button('reset');
  79. }
  80. Prompt(result.msg);
  81. }
  82. },
  83. error:function()
  84. {
  85. $this.button('reset');
  86. if(is_win == 1)
  87. {
  88. $('.verify-submit-win').button('reset');
  89. }
  90. Prompt('网络错误');
  91. }
  92. });
  93. } else {
  94. $verify_win.modal('close');
  95. $accounts.focus();
  96. }
  97. });
  98. });