change_plan_audit.js 10 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. $('#gr-search').bind('input propertychange', function(e) {
  13. oldSearchVal = e.target.value
  14. timer && clearTimeout(timer)
  15. timer = setTimeout(() => {
  16. const newVal = $('#gr-search').val()
  17. let html = ''
  18. if (newVal && newVal === oldSearchVal) {
  19. accountList.filter(item => item && cur_uid !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  20. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  21. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  22. class="ml-auto">${item.mobile || ''}</span></p>
  23. <span class="text-muted">${item.role || ''}</span>
  24. </dd>`
  25. })
  26. $('.book-list').empty()
  27. $('.book-list').append(html)
  28. } else {
  29. if (!$('.acc-btn').length) {
  30. accountGroup.forEach((group, idx) => {
  31. if (!group) return
  32. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  33. </a> ${group.groupName}</dt>
  34. <div class="dd-content" data-toggleid="${idx}">`
  35. group.groupList.forEach(item => {
  36. if (item.id !== cur_uid) {
  37. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  38. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  39. class="ml-auto">${item.mobile || ''}</span></p>
  40. <span class="text-muted">${item.role || ''}</span>
  41. </dd>`
  42. }
  43. });
  44. html += '</div>'
  45. })
  46. $('.book-list').empty()
  47. $('.book-list').append(html)
  48. }
  49. }
  50. }, 400);
  51. })
  52. // 添加审批流程按钮逻辑
  53. $('body').on('click', '.book-list dt', function () {
  54. const idx = $(this).find('.acc-btn').attr('data-groupid')
  55. const type = $(this).find('.acc-btn').attr('data-type')
  56. if (type === 'hide') {
  57. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  58. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  59. $(this).find('.acc-btn').attr('data-type', 'show')
  60. })
  61. } else {
  62. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  63. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  64. $(this).find('.acc-btn').attr('data-type', 'hide')
  65. })
  66. }
  67. return false
  68. })
  69. // 添加到审批流程中
  70. $('.search-user-list').on('click', 'dd', function () {
  71. const id = parseInt($(this).data('id'));
  72. if (id) {
  73. postData(preUrl + '/audit/add', { auditorId: id }, (datas) => {
  74. makeSpHtml(datas);
  75. });
  76. }
  77. });
  78. // 删除审批人
  79. $('body').on('click', '#auditors li a', function () {
  80. const li = $(this).parents('li');
  81. const data = {
  82. auditorId: parseInt(li.attr('auditorId')),
  83. };
  84. postData(preUrl + '/audit/delete', data, (result) => {
  85. li.remove();
  86. let index = 1;
  87. $('#auditors li').each(function () {
  88. $(this).children('.col-auto').eq(0).text(index);
  89. index++;
  90. });
  91. // 如果是重新上报
  92. // 令最后一个图标转换
  93. $('#auditors-list li[data-auditorId="' + data.auditorId + '"]').remove();
  94. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  95. console.log($('#auditors-list li').length-1, $('#auditors-list li').eq($('#auditors-list li').length-1).find('i'));
  96. $('#auditors-list li').eq($('#auditors-list li').length-1).find('i')
  97. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  98. }
  99. for (let i = 0; i < $('#auditors-list li').length; i++) {
  100. $('#auditors-list li').eq(i).find('.badge-pill').children('small').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审');
  101. }
  102. });
  103. });
  104. // 切换审批组
  105. $('#change-sp-group').change(function () {
  106. const data = {
  107. type: 'change_sp_group',
  108. sp_group: parseInt($(this).val()),
  109. }
  110. if (!data.sp_group) {
  111. toastr.error('请选择固定审批组');
  112. return false;
  113. }
  114. console.log(data);
  115. postData(preUrl + '/audit/spgroup', data, (datas) => {
  116. makeSpHtml(datas);
  117. });
  118. });
  119. // 退回选择修改审批人流程
  120. $('#hideSp').click(function () {
  121. $('#sp-list').modal('hide');
  122. });
  123. $('a[f-target]').click(function () {
  124. $($(this).attr('f-target')).modal('show');
  125. });
  126. // 多层modal关闭后的滚动bug修复
  127. $('#sp-list').on('hidden.bs.modal', function (e) {
  128. $(document.body).addClass('modal-open');
  129. });
  130. });
  131. function makeSpHtml(datas) {
  132. const html = [];
  133. // 如果是重新上报,添加到重新上报列表中
  134. const auditorshtml = [];
  135. for (const [index,data] of datas.entries()) {
  136. if (index !== 0) {
  137. html.push('<li class="list-group-item d-flex" auditorId="'+ data[0].aid +'">');
  138. html.push(`<div class="col-auto">${index}</div>`);
  139. html.push('<div class="col">');
  140. for (const auditor of data) {
  141. html.push(`<div class="d-inline-block mx-1" auditorId="${auditor.uid}"><i class="fa fa-user text-muted"></i> ${auditor.name} <small class="text-muted">${auditor.role}</small></div>`);
  142. }
  143. html.push('</div>');
  144. html.push('<div class="col-auto">');
  145. // todo 添加会签或签时
  146. if (data[0].audit_type !== auditType.key.common) {
  147. html.push(`<span class="badge badge-pill badge-${auditType.info[data[0].audit_type].class} badge-bg-small"><small>${auditType.info[data[0].audit_type].long}</small></span>`);
  148. }
  149. // html.push('<span class="badge badge-pill badge-primary badge-bg-small"><small></small></span>');
  150. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
  151. html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  152. }
  153. html.push('</div>');
  154. html.push('</li>');
  155. }
  156. // 添加新审批人流程修改
  157. auditorshtml.push('<li class="list-group-item d-flex justify-content-between align-items-center" data-auditorid="' + data[0].aid + '">');
  158. auditorshtml.push('<span class="mr-1"><i class="fa ' + (index === 0 ? 'fa-play-circle fa-rotate-90' : index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i></span>');
  159. auditorshtml.push('<span class="text-muted">');
  160. for (const auditor of data) {
  161. auditorshtml.push(`<small class="d-inline-block text-dark mx-1" title="${auditor.role}" data-auditorId="${auditor.uid}">${auditor.name}</small>`);
  162. }
  163. auditorshtml.push('</span>');
  164. auditorshtml.push('<div class="d-flex ml-auto">');
  165. if (data[0].audit_type !== auditType.key.common) {
  166. auditorshtml.push(`<span class="badge badge-pill badge-${auditType.info[data[0].audit_type].class} p-1"><small>${auditType.info[data[0].audit_type].short}</small></span>`);
  167. }
  168. if (index === 0) {
  169. auditorshtml.push('<span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>');
  170. } else if (index+1 === datas.length) {
  171. auditorshtml.push('<span class="badge badge-light badge-pill"><small>终审</small></span>');
  172. } else {
  173. auditorshtml.push('<span class="badge badge-light badge-pill"><small>'+ transFormToChinese(index) +'审</small></span>');
  174. }
  175. auditorshtml.push('</div>');
  176. auditorshtml.push('</li>');
  177. }
  178. $('#auditors').html(html.join(''));
  179. $('#auditors-list').html(auditorshtml.join(''));
  180. }
  181. // 检查上报情况
  182. function checkAuditorFrom () {
  183. if ($('#auditors li').length === 0) {
  184. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  185. toastr.error('请联系管理员添加审批人');
  186. } else {
  187. toastr.error('请先选择审批人,再上报数据');
  188. }
  189. return false;
  190. }
  191. let flag = false;
  192. if (change.code === '') {
  193. toastr.error('变更方案编号不能为空');
  194. flag = true;
  195. }
  196. if (!change.name) {
  197. toastr.error('变更工程名称不能为空');
  198. flag = true;
  199. }
  200. if (!change.reason) {
  201. toastr.error('变更原因不能为空');
  202. flag = true;
  203. }
  204. // 判断变更清单是否有空值
  205. const nullCodeList = _.filter(changeList, function(item) {
  206. return item.code === null || item.code === '';
  207. });
  208. if (nullCodeList.length > 0) {
  209. toastr.error('变更清单都需要设置清单编号才能上报');
  210. flag = true;
  211. }
  212. if (flag) {
  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. }