shenpi.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/10/09
  7. * @version
  8. */
  9. $(document).ready(function () {
  10. let timer = null;
  11. let oldSearchVal = null;
  12. $('body').on('input propertychange', '.gr-search', function(e) {
  13. oldSearchVal = e.target.value;
  14. timer && clearTimeout(timer);
  15. timer = setTimeout(() => {
  16. const newVal = $(this).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. $('.form-check input').on('change', function () {
  71. // 获取所有审批的checked值并更新
  72. const this_status = parseInt($(this).val());
  73. const this_code = $(this).data('code');
  74. const spt = sp_status_list[this_status];
  75. $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
  76. // 拼接post json
  77. const prop = {
  78. code: this_code,
  79. status: this_status
  80. };
  81. const _self = $(this);
  82. const tenderId = window.location.pathname.split('/')[2];
  83. postData('/tender/' + tenderId + '/shenpi/save', prop, function (data) {
  84. if (this_status === sp_status.sqspr) {
  85. _self.parents('.form-group').siblings('.lc-show').html('');
  86. } else if (this_status === sp_status.gdspl) {
  87. let addhtml = '<ul class="list-unstyled">\n';
  88. if (data.length !== 0) {
  89. for(const [i, audit] of data.entries()) {
  90. addhtml += makeAudit(audit, transFormToChinese(i+1));
  91. }
  92. addhtml += '<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>';
  93. } else {
  94. addhtml += makeSelectAudit(this_code, '一');
  95. }
  96. addhtml += '</ul>\n';
  97. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  98. } else if (this_status === sp_status.gdzs) {
  99. let addhtml = '<ul class="list-unstyled">\n' +
  100. ' <li class="d-flex justify-content-start mb-3">\n' +
  101. ' <span class="col-auto">授权审批人</span>\n' +
  102. ' <span class="col-7">\n' +
  103. ' <span class="d-inline-block"></span>\n' +
  104. ' </span>\n' +
  105. ' </li>\n';
  106. addhtml += data ? makeAudit(data) : makeSelectAudit(this_code);
  107. addhtml += '</ul>\n';
  108. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  109. }
  110. });
  111. });
  112. // 选中审批人
  113. $('body').on('click', 'dl dd', function () {
  114. const id = parseInt($(this).data('id'));
  115. if (id) {
  116. const user = _.find(accountList, function (item) {
  117. return item.id === id;
  118. });
  119. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  120. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  121. if (this_status === sp_status.gdspl) {
  122. // 判断是否已存在审批人
  123. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  124. for (let i = 0; i < aid_num; i++) {
  125. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  126. if (aid === id) {
  127. toastr.warning('该审核人已存在,请勿重复添加');
  128. return;
  129. }
  130. }
  131. }
  132. const prop = {
  133. status: this_status,
  134. code: sp_type[this_code],
  135. audit_id: id,
  136. type: 'add',
  137. };
  138. const _self = $(this);
  139. const tenderId = window.location.pathname.split('/')[2];
  140. postData('/tender/' + tenderId + '/shenpi/audit/save', prop, function (data) {
  141. if (this_status === sp_status.gdspl) {
  142. _self.parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
  143. }
  144. _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  145. '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="'+ user.id +'"><i class="fa fa-remove"></i></a></span> </span>');
  146. });
  147. }
  148. });
  149. // 移除审批人
  150. $('body').on('click', '.remove-audit', function () {
  151. const id = parseInt($(this).data('id'));
  152. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  153. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  154. const prop = {
  155. status: this_status,
  156. code: sp_type[this_code],
  157. audit_id: id,
  158. type: 'del',
  159. };
  160. const _self = $(this);
  161. const tenderId = window.location.pathname.split('/')[2];
  162. postData('/tender/' + tenderId + '/shenpi/audit/save', prop, function (data) {
  163. if (this_status === sp_status.gdspl) {
  164. const _selflc = _self.parents('.lc-show');
  165. _self.parents('li').remove();
  166. const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
  167. if (aid_num === 0) {
  168. let addhtml = '<ul class="list-unstyled">\n';
  169. addhtml += makeSelectAudit(this_code, '一');
  170. addhtml += '</ul>\n';
  171. _selflc.html(addhtml);
  172. } else {
  173. for (let i = 0; i < aid_num; i++) {
  174. _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  175. }
  176. }
  177. } else if (this_status === sp_status.gdzs) {
  178. let addhtml = '<ul class="list-unstyled">\n' +
  179. ' <li class="d-flex justify-content-start mb-3">\n' +
  180. ' <span class="col-auto">授权审批人</span>\n' +
  181. ' <span class="col-7">\n' +
  182. ' <span class="d-inline-block"></span>\n' +
  183. ' </span>\n' +
  184. ' </li>\n';
  185. addhtml += makeSelectAudit(this_code);
  186. addhtml += '</ul>\n';
  187. _self.parents('.lc-show').html(addhtml);
  188. }
  189. })
  190. });
  191. // 固定审批流-添加流程
  192. $('body').on('click', '.add-audit', function () {
  193. const num = $(this).parents('ul').children('li').length;
  194. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  195. const addhtml = makeSelectAudit(this_code, transFormToChinese(num));
  196. $(this).parents('ul').append(addhtml);
  197. $(this).parents('li').remove();
  198. });
  199. // 审批流程-审批人html 生成
  200. function makeAudit(audit, i = '终') {
  201. return '<li class="d-flex justify-content-start mb-3">\n' +
  202. ' <span class="col-auto">'+ i +'审</span>\n' +
  203. ' <span class="col-7 spr-span">\n' +
  204. ' <span class="d-inline-block"></span>\n' +
  205. ' <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="'+ audit.audit_id +'"><i class="fa fa-remove"></i></a></span> </span>\n' +
  206. ' </span>\n' +
  207. ' </li>';
  208. }
  209. // 审批流程-选择审批人html 生成
  210. function makeSelectAudit(code, i = '终') {
  211. let divhtml = '';
  212. accountGroup.forEach((group, idx) => {
  213. let didivhtml = '';
  214. if(group) {
  215. group.groupList.forEach(item => {
  216. didivhtml += item.id !== cur_uid ? '<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
  217. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  218. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  219. ' <span class="text-muted">' + item.role + '</span>\n' +
  220. ' </dd>\n' : '';
  221. });
  222. divhtml += '<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="' + idx + '" data-type="hide"><i class="fa fa-plus-square"></i></a> ' + group.groupName + '</dt>\n' +
  223. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  224. ' </div>\n';
  225. }
  226. });
  227. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  228. ' <span class="col-auto">' + i + '审</span>\n' +
  229. ' <span class="col-7 spr-span">\n' +
  230. ' <span class="d-inline-block">\n' +
  231. ' <div class="dropdown text-right">\n' +
  232. ' <button class="btn btn-outline-primary btn-sm dropdown-toggle" type="button" id="' + code + '_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  233. ' 选择审批人\n' +
  234. ' </button>\n' +
  235. ' <div class="dropdown-menu dropdown-menu-right" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  236. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  237. ' placeholder="姓名/手机 检索" autocomplete="off"></div>\n' +
  238. ' <dl class="list-unstyled book-list">\n' + divhtml +
  239. ' </dl>\n' +
  240. ' </div>\n' +
  241. ' </div>\n' +
  242. ' </span>\n' +
  243. ' </span>\n' +
  244. ' </li>';
  245. return html;
  246. }
  247. });