material_audit.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2019/2/27
  7. * @version
  8. */
  9. $(document).ready(function () {
  10. // 获取审核相关url
  11. function getUrlPre () {
  12. const path = window.location.pathname.split('/');
  13. return _.take(path, 6).join('/');
  14. }
  15. // 搜索审批人
  16. $('#searchAccount').click(() => {
  17. const data = {
  18. keyword: $('#searchName').val(),
  19. };
  20. postData('/search/user', data, (data) => {
  21. const resultDiv = $('#searchResult');
  22. if (data) {
  23. $('h5>span', resultDiv).text(data.name);
  24. $('#addAuditor').attr('auditorId', data.id);
  25. $('h6', resultDiv).text(data.role);
  26. $('p', resultDiv).text(data.company);
  27. resultDiv.show();
  28. } else {
  29. toast('未查询到该审核人', 'info');
  30. resultDiv.hide();
  31. }
  32. }, () => {
  33. $('#searchResult').hide();
  34. });
  35. });
  36. // 添加审批人
  37. $('#addAuditor').click(() => {
  38. postData(getUrlPre() + '/audit/add', { auditorId: $('#addAuditor').attr('auditorId') }, (data) => {
  39. const html = [];
  40. html.push('<li class="list-group-item" auditorId="'+ data.aid +'"><a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  41. html.push('<span>');
  42. html.push(data.order + ' ');
  43. html.push(data.name + ' ');
  44. html.push('</span>');
  45. html.push('<small class="text-muted">');
  46. html.push(data.role);
  47. html.push('</small></li>');
  48. $('#auditors').append(html.join(''));
  49. });
  50. });
  51. // 审批人分组选择
  52. $('#account_group').change(function () {
  53. let account_html = '<option value="0">选择审批人</option>';
  54. for (const account of accountList) {
  55. if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
  56. const role = account.role !== '' ? '(' + account.role + ')' : '';
  57. const company = account.company !== '' ? ' -' + account.company : '';
  58. account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
  59. }
  60. }
  61. $('#account_list').html(account_html);
  62. });
  63. // 添加到审批流程中
  64. $('body').on('change', '#account_list', function () {
  65. let id = $(this).val();
  66. id = parseInt(id);
  67. if (id !== 0) {
  68. postData(getUrlPre() + '/audit/add', { auditorId: id }, (data) => {
  69. const html = [];
  70. html.push('<li class="list-group-item" auditorId="'+ data.aid +'"><a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  71. html.push('<span>');
  72. html.push(data.order + ' ');
  73. html.push(data.name + ' ');
  74. html.push('</span>');
  75. html.push('<small class="text-muted">');
  76. html.push(data.role);
  77. html.push('</small></li>');
  78. $('#auditors').append(html.join(''));
  79. // 如果是重新上报,添加到重新上报列表中
  80. const auditorshtml = [];
  81. // 重新上报时。令其它的审批人流程图标转换
  82. $('#auditors-list li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  83. for (let i = 0; i < $('#auditors-list li').length; i++) {
  84. $('#auditors-list li').eq(i).find('.pull-right').text(transFormToChinese(i+1) + '审');
  85. $('#auditors-list2 li').eq(i).find('.pull-right').text(transFormToChinese(i+1) + '审');
  86. }
  87. // 添加新审批人
  88. auditorshtml.push('<li class="list-group-item" data-auditid="' + data.aid + '">');
  89. auditorshtml.push('<i class="fa fa-stop-circle"></i> ');
  90. auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  91. auditorshtml.push('<span class="pull-right">终审</span>');
  92. auditorshtml.push('</li>');
  93. $('#auditors-list').append(auditorshtml.join(''));
  94. const auditorshtml2 = [];
  95. // 重新上报时。令其它的审批人流程图标转换
  96. $('#auditors-list2 li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  97. // 添加新审批人
  98. auditorshtml2.push('<li class="list-group-item" data-auditid="' + data.aid + '">');
  99. auditorshtml2.push('<h5 class="card-title"><i class="fa fa-stop-circle"></i> ');
  100. auditorshtml2.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  101. auditorshtml2.push('<span class="pull-right">终审</span>');
  102. auditorshtml2.push('</h5></li>');
  103. $('#auditors-list2').append(auditorshtml2.join(''));
  104. });
  105. }
  106. });
  107. // 删除审批人
  108. $('body').on('click', '#auditors li>a', function () {
  109. const li = $(this).parent();
  110. const data = {
  111. auditorId: parseInt(li.attr('auditorId')),
  112. };
  113. postData(getUrlPre() + '/audit/delete', data, (result) => {
  114. li.remove();
  115. for (const rst of result) {
  116. const aLi = $('li[auditorId=' + rst.aid + ']');
  117. $('span', aLi).text(rst.order + ' ' + rst.name + ' ');
  118. }
  119. // 如果是重新上报
  120. // 令最后一个图标转换
  121. $('#auditors-list li[data-auditid="' + data.auditorId + '"]').remove();
  122. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  123. $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
  124. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  125. }
  126. $('#auditors-list2 li[data-auditid="' + data.auditorId + '"]').remove();
  127. if ($('#auditors-list2 li').length !== 0 && !$('#auditors-list2 li i').hasClass('fa-stop-circle')) {
  128. $('#auditors-list2 li').eq($('#auditors-list2 li').length-1).children('i')
  129. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  130. }
  131. for (let i = 0; i < $('#auditors-list').length; i++) {
  132. $('#auditors-list').eq(i).find('.pull-right').text((i+1 === $('#auditors-list').length ? '终' : transFormToChinese(i+1)) + '审');
  133. $('#auditors-list2').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2').length ? '终' : transFormToChinese(i+1)) + '审');
  134. }
  135. });
  136. });
  137. // 退回选择修改审批人流程
  138. $('#hideSp').click(function () {
  139. $('#sp-list2').modal('hide');
  140. });
  141. $('a[f-target]').click(function () {
  142. $($(this).attr('f-target')).modal('show');
  143. });
  144. // 多层modal关闭后的滚动bug修复
  145. $('#sp-list2').on('hidden.bs.modal', function (e) {
  146. $(document.body).addClass('modal-open');
  147. });
  148. });
  149. // 检查上报情况
  150. function checkAuditorFrom () {
  151. if ($('#auditors li').length === 0) {
  152. toast('请先选择审批人,再上报数据', 'error', 'exclamation-circle');
  153. return false;
  154. }
  155. $('#hide-all').show();
  156. }
  157. // texterea换行
  158. function auditCheck(i) {
  159. const inlineRadio1 = $('#inlineRadio1:checked').val()
  160. const inlineRadio2 = $('#inlineRadio2:checked').val()
  161. const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  162. $('textarea[name="opinion"]').eq(i).val(opinion);
  163. if (i === 1) {
  164. if (!inlineRadio1 && !inlineRadio2) {
  165. if (!$('#warning-text').length) {
  166. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  167. }
  168. return false;
  169. }
  170. if ($('#warning-text').length) $('#warning-text').remove()
  171. }
  172. return true;
  173. }