material_audit.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. // 搜索审批人
  18. // $('#searchAccount').click(() => {
  19. // const data = {
  20. // keyword: $('#searchName').val(),
  21. // };
  22. // postData('/search/user', data, (data) => {
  23. // const resultDiv = $('#searchResult');
  24. // if (data) {
  25. // $('h5>span', resultDiv).text(data.name);
  26. // $('#addAuditor').attr('auditorId', data.id);
  27. // $('h6', resultDiv).text(data.role);
  28. // $('p', resultDiv).text(data.company);
  29. // resultDiv.show();
  30. // } else {
  31. // toast('未查询到该审核人', 'info');
  32. // resultDiv.hide();
  33. // }
  34. // }, () => {
  35. // $('#searchResult').hide();
  36. // });
  37. // });
  38. $('#gr-search').bind('input propertychange', function(e) {
  39. oldSearchVal = e.target.value
  40. timer && clearTimeout(timer)
  41. timer = setTimeout(() => {
  42. const newVal = $('#gr-search').val()
  43. let html = ''
  44. if (newVal && newVal === oldSearchVal) {
  45. accountList.filter(item => item && cur_uid !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  46. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  47. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  48. class="ml-auto">${item.mobile || ''}</span></p>
  49. <span class="text-muted">${item.role || ''}</span>
  50. </dd>`
  51. })
  52. $('.book-list').empty()
  53. $('.book-list').append(html)
  54. } else {
  55. if (!$('.acc-btn').length) {
  56. accountGroup.forEach((group, idx) => {
  57. if (!group) return
  58. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  59. </a> ${group.groupName}</dt>
  60. <div class="dd-content" data-toggleid="${idx}">`
  61. group.groupList.forEach(item => {
  62. if (item.id !== cur_uid) {
  63. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  64. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  65. class="ml-auto">${item.mobile || ''}</span></p>
  66. <span class="text-muted">${item.role || ''}</span>
  67. </dd>`
  68. }
  69. });
  70. html += '</div>'
  71. })
  72. $('.book-list').empty()
  73. $('.book-list').append(html)
  74. }
  75. }
  76. }, 400);
  77. })
  78. // 添加审批人
  79. $('dl').on('click', 'dd', function() {
  80. const id = parseInt($(this).data('id'))
  81. postData(getUrlPre() + '/audit/add', { auditorId: id }, (data) => {
  82. const html = [];
  83. html.push('<li class="list-group-item" auditorId="'+ data.aid +'"><a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  84. html.push('<span>');
  85. html.push(data.order + ' ');
  86. html.push(data.name + ' ');
  87. html.push('</span>');
  88. html.push('<small class="text-muted">');
  89. html.push(data.role);
  90. html.push('</small></li>');
  91. $('#auditors').append(html.join(''));
  92. });
  93. });
  94. // 添加审批流程按钮逻辑
  95. $('.book-list').on('click', '.acc-btn', function () {
  96. const idx = $(this).attr('data-groupid')
  97. const type = $(this).attr('data-type')
  98. if (type === 'hide') {
  99. $(this).parent().parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  100. $(this).children().removeClass('fa-plus-square').addClass('fa-minus-square-o')
  101. $(this).attr('data-type', 'show')
  102. })
  103. } else {
  104. $(this).parent().parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  105. $(this).children().removeClass('fa-minus-square-o').addClass('fa-plus-square')
  106. $(this).attr('data-type', 'hide')
  107. })
  108. }
  109. return false
  110. })
  111. // 审批人分组选择
  112. // $('#account_group').change(function () {
  113. // let account_html = '<option value="0">选择审批人</option>';
  114. // for (const account of accountList) {
  115. // if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
  116. // const role = account.role !== '' ? '(' + account.role + ')' : '';
  117. // const company = account.company !== '' ? ' -' + account.company : '';
  118. // account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
  119. // }
  120. // }
  121. // $('#account_list').html(account_html);
  122. // });
  123. // 添加到审批流程中
  124. $('body').on('change', '#account_list', function () {
  125. let id = $(this).val();
  126. id = parseInt(id);
  127. if (id !== 0) {
  128. postData(getUrlPre() + '/audit/add', { auditorId: id }, (data) => {
  129. const html = [];
  130. html.push('<li class="list-group-item" auditorId="'+ data.aid +'"><a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  131. html.push('<span>');
  132. html.push(data.order + ' ');
  133. html.push(data.name + ' ');
  134. html.push('</span>');
  135. html.push('<small class="text-muted">');
  136. html.push(data.role);
  137. html.push('</small></li>');
  138. $('#auditors').append(html.join(''));
  139. // 如果是重新上报,添加到重新上报列表中
  140. const auditorshtml = [];
  141. // 重新上报时。令其它的审批人流程图标转换
  142. $('#auditors-list li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  143. for (let i = 0; i < $('#auditors-list li').length; i++) {
  144. $('#auditors-list li').eq(i).find('.pull-right').text(transFormToChinese(i+1) + '审');
  145. $('#auditors-list2 li').eq(i).find('.pull-right').text(transFormToChinese(i+1) + '审');
  146. }
  147. // 添加新审批人
  148. auditorshtml.push('<li class="list-group-item" data-auditid="' + data.aid + '">');
  149. auditorshtml.push('<i class="fa fa-stop-circle"></i> ');
  150. auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  151. auditorshtml.push('<span class="pull-right">终审</span>');
  152. auditorshtml.push('</li>');
  153. $('#auditors-list').append(auditorshtml.join(''));
  154. const auditorshtml2 = [];
  155. // 重新上报时。令其它的审批人流程图标转换
  156. $('#auditors-list2 li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  157. // 添加新审批人
  158. auditorshtml2.push('<li class="list-group-item" data-auditid="' + data.aid + '">');
  159. auditorshtml2.push('<h5 class="card-title"><i class="fa fa-stop-circle"></i> ');
  160. auditorshtml2.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  161. auditorshtml2.push('<span class="pull-right">终审</span>');
  162. auditorshtml2.push('</h5></li>');
  163. $('#auditors-list2').append(auditorshtml2.join(''));
  164. });
  165. }
  166. });
  167. // 删除审批人
  168. $('body').on('click', '#auditors li>a', function () {
  169. const li = $(this).parent();
  170. const data = {
  171. auditorId: parseInt(li.attr('auditorId')),
  172. };
  173. postData(getUrlPre() + '/audit/delete', data, (result) => {
  174. li.remove();
  175. for (const rst of result) {
  176. const aLi = $('li[auditorId=' + rst.aid + ']');
  177. $('span', aLi).text(rst.order + ' ' + rst.name + ' ');
  178. }
  179. // 如果是重新上报
  180. // 令最后一个图标转换
  181. $('#auditors-list li[data-auditid="' + data.auditorId + '"]').remove();
  182. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  183. $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
  184. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  185. }
  186. $('#auditors-list2 li[data-auditid="' + data.auditorId + '"]').remove();
  187. if ($('#auditors-list2 li').length !== 0 && !$('#auditors-list2 li i').hasClass('fa-stop-circle')) {
  188. $('#auditors-list2 li').eq($('#auditors-list2 li').length-1).children('i')
  189. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  190. }
  191. for (let i = 0; i < $('#auditors-list').length; i++) {
  192. $('#auditors-list').eq(i).find('.pull-right').text((i+1 === $('#auditors-list').length ? '终' : transFormToChinese(i+1)) + '审');
  193. $('#auditors-list2').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2').length ? '终' : transFormToChinese(i+1)) + '审');
  194. }
  195. });
  196. });
  197. // 退回选择修改审批人流程
  198. $('#hideSp').click(function () {
  199. $('#sp-list').modal('hide');
  200. });
  201. $('a[f-target]').click(function () {
  202. $($(this).attr('f-target')).modal('show');
  203. });
  204. // 多层modal关闭后的滚动bug修复
  205. $('#sp-list').on('hidden.bs.modal', function (e) {
  206. $(document.body).addClass('modal-open');
  207. });
  208. });
  209. // 检查上报情况
  210. function checkAuditorFrom () {
  211. if ($('#auditors li').length === 0) {
  212. toast('请先选择审批人,再上报数据', 'error', 'exclamation-circle');
  213. return false;
  214. }
  215. $('#hide-all').show();
  216. }
  217. // texterea换行
  218. function auditCheck(i) {
  219. const inlineRadio1 = $('#inlineRadio1:checked').val()
  220. const inlineRadio2 = $('#inlineRadio2:checked').val()
  221. const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  222. $('textarea[name="opinion"]').eq(i).val(opinion);
  223. if (i === 1) {
  224. if (!inlineRadio1 && !inlineRadio2) {
  225. if (!$('#warning-text').length) {
  226. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  227. }
  228. return false;
  229. }
  230. if ($('#warning-text').length) $('#warning-text').remove()
  231. }
  232. return true;
  233. }