暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

scripts.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. jQuery(document).ready(function() {
  2. /*
  3. Fullscreen background
  4. */
  5. $.backstretch("/template/pc/js/botstrap-step/cb10b62fa1f10acac99339fcfc511914_1.jpg");
  6. $('#top-navbar-1').on('shown.bs.collapse', function(){
  7. $.backstretch("resize");
  8. });
  9. $('#top-navbar-1').on('hidden.bs.collapse', function(){
  10. $.backstretch("resize");
  11. });
  12. /*
  13. Form
  14. */
  15. $('.registration-form fieldset:first-child').fadeIn('slow');
  16. $('.registration-form input[type="text"], .registration-form input[type="password"], .registration-form textarea').on('focus', function() {
  17. $(this).removeClass('input-error');
  18. });
  19. // next step
  20. $('.registration-form .btn-next').on('click', function() {
  21. var a11 = $('#choose11').val();
  22. var a12 = $('#choose12').val();
  23. if(a11 == 0 || a12 == 0){
  24. $('#myModal .modal-body p').html('请选择您所在城市');
  25. $('#myModal').modal('show');
  26. return false;
  27. }
  28. //校验字段
  29. var a = $('#choose2').val();
  30. console.log(a);
  31. if(a == 0){
  32. $('#myModal .modal-body p').html('请选择申报专业');
  33. $('#myModal').modal('show');
  34. return false;
  35. }
  36. var b = $('#choose3').val();
  37. console.log(a);
  38. if(b == 0){
  39. $('#myModal .modal-body p').html('请选择申报等级');
  40. $('#myModal').modal('show');
  41. return false;
  42. }
  43. console.log($(this).index());
  44. //调用专业
  45. if($(this).index() == 4) {
  46. //隐藏查询表单
  47. $('#sele-box').hide();
  48. $('#loadingModal').modal('show');
  49. $.ajax({
  50. url: '/api/Diyajax/getZcZyList',
  51. method: 'POST',
  52. dataType: 'json', // 指定响应数据为JSON
  53. data: {
  54. id: a
  55. },
  56. success: function (data) {
  57. // 请求成功后隐藏加载状态
  58. $('#loadingModal').modal('hide');
  59. // 处理返回的数据
  60. console.log('Ajax response:', data);
  61. console.log(data.data);
  62. var html = '';
  63. $.each(data.data, function (i, e) {
  64. console.log(e);
  65. html += '<p class="form-control-static" style="min-height:20px;padding-top:5px;padding-bottom:0px;"><label class="checkbox-inline"><input type="checkbox" name="zy[]" id="inlineCheckbox'+i+'" value="'+e.id+'"> '+e.title+'</label></p>';
  66. });
  67. if(html == ''){
  68. //隐藏
  69. $('#zy_box').hide();
  70. html = '暂无相关要求';
  71. }
  72. $('#zys').empty();
  73. $('#zys').append(html);
  74. },
  75. error: function (xhr, status, error) {
  76. // 请求失败后隐藏加载状态
  77. $('#loadingModal').modal('hide');
  78. // 处理错误
  79. console.error('Ajax error:', status, error);
  80. }
  81. });
  82. }
  83. //填完个人资料 点击下一步
  84. if($(this).index() == 7) {
  85. var b = $('#choose6').val();
  86. console.log(a);
  87. if(b == 0){
  88. $('#myModal .modal-body p').html('请选择年龄');
  89. $('#myModal').modal('show');
  90. return false;
  91. }
  92. var b = $('#choose5').val();
  93. console.log(a);
  94. if(b == 0){
  95. $('#myModal .modal-body p').html('请选择学历');
  96. $('#myModal').modal('show');
  97. return false;
  98. }
  99. var b = $('#choose7').val();
  100. console.log(a);
  101. if(b == 0){
  102. $('#myModal .modal-body p').html('请选择学校类型');
  103. $('#myModal').modal('show');
  104. return false;
  105. }
  106. var b33 = $('#choose33').val();
  107. console.log(a);
  108. if(b33 == 0){
  109. $('#myModal .modal-body p').html('请选择毕业时间');
  110. $('#myModal').modal('show');
  111. return false;
  112. }
  113. //调用证书
  114. $('#loadingModal').modal('show');
  115. $.ajax({
  116. url: '/api/Diyajax/getZcZsList',
  117. method: 'POST',
  118. dataType: 'json', // 指定响应数据为JSON
  119. data: {
  120. id: a
  121. },
  122. success: function (data) {
  123. // 请求成功后隐藏加载状态
  124. $('#loadingModal').modal('hide');
  125. // 处理返回的数据
  126. console.log('Ajax response:', data);
  127. console.log(data.data);
  128. var html = '';
  129. var options = '';
  130. for(i=1;i<=30;i++) {
  131. options += '<option value="'+i+'">'+i+'年</option>';
  132. }
  133. $.each(data.data, function (i, e) {
  134. console.log(e);
  135. html += '<p class="form-control-static" style="min-height:20px;padding-top:5px;padding-bottom:0px;"><label class="checkbox-inline"><input type="checkbox" name="zs[]" id="inlineCheckbox' + i + '" value="' + e.id + '"> ' + e.title + '</label><font style="margin-left:15px;"><select className="form-control-s" name="zsnx[]">'+options+'</select></font></p>';
  136. });
  137. if(html == ''){
  138. html = '暂无相关要求(2s后自动进行下一步)';
  139. //直接点击跳转下一步
  140. //ajax异步是一个线程
  141. //定时器也是一个独立线程
  142. //ajax直接执行点击有问题 放到定时器里面即可
  143. setTimeout(function() {
  144. $('#jumpBtn').trigger('click');
  145. //$('#jumpBtn').parent().parent().hide();
  146. }, 2000);
  147. }
  148. $('#zss').empty();
  149. $('#zss').append(html);
  150. },
  151. error: function (xhr, status, error) {
  152. // 请求失败后隐藏加载状态
  153. $('#loadingModal').modal('hide');
  154. // 处理错误
  155. console.error('Ajax error:', status, error);
  156. }
  157. });
  158. }
  159. if($(this).index() == 2) {
  160. //获取表单令牌 不能用接口直接过去 得用内部调用
  161. /*$('#loadingModal').modal('show');
  162. $.ajax({
  163. url: '/api/v1/api/get_token',
  164. method: 'POST',
  165. dataType: 'json', // 指定响应数据为JSON
  166. data: {},
  167. success: function (data) {
  168. // 请求成功后隐藏加载状态
  169. $('#loadingModal').modal('hide');
  170. // 处理返回的数据
  171. console.log('Ajax response:', data);
  172. console.log(data.data);
  173. $('#token').val(data.value);
  174. },
  175. error: function (xhr, status, error) {
  176. // 请求失败后隐藏加载状态
  177. $('#loadingModal').modal('hide');
  178. // 处理错误
  179. console.error('Ajax error:', status, error);
  180. }
  181. });*/
  182. }
  183. //继续下一屏切换
  184. var parent_fieldset = $(this).parents('fieldset');
  185. var next_step = true;
  186. parent_fieldset.find('input[type="text"], input[type="password"], textarea').each(function() {
  187. if( $(this).val() == "" ) {
  188. $(this).addClass('input-error');
  189. next_step = false;
  190. }
  191. else {
  192. $(this).removeClass('input-error');
  193. }
  194. });
  195. if( next_step ) {
  196. parent_fieldset.fadeOut(400, function() {
  197. $(this).next().fadeIn();
  198. });
  199. }
  200. });
  201. // previous step
  202. $('.registration-form .btn-previous').on('click', function() {
  203. console.log($(this).index());
  204. if($(this).index() == 6){
  205. //隐藏查询表单
  206. $('#sele-box').show();
  207. }
  208. $(this).parents('fieldset').fadeOut(400, function() {
  209. $(this).prev().fadeIn();
  210. });
  211. });
  212. // submit
  213. $('.registration-form').on('submit', function(e) {
  214. /*$(this).find('input[type="text"], input[type="password"], textarea').each(function() {
  215. if( $(this).val() == "" ) {
  216. e.preventDefault();
  217. $(this).addClass('input-error');
  218. }
  219. else {
  220. $(this).removeClass('input-error');
  221. }
  222. });*/
  223. function isValidPhoneNumber(phoneNumber) {
  224. var regex = /^1[3-9]\d{9}$/; // 中国手机号码正则表达式,以1开头,第二位是3-9,后面跟着9位数字
  225. return regex.test(phoneNumber);
  226. }
  227. //开始手动验证
  228. var a = $('#per-name').val();
  229. var b = $('#per-phone').val();
  230. var c = $('#per-code').val();
  231. if(a == ''){
  232. $('#myModal .modal-body p').html('请输入您的称呼');
  233. $('#myModal').modal('show');
  234. return false;
  235. }
  236. if(b == ''){
  237. $('#myModal .modal-body p').html('请输入您的手机号码');
  238. $('#myModal').modal('show');
  239. return false;
  240. }
  241. console.log(isValidPhoneNumber(b));
  242. if(isValidPhoneNumber(b) === false){
  243. $('#myModal .modal-body p').html('请输入正确的手机号码格式');
  244. $('#myModal').modal('show');
  245. return false;
  246. }
  247. if(c == ''){
  248. $('#myModal .modal-body p').html('请输入验证码');
  249. $('#myModal').modal('show');
  250. return false;
  251. }
  252. //循环所有checkbox 重新构建数组
  253. //var zhengshu = [];
  254. var zhengshu = '';
  255. $('#zss input[type=checkbox]').each(function() {
  256. if ($(this).is(':checked')) {
  257. // 至少有一个checkbox被选中
  258. //zhengshu.push($(this).val());
  259. zhengshu += $(this).val()+',';
  260. } else {
  261. // 没有任何checkbox被选中
  262. //zhengshu.push("0");
  263. zhengshu += '0,';
  264. }
  265. });
  266. $('#zhengshu_val').val(zhengshu);
  267. //发送表单信息到后台
  268. $('#loadingModal .visually-hidden').html('获取结果中...');
  269. $('#loadingModal').modal('show');
  270. var formData = $('.registration-form').serializeArray();
  271. console.log(formData);
  272. //return false;
  273. $.ajax({
  274. url: '/api/Diyajax/insData',
  275. method: 'POST',
  276. dataType: 'json', // 指定响应数据为JSON
  277. data: formData,
  278. success: function(data) {
  279. // 请求成功后隐藏加载状态
  280. $('#loadingModal').modal('hide');
  281. // 处理返回的数据
  282. console.log('Ajax response:', data);
  283. $('#loadingModal .visually-hidden').html(data.msg);
  284. $('#loadingModal').modal('show');
  285. if(data.code == 0){
  286. setTimeout(function() {
  287. $('#loadingModal').modal('hide');
  288. }, 3000); // 5秒后取消定时器
  289. }else{
  290. //重置表单数据
  291. //$('.registration-form').reset();
  292. $('.registration-form')[0].reset();
  293. //成功
  294. setTimeout(function() {
  295. $('#loadingModal').modal('hide');
  296. //跳转到结果页
  297. location.href = 'https://www.zc10000.com/cp?h='+data.data.code;
  298. }, 1000); // 5秒后取消定时器
  299. }
  300. },
  301. error: function(xhr, status, error) {
  302. // 请求失败后隐藏加载状态
  303. $('#loadingModal').modal('hide');
  304. // 处理错误
  305. console.error('Ajax error:', status, error);
  306. }
  307. });
  308. return false;
  309. });
  310. /**
  311. * 获取验证码
  312. */
  313. /*$('#cx-rel-code').on('click',function (){
  314. });*/
  315. /**
  316. * 查询提交的事件
  317. */
  318. $('#cx-submit').on('click',function (){
  319. function isValidPhoneNumber(phoneNumber) {
  320. var regex = /^1[3-9]\d{9}$/; // 中国手机号码正则表达式,以1开头,第二位是3-9,后面跟着9位数字
  321. return regex.test(phoneNumber);
  322. }
  323. var a = $('#cx-code').val();
  324. if(a == ''){
  325. $('#myModal .modal-body p').html('请输入验证码');
  326. $('#myModal').modal('show');
  327. return false;
  328. }
  329. var b = $('#ffnp').val();
  330. if(isValidPhoneNumber(b) === false){
  331. $('#myModal .modal-body p').html('请输入正确的手机号码格式');
  332. $('#myModal').modal('show');
  333. return false;
  334. }
  335. var t = $('#times').val();
  336. //请求ajax
  337. $.ajax({
  338. url: '/api/Diyajax/cxCode',
  339. method: 'POST',
  340. dataType: 'json', // 指定响应数据为JSON
  341. data: {
  342. 'code': a,
  343. 'mobile': b,
  344. },
  345. success: function(data) {
  346. // 请求成功后隐藏加载状态
  347. $('#loadingModal').modal('hide');
  348. // 处理返回的数据
  349. console.log('Ajax response:', data);
  350. $('#loadingModal .visually-hidden').html(data.msg);
  351. $('#loadingModal').modal('show');
  352. if(data.code == 0){
  353. setTimeout(function() {
  354. $('#loadingModal').modal('hide');
  355. }, 3000); // 5秒后取消定时器
  356. }else{
  357. //重置表单数据
  358. $('#cx-code').val('');
  359. //成功
  360. setTimeout(function() {
  361. $('#loadingModal').modal('hide');
  362. //跳转到结果页
  363. location.href = 'https://www.zc10000.com/cp?p='+b+'&t='+t;
  364. }, 2000); // 5秒后取消定时器
  365. }
  366. },
  367. error: function(xhr, status, error) {
  368. // 请求失败后隐藏加载状态
  369. $('#loadingModal').modal('hide');
  370. // 处理错误
  371. console.error('Ajax error:', status, error);
  372. }
  373. });
  374. $('.form-inline').trigger('click');
  375. return false;
  376. });
  377. // 获取长度为len的随机字符串
  378. function _getRandomString(len) {
  379. len = len || 32;
  380. var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1
  381. var maxPos = $chars.length;
  382. var pwd = '';
  383. for (i = 0; i < len; i++) {
  384. pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  385. }
  386. return pwd;
  387. }
  388. var timestamp = new Date().getTime();
  389. var times= timestamp + _getRandomString(32);
  390. console.log(times);
  391. $('#times').val(times);
  392. });