change_audit.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 && (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 !== changesUid) {
  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', '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. $('#hideSp').click(function () {
  75. $('#sub-sp2').modal('hide');
  76. });
  77. // 添加到审批流程中
  78. $('dl').on('click', 'dd', function () {
  79. const id = parseInt($(this).data('id'));
  80. if (id !== 0) {
  81. postData(getUrlPre() + '/audit/add', { auditorId: id }, (datas) => {
  82. makeSpList(datas);
  83. });
  84. }
  85. });
  86. // 移除审批流程的审批人
  87. $('body').on('click', '#auditList li a', function () {
  88. const uid = $(this).parents('li').attr('data-auditid');
  89. const li = $(this).parents('li');
  90. const data = {
  91. auditorId: uid,
  92. };
  93. postData(getUrlPre() + '/audit/delete', data, (result) => {
  94. li.remove();
  95. let index = 1;
  96. $('#auditList li').each(function () {
  97. $(this).children('.col-auto').eq(0).text(index);
  98. index++;
  99. });
  100. // if (index === 1) {
  101. // $('#account_list').val(0);
  102. // }
  103. // 重新上报时。移除审批流程
  104. // 令最后一个图标转换
  105. $('#auditors-list li[data-auditid="' + uid + '"]').remove();
  106. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li').find('i').hasClass('fa-stop-circle')) {
  107. $('#auditors-list li').eq($('#auditors-list li').length-1).find('i')
  108. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  109. }
  110. for (let i = 0; i < $('#auditors-list li').length; i++) {
  111. $('#auditors-list li').eq(i).find('.badge-pill').children('small').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审');
  112. }
  113. // $('#auditors-list li').eq(0).find('i').removeClass('fa-chevron-circle-down').addClass('fa-play-circle fa-rotate-90');
  114. });
  115. });
  116. // 切换审批组
  117. $('#change-sp-group').change(function () {
  118. const data = {
  119. type: 'change_sp_group',
  120. sp_group: parseInt($(this).val()),
  121. }
  122. if (!data.sp_group) {
  123. toastr.error('请选择固定审批组');
  124. return false;
  125. }
  126. console.log(data);
  127. postData(getUrlPre() + '/audit/spgroup', data, (datas) => {
  128. makeSpList(datas)
  129. });
  130. });
  131. $('a[f-target]').click(function () {
  132. $($(this).attr('f-target')).modal('show');
  133. });
  134. // 多层modal关闭后的滚动bug修复
  135. $('#sp-list').on('hidden.bs.modal', function (e) {
  136. $(document.body).addClass('modal-open');
  137. });
  138. function makeSpList(datas) {
  139. const html = [];
  140. // 如果是重新上报,添加到重新上报列表中
  141. const auditorshtml = [];
  142. for (const [index,data] of datas.entries()) {
  143. if (index !== 0) {
  144. html.push('<li class="list-group-item d-flex" data-auditid="'+ data[0].uid +'">');
  145. html.push(`<div class="col-auto">${index}</div>`);
  146. html.push('<div class="col">');
  147. for (const auditor of data) {
  148. html.push(`<div class="d-inline-block mx-1" auditorId="${auditor.uid}"><i class="fa fa-user text-muted"></i> ${auditor.name} <small class="text-muted">${auditor.role}</small></div>`);
  149. }
  150. html.push('</div>');
  151. html.push('<div class="col-auto">');
  152. // todo 添加会签或签时
  153. if (data[0].audit_type !== auditType.key.common) {
  154. 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>`);
  155. }
  156. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
  157. html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  158. }
  159. html.push('</div>');
  160. html.push('</li>');
  161. }
  162. auditorshtml.push(`<li class="list-group-item d-flex justify-content-between align-items-center" data-auditid="${index !== 0 ? data[0].uid : ''}">`);
  163. auditorshtml.push('<span class="mr-1"><i class="fa ' + (index === 0 ? 'fa-play-circle fa-rotate-90' : index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i></span>');
  164. auditorshtml.push('<span class="text-muted">');
  165. for (const auditor of data) {
  166. auditorshtml.push(`<small class="d-inline-block text-dark mx-1" title="${auditor.role}" data-auditorId="${auditor.uid}">${auditor.name}</small>`);
  167. }
  168. auditorshtml.push('</span>');
  169. auditorshtml.push('<div class="d-flex ml-auto">');
  170. if (data[0].audit_type !== auditType.key.common) {
  171. 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>`);
  172. }
  173. if (index === 0) {
  174. auditorshtml.push('<span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>');
  175. } else if (index+1 === datas.length) {
  176. auditorshtml.push('<span class="badge badge-light badge-pill"><small>终审</small></span>');
  177. } else {
  178. auditorshtml.push('<span class="badge badge-light badge-pill"><small>'+ transFormToChinese(index) +'审</small></span>');
  179. }
  180. auditorshtml.push('</div>');
  181. auditorshtml.push('</li>');
  182. }
  183. $('#auditList').html(html.join(''));
  184. $('#auditors-list').html(auditorshtml.join(''));
  185. }
  186. });
  187. // texterea换行
  188. function auditCheck(i) {
  189. const inlineRadio1 = $('#inlineRadio1:checked').val()
  190. const inlineRadio2 = $('#inlineRadio2:checked').val()
  191. const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  192. $('textarea[name="opinion"]').eq(i).val(opinion);
  193. if (i === 1) {
  194. if (!inlineRadio1 && !inlineRadio2) {
  195. if (!$('#warning-text').length) {
  196. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  197. }
  198. return false;
  199. }
  200. if ($('#warning-text').length) $('#warning-text').remove()
  201. }
  202. return true;
  203. }