material_audit.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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', '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. $('dl').on('click', 'dd', function () {
  76. const id = parseInt($(this).data('id'))
  77. if (id) {
  78. postData(getUrlPre() + '/audit/add', { auditorId: id }, (data) => {
  79. const html = [];
  80. html.push('<li class="list-group-item" auditorId="'+ data.aid +'"><a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  81. html.push('<span>');
  82. html.push(data.order + ' ');
  83. html.push(data.name + ' ');
  84. html.push('</span>');
  85. html.push('<small class="text-muted">');
  86. html.push(data.role);
  87. html.push('</small></li>');
  88. $('#auditors').append(html.join(''));
  89. // 如果是重新上报,添加到重新上报列表中
  90. const auditorshtml = [];
  91. // 重新上报时。令其它的审批人流程图标转换
  92. $('#auditors-list li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  93. for (let i = 0; i < $('#auditors-list li').length; i++) {
  94. $('#auditors-list li').eq(i).find('.pull-right').text(transFormToChinese(i+1) + '审');
  95. $('#auditors-list2 li').eq(i).find('.pull-right').text(transFormToChinese(i+1) + '审');
  96. }
  97. // 添加新审批人
  98. auditorshtml.push('<li class="list-group-item" data-auditid="' + data.aid + '">');
  99. auditorshtml.push('<i class="fa fa-stop-circle"></i> ');
  100. auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  101. auditorshtml.push('<span class="pull-right">终审</span>');
  102. auditorshtml.push('</li>');
  103. $('#auditors-list').append(auditorshtml.join(''));
  104. const auditorshtml2 = [];
  105. // 重新上报时。令其它的审批人流程图标转换
  106. $('#auditors-list2 li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  107. // 添加新审批人
  108. auditorshtml2.push('<li class="list-group-item" data-auditid="' + data.aid + '">');
  109. auditorshtml2.push('<h5 class="card-title"><i class="fa fa-stop-circle"></i> ');
  110. auditorshtml2.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  111. auditorshtml2.push('<span class="pull-right">终审</span>');
  112. auditorshtml2.push('</h5></li>');
  113. $('#auditors-list2').append(auditorshtml2.join(''));
  114. });
  115. }
  116. });
  117. // 删除审批人
  118. $('body').on('click', '#auditors li>a', function () {
  119. const li = $(this).parent();
  120. const data = {
  121. auditorId: parseInt(li.attr('auditorId')),
  122. };
  123. postData(getUrlPre() + '/audit/delete', data, (result) => {
  124. li.remove();
  125. for (const rst of result) {
  126. const aLi = $('li[auditorId=' + rst.aid + ']');
  127. $('span', aLi).text(rst.order + ' ' + rst.name + ' ');
  128. }
  129. // 如果是重新上报
  130. // 令最后一个图标转换
  131. $('#auditors-list li[data-auditid="' + data.auditorId + '"]').remove();
  132. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  133. $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
  134. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  135. }
  136. $('#auditors-list2 li[data-auditid="' + data.auditorId + '"]').remove();
  137. if ($('#auditors-list2 li').length !== 0 && !$('#auditors-list2 li i').hasClass('fa-stop-circle')) {
  138. $('#auditors-list2 li').eq($('#auditors-list2 li').length-1).children('i')
  139. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  140. }
  141. for (let i = 0; i < $('#auditors-list').length; i++) {
  142. $('#auditors-list').eq(i).find('.pull-right').text((i+1 === $('#auditors-list').length ? '终' : transFormToChinese(i+1)) + '审');
  143. $('#auditors-list2').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2').length ? '终' : transFormToChinese(i+1)) + '审');
  144. }
  145. });
  146. });
  147. // 退回选择修改审批人流程
  148. $('#hideSp').click(function () {
  149. $('#sp-list').modal('hide');
  150. });
  151. $('a[f-target]').click(function () {
  152. $($(this).attr('f-target')).modal('show');
  153. });
  154. // 多层modal关闭后的滚动bug修复
  155. $('#sp-list').on('hidden.bs.modal', function (e) {
  156. $(document.body).addClass('modal-open');
  157. });
  158. });
  159. // 检查上报情况
  160. function checkAuditorFrom () {
  161. if ($('#auditors li').length === 0) {
  162. toast('请先选择审批人,再上报数据', 'error', 'exclamation-circle');
  163. return false;
  164. }
  165. $('#hide-all').show();
  166. }
  167. // texterea换行
  168. function auditCheck(i) {
  169. const inlineRadio1 = $('#inlineRadio1:checked').val()
  170. const inlineRadio2 = $('#inlineRadio2:checked').val()
  171. const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  172. $('textarea[name="opinion"]').eq(i).val(opinion);
  173. if (i === 1) {
  174. if (!inlineRadio1 && !inlineRadio2) {
  175. if (!$('#warning-text').length) {
  176. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  177. }
  178. return false;
  179. }
  180. if ($('#warning-text').length) $('#warning-text').remove()
  181. }
  182. return true;
  183. }