change_audit.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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) {
  81. const auditListIdData = [];
  82. $('#auditList li').each(function () {
  83. const aid = $(this).data('auditid');
  84. auditListIdData.push(aid);
  85. });
  86. if (!in_array(auditListIdData, id)) {
  87. postData(getUrlPre() + '/audit/add', { auditorId: id }, (datas) => {
  88. if (shenpi_status === shenpiConst.sp_status.gdzs) {
  89. auditListIdData.splice(-1,0,id);
  90. } else {
  91. auditListIdData.push(id);
  92. }
  93. const html = [];
  94. const auditorshtml = [];
  95. auditListIdData.unshift(changesUid);
  96. for (const [index,ids] of auditListIdData.entries()) {
  97. const accountInfo = _.find(accountList, { 'id': ids });
  98. if (index !== 0) {
  99. const user = accountInfo.id + '/%/' + accountInfo.name + '/%/' + accountInfo.role + '/%/' + accountInfo.company;
  100. html.push('<li class="list-group-item" data-auditmsg="' + user + '" data-auditid="'+ ids +'">');
  101. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== auditListIdData.length)) {
  102. html.push('<a href="javascript:void(0);" class="text-danger pull-right remove_audit_btn">移除</a>');
  103. }
  104. html.push('<span>');
  105. html.push(index + ' ');
  106. html.push('</span> ');
  107. html.push(accountInfo.name + ' ');
  108. html.push('<small class="text-muted">');
  109. html.push(accountInfo.role);
  110. html.push('</small>');
  111. html.push('<p class="m-0 ml-2"><small class="text-muted">' + accountInfo.company + '</small></p>');
  112. html.push('</li>');
  113. }
  114. // 添加新审批人流程修改
  115. auditorshtml.push('<li class="list-group-item" ' + (index !== 0 ? 'data-auditid="' + accountInfo.id + '"' : '') + '>');
  116. auditorshtml.push('<i class="fa ' + (index+1 === auditListIdData.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
  117. auditorshtml.push(accountInfo.name + ' <small class="text-muted">' + accountInfo.role + '</small>');
  118. if (index === 0) {
  119. auditorshtml.push('<span class="pull-right">原报</span>');
  120. } else if (index+1 === auditListIdData.length) {
  121. auditorshtml.push('<span class="pull-right">终审</span>');
  122. } else {
  123. auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
  124. }
  125. auditorshtml.push('</li>');
  126. }
  127. $('#auditList').html(html.join(''));
  128. $('#shenpi-audit-list').html(auditorshtml.join(''));
  129. });
  130. } else {
  131. toastr.error('审批流程中已存在该用户!');
  132. }
  133. }
  134. });
  135. // 移除审批流程的审批人
  136. $('body').on('click', '.remove_audit_btn', function () {
  137. const uid = $(this).parents('li').attr('data-auditid');
  138. const li = $(this).parent();
  139. const data = {
  140. auditorId: uid,
  141. };
  142. postData(getUrlPre() + '/audit/delete', data, (result) => {
  143. li.remove();
  144. let index = 1;
  145. $('#auditList li').each(function () {
  146. $(this).children('span').text(index);
  147. index++;
  148. });
  149. if (index === 1) {
  150. $('#account_list').val(0);
  151. }
  152. // 重新上报时。移除审批流程
  153. // 令最后一个图标转换
  154. $('#shenpi-audit-list li[data-auditid="' + uid + '"]').remove();
  155. if ($('#shenpi-audit-list li').length !== 0 && !$('#shenpi-audit-list li i').hasClass('fa-stop-circle')) {
  156. $('#shenpi-audit-list li').eq($('#shenpi-audit-list li').length-1).children('i')
  157. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  158. }
  159. for (let i = 0; i < $('#shenpi-audit-list li').length; i++) {
  160. $('#shenpi-audit-list li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#shenpi-audit-list li').length ? '终' : transFormToChinese(i)) + '审');
  161. }
  162. $('#shenpi-audit-list li i').eq(0).removeClass('fa-chevron-circle-down').addClass('fa-play-circle');
  163. });
  164. });
  165. $('a[f-target]').click(function () {
  166. $($(this).attr('f-target')).modal('show');
  167. });
  168. // 多层modal关闭后的滚动bug修复
  169. $('#sp-list').on('hidden.bs.modal', function (e) {
  170. $(document.body).addClass('modal-open');
  171. });
  172. });
  173. // texterea换行
  174. function auditCheck(i) {
  175. const inlineRadio1 = $('#inlineRadio1:checked').val()
  176. const inlineRadio2 = $('#inlineRadio2:checked').val()
  177. const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  178. $('textarea[name="opinion"]').eq(i).val(opinion);
  179. if (i === 1) {
  180. if (!inlineRadio1 && !inlineRadio2) {
  181. if (!$('#warning-text').length) {
  182. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  183. }
  184. return false;
  185. }
  186. if ($('#warning-text').length) $('#warning-text').remove()
  187. }
  188. return true;
  189. }