material_audit.js 9.6 KB

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