phase_pay_audit.js 24 KB

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