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 !== 0) {
  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. // todo 添加会签或签时
  117. // html.push('<span class="badge badge-pill badge-primary badge-bg-small"><small></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. // 删除审批人
  142. $('body').on('click', '#auditors li a', function () {
  143. const li = $(this).parents('li');
  144. const data = {
  145. auditorId: parseInt(li.attr('auditorId')),
  146. };
  147. postData('audit/delete', data, (result) => {
  148. li.remove();
  149. for (const rst of result) {
  150. const aLi = $('li[auditorId=' + rst.audit_id + ']');
  151. $('span', aLi).text(rst.order + ' ' + rst.name + ' ');
  152. }
  153. // 如果是重新上报
  154. // 令最后一个图标转换
  155. $('#auditors-list li[data-auditorid="' + data.auditorId + '"]').remove();
  156. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  157. $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
  158. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  159. }
  160. for (let i = 0; i < $('#auditors-list li').length; i++) {
  161. $('#auditors-list li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审');
  162. // $('#auditors-list2 li').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2 li').length ? '终' : transFormToChinese(i+1)) + '审');
  163. }
  164. });
  165. });
  166. // 退回选择修改审批人流程
  167. $('#hideSp').click(function () {
  168. $('#sp-list').modal('hide');
  169. });
  170. $('a[f-target]').click(function () {
  171. $($(this).attr('f-target')).modal('show');
  172. });
  173. // 多层modal关闭后的滚动bug修复
  174. $('#sp-list').on('hidden.bs.modal', function (e) {
  175. $(document.body).addClass('modal-open');
  176. });
  177. // 重新审批获取手机验证码
  178. // 获取验证码
  179. let isPosting = false;
  180. $("#get-code").click(function() {
  181. if (isPosting) return false;
  182. const btn = $(this);
  183. $.ajax({
  184. url: '/profile/code',
  185. type: 'post',
  186. data: { mobile: authMobile, type: 'shenpi' },
  187. dataTye: 'json',
  188. error: function() {
  189. isPosting = false;
  190. let csrfToken = Cookies.get('csrfToken_j');
  191. xhr.setRequestHeader('x-csrf-token', csrfToken);
  192. },
  193. beforeSend: function() {
  194. isPosting = true;
  195. },
  196. success: function(response) {
  197. isPosting = false;
  198. if (response.err === 0) {
  199. codeSuccess(btn);
  200. $("input[name='code']").removeAttr('readonly');
  201. $("#re-shenpi-btn").removeAttr('disabled');
  202. } else {
  203. toast(response.msg, 'error');
  204. }
  205. }
  206. });
  207. });
  208. // 管理员更改审批流程js部分
  209. let timer2 = null;
  210. let oldSearchVal2 = null;
  211. $('body').on('input propertychange', '.gr-search', function(e) {
  212. oldSearchVal2 = e.target.value;
  213. timer2 && clearTimeout(timer2);
  214. timer2 = setTimeout(() => {
  215. const newVal = $(this).val();
  216. const code = $(this).attr('data-code');
  217. let html = '';
  218. if (newVal && newVal === oldSearchVal2) {
  219. accountList.filter(item => item && item.id !== phaseUserId && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  220. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  221. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  222. class="ml-auto">${item.mobile || ''}</span></p>
  223. <span class="text-muted">${item.role || ''}</span>
  224. </dd>`
  225. });
  226. $('#' + code + '_dropdownMenu .book-list').empty();
  227. $('#' + code + '_dropdownMenu .book-list').append(html);
  228. } else {
  229. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  230. accountGroup.forEach((group, idx) => {
  231. if (!group) return;
  232. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  233. </a> ${group.groupName}</dt>
  234. <div class="dd-content" data-toggleid="${idx}">`;
  235. group.groupList.forEach(item => {
  236. if (item.id !== phaseUserId) {
  237. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  238. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  239. class="ml-auto">${item.mobile || ''}</span></p>
  240. <span class="text-muted">${item.role || ''}</span>
  241. </dd>`;
  242. }
  243. });
  244. html += '</div>';
  245. });
  246. $('#' + code + '_dropdownMenu .book-list').empty();
  247. $('#' + code + '_dropdownMenu .book-list').append(html);
  248. }
  249. }
  250. }, 400);
  251. });
  252. const getAdminEditShenpiListHtml = function(auditGroup) {
  253. const html = [];
  254. for (const [i, group] of auditGroup.entries()) {
  255. if (i === 0) continue;
  256. for (const [j, auditor] of group.entries()) {
  257. html.push('<tr>');
  258. if (j === 0) {
  259. 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>`;
  260. html.push(`<td class="text-left d-flex">${i + '审'}${auditTypeHtml}</td>`);
  261. } else {
  262. html.push(`<td class="text-left d-flex"></td>`);
  263. }
  264. html.push(`<td></span> ${auditor.name} <small class="text-muted">${auditor.role}</small></td>`);
  265. 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>`);
  266. html.push('<td style="text-align: center">');
  267. if (auditor.audit_status === auditConst.status.checking && j === group.length - 1) {
  268. html.push('<span class="dropdown mr-2">',
  269. `<a href="javascript: void(0)" class="add-audit" id="${auditor.audit_id}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">增加</a>`,
  270. makeSelectAudit(auditor.audit_id+'_add', auditor.audit_id, 'add'),'</div>', '</span>');
  271. }
  272. if (auditor.audit_status === auditConst.status.uncheck) {
  273. if (j === group.length - 1) {
  274. html.push('<span class="dropdown mr-2">',
  275. `<a href="javascript: void(0)" class="add-audit" id="${auditor.audit_id}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">增加</a>`,
  276. makeSelectAudit(auditor.audit_id+'_add', auditor.audit_id, 'add'),'</div>', '</span>');
  277. if (auditor.audit_type !== auditType.key.common) {
  278. html.push('<span class="dropdown mr-2">',
  279. `<a href="javascript: void(0)" class="add-audit" id="${auditor.audit_id}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">平级</a>`,
  280. makeSelectAudit(auditor.audit_id+'_add-sibling', auditor.audit_id, 'add-sibling'),'</div>', '</span>');
  281. }
  282. }
  283. html.push('<span class="dropdown mr-2">',
  284. `<a href="javascript: void(0)" class="add-audit" id="${auditor.audit_id}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">更换</a>`,
  285. makeSelectAudit(auditor.audit_id+'_change', auditor.audit_id, 'change'),'</div>', '</span>');
  286. html.push(`<span class="dropdown">
  287. <a href="javascript: void(0)" class="text-danger" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">移除</a>
  288. <div class="dropdown-menu">
  289. <span class="dropdown-item" href="javascript:void(0);">确认移除审批人?</span>
  290. <div class="dropdown-divider"></div>
  291. <div class="px-2 py-1 text-center">
  292. <button class="remove-audit btn btn-sm btn-danger" data-id="${auditor.audit_id}">移除</button>
  293. <button class="btn btn-sm btn-secondary">取消</button>
  294. </div>
  295. </div>
  296. </span>`);
  297. }
  298. html.push('</td>');
  299. html.push('</tr>');
  300. }
  301. }
  302. return html.join('');
  303. };
  304. $('body').on('click', '#admin-edit-shenpi dl dd', function () {
  305. const id = parseInt($(this).attr('data-id'));
  306. if (!id) return;
  307. let this_aid = parseInt($(this).parents('.book-list').attr('data-aid'));
  308. let this_operate = $(this).parents('.book-list').attr('data-operate');
  309. const user = _.find(accountList, function (item) {
  310. return item.id === id;
  311. });
  312. const auditorIndex = _.findIndex(auditorList, { audit_id: id });
  313. if (auditorIndex !== -1) {
  314. toastr.warning('该审核人已存在,请勿重复添加');
  315. return;
  316. }
  317. const prop = {
  318. operate: this_operate,
  319. old_aid: this_aid,
  320. new_aid: user.id,
  321. };
  322. postData('audit/save', prop, (datas) => {
  323. $('#admin-edit-shenpi-list').html(getAdminEditShenpiListHtml(datas));
  324. changeLiucheng(datas);
  325. });
  326. });
  327. // 管理员移除审批人
  328. $('body').on('click', '.remove-audit', function () {
  329. const id = parseInt($(this).attr('data-id'));
  330. const prop = {
  331. operate: 'del',
  332. old_aid: id,
  333. };
  334. postData('audit/save', prop, (datas) => {
  335. $('#admin-edit-shenpi-list').html(getAdminEditShenpiListHtml(datas));
  336. changeLiucheng(datas);
  337. });
  338. });
  339. const getAuditTypeText = function (type) {
  340. if (type === auditType.key.common) return '';
  341. return `<span class="text-${auditType.info[type].class}">${auditType.info[type].long}</span>`;
  342. };
  343. function changeLiucheng(datas) {
  344. const auditorshtml = [];
  345. let lastAuditorHtml = [];
  346. for (const [index,data] of datas.entries()) {
  347. auditorshtml.push('<li class="list-group-item d-flex justify-content-between align-items-center">');
  348. if (index === 0) {
  349. auditorshtml.push('<span class="mr-1"><i class="fa fa fa-play-circle fa-rotate-90"></i></span>');
  350. } else if (index+1 === datas.length) {
  351. auditorshtml.push('<span class="mr-1"><i class="fa fa fa-stop-circle"></i></span>');
  352. } else {
  353. auditorshtml.push('<span class="mr-1"><i class="fa fa-chevron-circle-down"></i></span>');
  354. }
  355. auditorshtml.push('<span class="text-muted">');
  356. for (const u of data) {
  357. auditorshtml.push(`<small class="d-inline-block text-dark mx-1" title="${u.role}" data-auditorId="${u.audit_id}">${u.name}</small>`);
  358. }
  359. auditorshtml.push('</span>');
  360. auditorshtml.push('<div class="d-flex ml-auto">');
  361. 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>`);
  362. if (index === 0) {
  363. auditorshtml.push('<span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>');
  364. } else if (index+1 === datas.length) {
  365. auditorshtml.push('<span class="badge badge-light badge-pill"><small>终审</small></span>');
  366. } else {
  367. auditorshtml.push('<span class="badge badge-light badge-pill"><small>'+ transFormToChinese(index) +'审</small></span>');
  368. }
  369. auditorshtml.push('</div>');
  370. auditorshtml.push('</li>');
  371. if (data[0].audit_status === sam_auditConst.status.uncheck) {
  372. lastAuditorHtml.push('<li class="timeline-list-item pb-2 is_uncheck">');
  373. if (index < datas.length - 1) {
  374. lastAuditorHtml.push('<div class="timeline-item-tail"></div>');
  375. }
  376. lastAuditorHtml.push('<div class="timeline-item-icon bg-secondary text-light"></div>');
  377. lastAuditorHtml.push('<div class="timeline-item-content">');
  378. lastAuditorHtml.push(`<div class="py-1">
  379. <span class="text-black-50">
  380. ${ !index === datas.length - 1 ? data[0].audit_order + '' : '终' }审 ${getAuditTypeText(data[0].audit_type)}
  381. </span>
  382. </div>`);
  383. lastAuditorHtml.push('<div class="card"><div class="card-body px-3 py-0">');
  384. for (const [i, auditor] of data.entries()) {
  385. lastAuditorHtml.push(`<div class="card-text p-2 py-3 row ${ ( i > 0 ? 'border-top' : '') }">`);
  386. lastAuditorHtml.push(`<div class="col"><span class="h6">${auditor.name}</span><span class="text-muted ml-1">${auditor.role}</span></div>`);
  387. lastAuditorHtml.push('<div class="col">');
  388. lastAuditorHtml.push('</div>');
  389. lastAuditorHtml.push('</div>');
  390. }
  391. lastAuditorHtml.push('</div></div>');
  392. lastAuditorHtml.push('</div>');
  393. lastAuditorHtml.push('</li>');
  394. }
  395. }
  396. $('.last-auditor-list .is_uncheck').remove();
  397. $('.last-auditor-list').append(lastAuditorHtml.join(''));
  398. $('.auditors-list').html(auditorshtml.join(''));
  399. }
  400. // 审批流程-选择审批人html 生成
  401. function makeSelectAudit(code, aid, status) {
  402. let divhtml = '';
  403. accountGroup.forEach((group, idx) => {
  404. let didivhtml = '';
  405. if(group) {
  406. group.groupList.forEach(item => {
  407. didivhtml += item.id !== phaseUserId ? '<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
  408. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  409. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  410. ' <span class="text-muted">' + item.role + '</span>\n' +
  411. ' </dd>\n' : '';
  412. });
  413. 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' +
  414. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  415. ' </div>\n';
  416. }
  417. });
  418. let html = '<div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  419. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  420. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  421. ' <dl class="list-unstyled book-list" data-aid="'+ aid +'" data-operate="'+ status +'">\n' + divhtml +
  422. ' </dl>\n' +
  423. ' </div>\n' +
  424. ' </div>\n' +
  425. ' </span>\n' +
  426. ' </span>\n' +
  427. ' </li>';
  428. return html;
  429. }
  430. });