change_project_audit.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. let timer2 = null
  13. let oldSearchVal2 = null
  14. $('#gr-search').bind('input propertychange', function(e) {
  15. oldSearchVal = e.target.value
  16. timer && clearTimeout(timer)
  17. timer = setTimeout(() => {
  18. const newVal = $('#gr-search').val()
  19. let html = ''
  20. if (newVal && newVal === oldSearchVal) {
  21. accountList.filter(item => item && cur_uid !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  22. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  23. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  24. class="ml-auto">${item.mobile || ''}</span></p>
  25. <span class="text-muted">${item.role || ''}</span>
  26. </dd>`
  27. })
  28. $('.search-user-list').empty()
  29. $('.search-user-list').append(html)
  30. } else {
  31. if (!$('.acc-btn').length) {
  32. accountGroup.forEach((group, idx) => {
  33. if (!group) return
  34. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  35. </a> ${group.groupName}</dt>
  36. <div class="dd-content" data-toggleid="${idx}">`
  37. group.groupList.forEach(item => {
  38. if (item.id !== cur_uid) {
  39. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  40. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  41. class="ml-auto">${item.mobile || ''}</span></p>
  42. <span class="text-muted">${item.role || ''}</span>
  43. </dd>`
  44. }
  45. });
  46. html += '</div>'
  47. })
  48. $('.search-user-list').empty()
  49. $('.search-user-list').append(html)
  50. }
  51. }
  52. }, 400);
  53. })
  54. // 添加审批流程按钮逻辑
  55. $('.search-user-list').on('click', 'dt', function () {
  56. const idx = $(this).find('.acc-btn').attr('data-groupid')
  57. const type = $(this).find('.acc-btn').attr('data-type')
  58. if (type === 'hide') {
  59. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  60. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  61. $(this).find('.acc-btn').attr('data-type', 'show')
  62. })
  63. } else {
  64. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  65. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  66. $(this).find('.acc-btn').attr('data-type', 'hide')
  67. })
  68. }
  69. return false
  70. })
  71. // 添加到审批流程中
  72. $('.search-user-list').on('click', 'dd', function () {
  73. const id = parseInt($(this).data('id'));
  74. if (id) {
  75. postData(preUrl + '/audit/add', { auditorId: id }, (datas) => {
  76. makeSpHtml(datas);
  77. });
  78. }
  79. });
  80. // 删除审批人
  81. $('body').on('click', '#auditors li a', function () {
  82. const li = $(this).parents('li');
  83. const data = {
  84. auditorId: parseInt(li.attr('auditorId')),
  85. };
  86. console.log(data);
  87. postData(preUrl + '/audit/delete', data, (result) => {
  88. li.remove();
  89. let index = 1;
  90. $('#auditors li').each(function () {
  91. $(this).children('.col-auto').eq(0).text(index);
  92. index++;
  93. });
  94. // 如果是重新上报
  95. // 令最后一个图标转换
  96. $('#auditors-list li[data-auditorId="' + data.auditorId + '"]').remove();
  97. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  98. console.log($('#auditors-list li').length-1, $('#auditors-list li').eq($('#auditors-list li').length-1).find('i'));
  99. $('#auditors-list li').eq($('#auditors-list li').length-1).find('i')
  100. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  101. }
  102. for (let i = 0; i < $('#auditors-list li').length; i++) {
  103. $('#auditors-list li').eq(i).find('.badge-pill').children('small').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审');
  104. }
  105. });
  106. });
  107. // 协审人搜索
  108. $('#gr-search2').bind('input propertychange', function(e) {
  109. oldSearchVal2 = e.target.value;
  110. timer2 && clearTimeout(timer2);
  111. timer2 = setTimeout(() => {
  112. const newVal = $('#gr-search2').val();
  113. let html = '';
  114. if (newVal && newVal === oldSearchVal2) {
  115. accountList.filter(item => item && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  116. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  117. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  118. class="ml-auto">${item.mobile || ''}</span></p>
  119. <span class="text-muted">${item.role || ''}</span>
  120. </dd>`
  121. })
  122. $('.search-user-list2').empty();
  123. $('.search-user-list2').append(html);
  124. } else {
  125. if (!$('.acc-btn').length) {
  126. accountGroup.forEach((group, idx) => {
  127. if (!group) return
  128. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  129. </a> ${group.groupName}</dt>
  130. <div class="dd-content" data-toggleid="${idx}">`
  131. group.groupList.forEach(item => {
  132. if (item.id !== change.uid) {
  133. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  134. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  135. class="ml-auto">${item.mobile || ''}</span></p>
  136. <span class="text-muted">${item.role || ''}</span>
  137. </dd>`
  138. }
  139. });
  140. html += '</div>'
  141. })
  142. $('.search-user-list2').empty();
  143. $('.search-user-list2').append(html);
  144. }
  145. }
  146. }, 400);
  147. })
  148. // 添加审批流程按钮逻辑
  149. $('.search-user-list2').on('click', 'dt', function () {
  150. const idx = $(this).find('.acc-btn').attr('data-groupid')
  151. const type = $(this).find('.acc-btn').attr('data-type')
  152. if (type === 'hide') {
  153. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  154. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  155. $(this).find('.acc-btn').attr('data-type', 'show')
  156. })
  157. } else {
  158. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  159. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  160. $(this).find('.acc-btn').attr('data-type', 'hide')
  161. })
  162. }
  163. return false
  164. });
  165. // 添加到审批流程中
  166. $('.search-user-list2').on('click', 'dd', function () {
  167. const id = parseInt($(this).data('id'));
  168. if (id) {
  169. console.log(id);
  170. postData(preUrl + '/xsaudit/add', { auditorId: id }, (data) => {
  171. const html = [];
  172. html.push('<span class="d-inline-block">\n' +
  173. ' <span class="badge badge-light">\n' +
  174. ' ' + data.name + '\n' +
  175. ' <span class="dropdown">\n' +
  176. ' <a href="javascript:void(0)" class="btn-sm text-danger px-1" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-remove"></i></a>\n' +
  177. ' <div class="dropdown-menu">\n' +
  178. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  179. ' <div class="dropdown-divider"></div>\n' +
  180. ' <div class="px-2 py-1 text-center">\n' +
  181. ' <button class="btn btn-sm btn-danger" aid="'+ data.aid +'">移除</button>\n' +
  182. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  183. ' </div>\n' +
  184. ' </div>\n' +
  185. ' </span>\n' +
  186. ' </span>\n' +
  187. ' </span> ');
  188. $('#xs-list').append(html.join(''));
  189. });
  190. }
  191. });
  192. // 删除审批人
  193. $('body').on('click', '#xs-list .btn-danger', function () {
  194. const li = $(this).parents('.d-inline-block');
  195. const data = {
  196. auditorId: parseInt($(this).attr('aid')),
  197. };
  198. postData(preUrl + '/xsaudit/delete', data, (result) => {
  199. li.remove();
  200. });
  201. });
  202. // 切换审批组
  203. $('#change-sp-group').change(function () {
  204. const data = {
  205. type: 'change_sp_group',
  206. sp_group: parseInt($(this).val()),
  207. }
  208. if (!data.sp_group) {
  209. toastr.error('请选择固定审批组');
  210. return false;
  211. }
  212. console.log(data);
  213. postData(preUrl + '/audit/spgroup', data, (datas) => {
  214. makeSpHtml(datas);
  215. });
  216. });
  217. // 退回选择修改审批人流程
  218. $('#hideSp').click(function () {
  219. $('#sp-list').modal('hide');
  220. });
  221. $('a[f-target]').click(function () {
  222. $($(this).attr('f-target')).modal('show');
  223. });
  224. // 多层modal关闭后的滚动bug修复
  225. $('#sp-list').on('hidden.bs.modal', function (e) {
  226. $(document.body).addClass('modal-open');
  227. });
  228. });
  229. function makeSpHtml(datas) {
  230. const html = [];
  231. // 如果是重新上报,添加到重新上报列表中
  232. const auditorshtml = [];
  233. for (const [index,data] of datas.entries()) {
  234. if (index !== 0) {
  235. html.push('<li class="list-group-item d-flex" auditorId="'+ data[0].aid +'">');
  236. html.push(`<div class="col-auto">${index}</div>`);
  237. html.push('<div class="col">');
  238. for (const auditor of data) {
  239. 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>`);
  240. }
  241. html.push('</div>');
  242. html.push('<div class="col-auto">');
  243. // todo 添加会签或签时
  244. if (data[0].audit_type !== auditType.key.common) {
  245. 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>`);
  246. }
  247. // html.push('<span class="badge badge-pill badge-primary badge-bg-small"><small></small></span>');
  248. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
  249. html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  250. }
  251. html.push('</div>');
  252. html.push('</li>');
  253. }
  254. // 添加新审批人流程修改
  255. auditorshtml.push('<li class="list-group-item d-flex justify-content-between align-items-center" data-auditorid="' + data[0].aid + '">');
  256. 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>');
  257. auditorshtml.push('<span class="text-muted">');
  258. for (const auditor of data) {
  259. auditorshtml.push(`<small class="d-inline-block text-dark mx-1" title="${auditor.role}" data-auditorId="${auditor.uid}">${auditor.name}</small>`);
  260. }
  261. auditorshtml.push('</span>');
  262. auditorshtml.push('<div class="d-flex ml-auto">');
  263. if (data[0].audit_type !== auditType.key.common) {
  264. 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>`);
  265. }
  266. if (index === 0) {
  267. auditorshtml.push('<span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>');
  268. } else if (index+1 === datas.length) {
  269. auditorshtml.push('<span class="badge badge-light badge-pill"><small>终审</small></span>');
  270. } else {
  271. auditorshtml.push('<span class="badge badge-light badge-pill"><small>'+ transFormToChinese(index) +'审</small></span>');
  272. }
  273. auditorshtml.push('</div>');
  274. auditorshtml.push('</li>');
  275. }
  276. $('#auditors').html(html.join(''));
  277. $('#auditors-list').html(auditorshtml.join(''));
  278. }
  279. // 检查上报情况
  280. function checkAuditorFrom () {
  281. if ($('#auditors li').length === 0) {
  282. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  283. toastr.error('请联系管理员添加审批人');
  284. } else {
  285. toastr.error('请先选择审批人,再上报数据');
  286. }
  287. return false;
  288. }
  289. let flag = false;
  290. if (change.code === '') {
  291. toastr.error('立项书编号不能为空');
  292. flag = true;
  293. }
  294. if (change.name === '') {
  295. toastr.error('变更工程名称不能为空');
  296. flag = true;
  297. }
  298. if (!change.reason) {
  299. toastr.error('变更原因不能为空');
  300. flag = true;
  301. }
  302. if (flag) {
  303. return false;
  304. }
  305. $('#hide-all').show();
  306. }
  307. // texterea换行
  308. function auditCheck(i) {
  309. // const inlineRadio1 = $('#inlineRadio1:checked').val()
  310. // const inlineRadio2 = $('#inlineRadio2:checked').val()
  311. const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  312. $('textarea[name="opinion"]').eq(i).val(opinion);
  313. if (i === 2) {
  314. if ($('textarea[name="opinion"]').eq(i).val() === '') {
  315. toastr.error('请输入终止原因');
  316. return false;
  317. }
  318. }
  319. // if (i === 1) {
  320. // if (!inlineRadio1 && !inlineRadio2) {
  321. // if (!$('#warning-text').length) {
  322. // $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  323. // }
  324. // return false;
  325. // }
  326. // if ($('#warning-text').length) $('#warning-text').remove()
  327. // }
  328. return true;
  329. }