change_project_audit.js 15 KB

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