shenpi.js 15 KB

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