material_audit.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2019/2/27
  7. * @version
  8. */
  9. $(document).ready(function () {
  10. let timer = null
  11. let oldSearchVal = null
  12. // 获取审核相关url
  13. function getUrlPre () {
  14. const path = window.location.pathname.split('/');
  15. return _.take(path, 6).join('/');
  16. }
  17. $('#gr-search').bind('input propertychange', function(e) {
  18. oldSearchVal = e.target.value
  19. timer && clearTimeout(timer)
  20. timer = setTimeout(() => {
  21. const newVal = $('#gr-search').val()
  22. let html = ''
  23. if (newVal && newVal === oldSearchVal) {
  24. accountList.filter(item => item && cur_uid !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  25. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  26. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  27. class="ml-auto">${item.mobile || ''}</span></p>
  28. <span class="text-muted">${item.role || ''}</span>
  29. </dd>`
  30. })
  31. $('.book-list').empty()
  32. $('.book-list').append(html)
  33. } else {
  34. if (!$('.acc-btn').length) {
  35. accountGroup.forEach((group, idx) => {
  36. if (!group) return
  37. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  38. </a> ${group.groupName}</dt>
  39. <div class="dd-content" data-toggleid="${idx}">`
  40. group.groupList.forEach(item => {
  41. if (item.id !== cur_uid) {
  42. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  43. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  44. class="ml-auto">${item.mobile || ''}</span></p>
  45. <span class="text-muted">${item.role || ''}</span>
  46. </dd>`
  47. }
  48. });
  49. html += '</div>'
  50. })
  51. $('.book-list').empty()
  52. $('.book-list').append(html)
  53. }
  54. }
  55. }, 400);
  56. })
  57. // 添加审批流程按钮逻辑
  58. $('.book-list').on('click', '.book-list dt', function () {
  59. const idx = $(this).find('.acc-btn').attr('data-groupid')
  60. const type = $(this).find('.acc-btn').attr('data-type')
  61. if (type === 'hide') {
  62. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  63. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  64. $(this).find('.acc-btn').attr('data-type', 'show')
  65. })
  66. } else {
  67. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  68. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  69. $(this).find('.acc-btn').attr('data-type', 'hide')
  70. })
  71. }
  72. return false
  73. })
  74. // 添加到审批流程中
  75. $('#book-list').on('click', 'dd', function () {
  76. const id = parseInt($(this).data('id'));
  77. if (id) {
  78. postData(getUrlPre() + '/audit/add', { auditorId: id }, (datas) => {
  79. const html = [];
  80. // 如果是重新上报,添加到重新上报列表中
  81. const auditorshtml = [];
  82. for (const [index,data] of datas.entries()) {
  83. if (index !== 0) {
  84. html.push('<li class="list-group-item d-flex" auditorId="'+ data[0].aid +'">');
  85. html.push(`<div class="col-auto">${index}</div>`);
  86. html.push('<div class="col">');
  87. for (const auditor of data) {
  88. html.push(`<div class="d-inline-block mx-1"><i class="fa fa-user text-muted"></i> ${auditor.name} <small class="text-muted">${auditor.role}</small></div>`);
  89. }
  90. html.push('</div>');
  91. html.push('<div class="col-auto">');
  92. if (data[0].audit_type !== auditType.key.common) {
  93. html.push(`<span class="badge badge-pill badge-${auditType.info[data[0].audit_type].class} badge-bg-small"><small>${auditType.info[data[0].audit_type].long}</small></span>`);
  94. }
  95. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
  96. html.push('<a href="javascript: void(0)" class="text-danger pull-right ml-1">移除</a>');
  97. }
  98. html.push('</div>');
  99. html.push('</li>');
  100. }
  101. auditorshtml.push('<li class="list-group-item" data-auditorid="' + data.aid + '">');
  102. auditorshtml.push('<i class="fa ' + (index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
  103. auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  104. if (index === 0) {
  105. auditorshtml.push('<span class="pull-right">原报</span>');
  106. } else if (index+1 === datas.length) {
  107. auditorshtml.push('<span class="pull-right">终审</span>');
  108. } else {
  109. auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
  110. }
  111. auditorshtml.push('</li>');
  112. }
  113. $('#auditors').html(html.join(''));
  114. $('#auditors-list').html(auditorshtml.join(''));
  115. });
  116. }
  117. });
  118. // 删除审批人
  119. $('body').on('click', '#auditors li>a', function () {
  120. const li = $(this).parent();
  121. const data = {
  122. auditorId: parseInt(li.attr('auditorId')),
  123. };
  124. postData(getUrlPre() + '/audit/delete', data, (result) => {
  125. li.remove();
  126. for (const rst of result) {
  127. const aLi = $('li[auditorId=' + rst.aid + ']');
  128. $('div:first', aLi).text(rst.order);
  129. }
  130. // 如果是重新上报
  131. // 令最后一个图标转换
  132. $('#auditors-list li[data-auditorid="' + data.auditorId + '"]').remove();
  133. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  134. $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
  135. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  136. }
  137. // $('#auditors-list2 li[data-auditid="' + data.auditorId + '"]').remove();
  138. // if ($('#auditors-list2 li').length !== 0 && !$('#auditors-list2 li i').hasClass('fa-stop-circle')) {
  139. // $('#auditors-list2 li').eq($('#auditors-list2 li').length-1).children('i')
  140. // .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  141. // }
  142. for (let i = 0; i < $('#auditors-list li').length; i++) {
  143. $('#auditors-list li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审');
  144. // $('#auditors-list2').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2').length ? '终' : transFormToChinese(i+1)) + '审');
  145. }
  146. });
  147. });
  148. // 退回选择修改审批人流程
  149. $('#hideSp').click(function () {
  150. $('#sp-list').modal('hide');
  151. });
  152. $('a[f-target]').click(function () {
  153. $($(this).attr('f-target')).modal('show');
  154. });
  155. // 多层modal关闭后的滚动bug修复
  156. $('#sp-list').on('hidden.bs.modal', function (e) {
  157. $(document.body).addClass('modal-open');
  158. });
  159. // 重新审批获取手机验证码
  160. // 获取验证码
  161. let isPosting = false;
  162. $("#get-code").click(function() {
  163. if (isPosting) {
  164. return false;
  165. }
  166. const btn = $(this);
  167. $.ajax({
  168. url: '/profile/code?_csrf_j=' + csrf,
  169. type: 'post',
  170. data: { mobile: authMobile, type: 'shenpi' },
  171. dataTye: 'json',
  172. error: function() {
  173. isPosting = false;
  174. },
  175. beforeSend: function() {
  176. isPosting = true;
  177. },
  178. success: function(response) {
  179. isPosting = false;
  180. if (response.err === 0) {
  181. codeSuccess(btn);
  182. $("input[name='code']").removeAttr('readonly');
  183. $("#re-shenpi-btn").removeAttr('disabled');
  184. } else {
  185. toastr.error(response.msg);
  186. }
  187. }
  188. });
  189. });
  190. // 管理员更改审批流程js部分
  191. let timer2 = null;
  192. let oldSearchVal2 = null;
  193. $('body').on('input propertychange', '.gr-search', function(e) {
  194. oldSearchVal2 = e.target.value;
  195. timer2 && clearTimeout(timer2);
  196. timer2 = setTimeout(() => {
  197. const newVal = $(this).val();
  198. const code = $(this).attr('data-code');
  199. let html = '';
  200. if (newVal && newVal === oldSearchVal2) {
  201. accountList.filter(item => item && item.id !== material_uid && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  202. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  203. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  204. class="ml-auto">${item.mobile || ''}</span></p>
  205. <span class="text-muted">${item.role || ''}</span>
  206. </dd>`
  207. });
  208. $('#' + code + '_dropdownMenu .book-list').empty();
  209. $('#' + code + '_dropdownMenu .book-list').append(html);
  210. } else {
  211. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  212. accountGroup.forEach((group, idx) => {
  213. if (!group) return;
  214. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  215. </a> ${group.groupName}</dt>
  216. <div class="dd-content" data-toggleid="${idx}">`;
  217. group.groupList.forEach(item => {
  218. if (item.id !== material_uid) {
  219. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  220. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  221. class="ml-auto">${item.mobile || ''}</span></p>
  222. <span class="text-muted">${item.role || ''}</span>
  223. </dd>`;
  224. }
  225. });
  226. html += '</div>';
  227. });
  228. $('#' + code + '_dropdownMenu .book-list').empty();
  229. $('#' + code + '_dropdownMenu .book-list').append(html);
  230. }
  231. }
  232. }, 400);
  233. });
  234. const getAdminEditShenpiListHtml = function(auditGroup) {
  235. const html = [];
  236. for (const [i, group] of auditGroup.entries()) {
  237. if (i === 0) continue;
  238. for (const [j, auditor] of group.entries()) {
  239. html.push('<tr>');
  240. if (j === 0) {
  241. const auditTypeHtml = auditor.type === auditType.key.common ? '' : `<span class="ml-2 badge badge-pill badge-${auditType.info[auditor.audit_type].class} p-1"><small>${auditType.info[auditor.audit_type].short}</small></span>`;
  242. html.push(`<td class="text-left d-flex">${i + '审'}${auditTypeHtml}</td>`);
  243. } else {
  244. html.push(`<td class="text-left d-flex"></td>`);
  245. }
  246. html.push(`<td></span> ${auditor.name} <small class="text-muted">${auditor.role}</small></td>`);
  247. html.push(`<td style="text-align: center"><span class="${sam_auditConst.auditStringClass[auditor.status]}">${ auditor.status !== sam_auditConst.status.uncheck ? sam_auditConst.auditString[auditor.status] : '待审批' }</span></td>`);
  248. html.push('<td style="text-align: center">');
  249. if (auditor.status === sam_auditConst.status.checking && j === group.length - 1) {
  250. html.push('<span class="dropdown mr-2">',
  251. `<a href="javascript: void(0)" class="add-audit" id="${auditor.aid}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">增加</a>`,
  252. makeSelectAudit(auditor.aid+'_add', auditor.aid, 'add'),'</div>', '</span>');
  253. }
  254. if (auditor.status === sam_auditConst.status.uncheck) {
  255. if (j === group.length - 1) {
  256. html.push('<span class="dropdown mr-2">',
  257. `<a href="javascript: void(0)" class="add-audit" id="${auditor.aid}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">增加</a>`,
  258. makeSelectAudit(auditor.aid+'_add', auditor.aid, 'add'),'</div>', '</span>');
  259. if (auditor.audit_type !== auditType.key.common) {
  260. html.push('<span class="dropdown mr-2">',
  261. `<a href="javascript: void(0)" class="add-audit" id="${auditor.aid}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">平级</a>`,
  262. makeSelectAudit(auditor.aid+'_add-sibling', auditor.aid, 'add-sibling'),'</div>', '</span>');
  263. }
  264. }
  265. html.push('<span class="dropdown mr-2">',
  266. `<a href="javascript: void(0)" class="add-audit" id="${auditor.aid}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">更换</a>`,
  267. makeSelectAudit(auditor.aid+'_change', auditor.aid, 'change'),'</div>', '</span>');
  268. html.push(`<span class="dropdown">
  269. <a href="javascript: void(0)" class="text-danger" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">移除</a>
  270. <div class="dropdown-menu">
  271. <span class="dropdown-item" href="javascript:void(0);">确认移除审批人?</span>
  272. <div class="dropdown-divider"></div>
  273. <div class="px-2 py-1 text-center">
  274. <button class="remove-audit btn btn-sm btn-danger" data-id="${auditor.aid}">移除</button>
  275. <button class="btn btn-sm btn-secondary">取消</button>
  276. </div>
  277. </div>
  278. </span>`);
  279. }
  280. html.push('</td>');
  281. html.push('</tr>');
  282. }
  283. }
  284. return html.join('');
  285. };
  286. $('body').on('click', '#admin-edit-shenpi dl dd', function () {
  287. const id = parseInt($(this).attr('data-id'));
  288. if (!id) return;
  289. let this_aid = parseInt($(this).parents('.book-list').attr('data-aid'));
  290. let this_operate = $(this).parents('.book-list').attr('data-operate');
  291. const user = _.find(accountList, function (item) {
  292. return item.id === id;
  293. });
  294. const auditorIndex = _.findIndex(auditorList, { aid: id });
  295. if (auditorIndex !== -1) {
  296. toastr.warning('该审核人已存在,请勿重复添加');
  297. return;
  298. }
  299. const prop = {
  300. operate: this_operate,
  301. old_aid: this_aid,
  302. new_aid: user.id,
  303. };
  304. postData(getUrlPre() + '/audit/save', prop, (datas) => {
  305. $('#admin-edit-shenpi-list').html(getAdminEditShenpiListHtml(datas));
  306. changeLiucheng(datas);
  307. });
  308. });
  309. // 移除审批人
  310. $('body').on('click', '.remove-audit', function () {
  311. const id = parseInt($(this).attr('data-id'));
  312. const prop = {
  313. operate: 'del',
  314. old_aid: id,
  315. };
  316. postData(getUrlPre() + '/audit/save', prop, (datas) => {
  317. $('#admin-edit-shenpi-list').html(getAdminEditShenpiListHtml(datas));
  318. changeLiucheng(datas);
  319. });
  320. });
  321. const getAuditTypeText = function (type) {
  322. if (type === auditType.key.common) return '';
  323. return `<span class="text-${auditType.info[type].class}">${auditType.info[type].long}</span>`;
  324. };
  325. function changeLiucheng(datas) {
  326. const auditorshtml = [];
  327. let lastAuditorHtml = [];
  328. for (const [index,data] of datas.entries()) {
  329. auditorshtml.push('<li class="list-group-item d-flex justify-content-between align-items-center">');
  330. if (index === 0) {
  331. auditorshtml.push('<span class="mr-1"><i class="fa fa fa-play-circle fa-rotate-90"></i></span>');
  332. } else if (index+1 === datas.length) {
  333. auditorshtml.push('<span class="mr-1"><i class="fa fa fa-stop-circle"></i></span>');
  334. } else {
  335. auditorshtml.push('<span class="mr-1"><i class="fa fa-chevron-circle-down"></i></span>');
  336. }
  337. auditorshtml.push('<span class="text-muted">');
  338. for (const u of data) {
  339. auditorshtml.push(`<small class="d-inline-block text-dark mx-1" title="${u.role}" data-auditorId="${u.aid}">${u.name}</small>`);
  340. }
  341. auditorshtml.push('</span>');
  342. auditorshtml.push('<div class="d-flex ml-auto">');
  343. if (data[0].audit_type !== auditType.key.common) auditorshtml.push(`<span class="badge badge-pill badge-${auditType.info[data[0].audit_type].class} p-1"><small>${auditType.info[data[0].audit_type].short}</small></span>`);
  344. if (index === 0) {
  345. auditorshtml.push('<span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>');
  346. } else if (index+1 === datas.length) {
  347. auditorshtml.push('<span class="badge badge-light badge-pill"><small>终审</small></span>');
  348. } else {
  349. auditorshtml.push('<span class="badge badge-light badge-pill"><small>'+ transFormToChinese(index) +'审</small></span>');
  350. }
  351. auditorshtml.push('</div>');
  352. auditorshtml.push('</li>');
  353. if (data[0].status === sam_auditConst.status.uncheck) {
  354. lastAuditorHtml.push('<li class="timeline-list-item pb-2 is_uncheck">');
  355. if (index < datas.length - 1) {
  356. lastAuditorHtml.push('<div class="timeline-item-tail"></div>');
  357. }
  358. lastAuditorHtml.push('<div class="timeline-item-icon bg-secondary text-light"></div>');
  359. lastAuditorHtml.push('<div class="timeline-item-content">');
  360. lastAuditorHtml.push(`<div class="py-1">
  361. <span class="text-black-50">
  362. ${ index !== datas.length - 1 ? data[0].audit_order + '' : '终' }审 ${getAuditTypeText(data[0].audit_type)}
  363. </span>
  364. </div>`);
  365. lastAuditorHtml.push('<div class="card"><div class="card-body px-3 py-0">');
  366. for (const [i, auditor] of data.entries()) {
  367. lastAuditorHtml.push(`<div class="card-text p-2 py-3 row ${ ( i > 0 ? 'border-top' : '') }">`);
  368. lastAuditorHtml.push(`<div class="col"><span class="h6">${auditor.name}</span><span class="text-muted ml-1">${auditor.role}</span></div>`);
  369. lastAuditorHtml.push('<div class="col">');
  370. lastAuditorHtml.push('</div>');
  371. lastAuditorHtml.push('</div>');
  372. }
  373. lastAuditorHtml.push('</div></div>');
  374. lastAuditorHtml.push('</div>');
  375. lastAuditorHtml.push('</li>');
  376. }
  377. }
  378. $('.last-auditor-list .is_uncheck').remove();
  379. $('.last-auditor-list').append(lastAuditorHtml.join(''));
  380. $('.auditors-list').html(auditorshtml.join(''));
  381. }
  382. // 审批流程-选择审批人html 生成
  383. function makeSelectAudit(code, aid, status) {
  384. let divhtml = '';
  385. accountGroup.forEach((group, idx) => {
  386. let didivhtml = '';
  387. if(group) {
  388. group.groupList.forEach(item => {
  389. didivhtml += item.id !== material_uid ? '<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
  390. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  391. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  392. ' <span class="text-muted">' + item.role + '</span>\n' +
  393. ' </dd>\n' : '';
  394. });
  395. divhtml += '<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="' + idx + '" data-type="hide"><i class="fa fa-plus-square"></i></a> ' + group.groupName + '</dt>\n' +
  396. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  397. ' </div>\n';
  398. }
  399. });
  400. let html = '<div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  401. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  402. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  403. ' <dl class="list-unstyled book-list" data-aid="'+ aid +'" data-operate="'+ status +'">\n' + divhtml +
  404. ' </dl>\n' +
  405. ' </div>\n' +
  406. ' </div>\n' +
  407. ' </span>\n' +
  408. ' </span>\n' +
  409. ' </li>';
  410. return html;
  411. }
  412. });
  413. // 检查上报情况
  414. function checkAuditorFrom () {
  415. if ($('#auditors li').length === 0) {
  416. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  417. toastr.error('请联系管理员添加审批人');
  418. } else {
  419. toastr.error('请先选择审批人,再上报数据');
  420. }
  421. return false;
  422. }
  423. // 判断是否存在工料编号不能为空的情况
  424. const nullList = _.filter(materialBillsData, function (item) {
  425. return item.code === '' || item.code === null;
  426. });
  427. if (nullList.length > 0) {
  428. toastr.error('信息价调差存在编号为空的工料,请添加编号后再上报');
  429. return false;
  430. }
  431. $('#hide-all').show();
  432. }
  433. // texterea换行
  434. function auditCheck(i) {
  435. const inlineRadio1 = $('#inlineRadio1:checked').val()
  436. const inlineRadio2 = $('#inlineRadio2:checked').val()
  437. const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  438. $('textarea[name="opinion"]').eq(i).val(opinion);
  439. if (i === 1) {
  440. if (!inlineRadio1 && !inlineRadio2) {
  441. if (!$('#warning-text').length) {
  442. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  443. }
  444. return false;
  445. }
  446. if ($('#warning-text').length) $('#warning-text').remove()
  447. }
  448. return true;
  449. }
  450. /**
  451. * 获取成功后的操作
  452. *
  453. * @param {Object} btn - 点击的按钮
  454. * @return {void}
  455. */
  456. function codeSuccess(btn) {
  457. let counter = 60;
  458. btn.addClass('disabled').text('重新获取 ' + counter + 'S');
  459. btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
  460. const bindBtn = $("#bind-btn");
  461. bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
  462. const countDown = setInterval(function() {
  463. const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
  464. // 倒数结束后
  465. if (countString === '') {
  466. clearInterval(countDown);
  467. btn.removeClass('disabled');
  468. }
  469. const text = '重新获取' + countString;
  470. btn.text(text);
  471. counter -= 1;
  472. }, 1000);
  473. }