shenpi.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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').bind('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. if (this_status === sp_status.sqspr) {
  77. $(this).parents('.form-group').siblings('.lc-show').html('');
  78. } else if (this_status === sp_status.gdspl) {
  79. let addhtml = '<ul class="list-unstyled">\n';
  80. addhtml += makeSelectAudit(this_code, '一');
  81. addhtml += '</ul>\n';
  82. $(this).parents('.form-group').siblings('.lc-show').html(addhtml);
  83. } else if (this_status === sp_status.gdzs) {
  84. let addhtml = '<ul class="list-unstyled">\n' +
  85. ' <li class="d-flex justify-content-start mb-3">\n' +
  86. ' <span class="col-auto">授权审批人</span>\n' +
  87. ' <span class="col-7">\n' +
  88. ' <span class="d-inline-block"></span>\n' +
  89. ' </span>\n' +
  90. ' </li>\n';
  91. addhtml += makeSelectAudit(this_code);
  92. addhtml += '</ul>\n';
  93. $(this).parents('.form-group').siblings('.lc-show').html(addhtml);
  94. }
  95. });
  96. // 选中审批人
  97. $('body').on('click', 'dl dd', function () {
  98. const id = parseInt($(this).data('id'));
  99. if (id) {
  100. const user = _.find(accountList, function (item) {
  101. return item.id === id;
  102. });
  103. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  104. if (this_status === sp_status.gdspl) {
  105. // 判断是否已存在审批人
  106. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  107. for (let i = 0; i < aid_num; i++) {
  108. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  109. if (aid === id) {
  110. toastr.warning('该审核人已存在,请勿重复添加');
  111. return;
  112. }
  113. }
  114. $(this).parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
  115. }
  116. $(this).parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  117. '<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>');
  118. }
  119. });
  120. // 移除审批人
  121. $('body').on('click', '.remove-audit', function () {
  122. const id = parseInt($(this).data('id'));
  123. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  124. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  125. if (this_status === sp_status.gdspl) {
  126. const _self = $(this).parents('.lc-show');
  127. $(this).parents('li').remove();
  128. const aid_num = parseInt(_self.children('ul').find('li.d-flex').length);
  129. if (aid_num === 0) {
  130. let addhtml = '<ul class="list-unstyled">\n';
  131. addhtml += makeSelectAudit(this_code, '一');
  132. addhtml += '</ul>\n';
  133. _self.html(addhtml);
  134. } else {
  135. for (let i = 0; i < aid_num; i++) {
  136. _self.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  137. }
  138. }
  139. } else if (this_status === sp_status.gdzs) {
  140. let addhtml = '<ul class="list-unstyled">\n' +
  141. ' <li class="d-flex justify-content-start mb-3">\n' +
  142. ' <span class="col-auto">授权审批人</span>\n' +
  143. ' <span class="col-7">\n' +
  144. ' <span class="d-inline-block"></span>\n' +
  145. ' </span>\n' +
  146. ' </li>\n';
  147. addhtml += makeSelectAudit(this_code);
  148. addhtml += '</ul>\n';
  149. $(this).parents('.lc-show').html(addhtml);
  150. }
  151. });
  152. // 固定审批流-添加流程
  153. $('body').on('click', '.add-audit', function () {
  154. const num = $(this).parents('ul').children('li').length;
  155. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  156. const addhtml = makeSelectAudit(this_code, transFormToChinese(num));
  157. $(this).parents('ul').append(addhtml);
  158. $(this).parents('li').remove();
  159. });
  160. // 审批流程-选择审批人html 生成
  161. function makeSelectAudit(code, i = '终') {
  162. let divhtml = '';
  163. accountGroup.forEach((group, idx) => {
  164. let didivhtml = '';
  165. if(group) {
  166. group.groupList.forEach(item => {
  167. didivhtml += item.id !== cur_uid ? '<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
  168. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  169. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  170. ' <span class="text-muted">' + item.role + '</span>\n' +
  171. ' </dd>\n' : '';
  172. });
  173. 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' +
  174. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  175. ' </div>\n';
  176. }
  177. });
  178. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  179. ' <span class="col-auto">' + i + '审</span>\n' +
  180. ' <span class="col-7 spr-span">\n' +
  181. ' <span class="d-inline-block">\n' +
  182. ' <div class="dropdown text-right">\n' +
  183. ' <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' +
  184. ' 选择审批人\n' +
  185. ' </button>\n' +
  186. ' <div class="dropdown-menu dropdown-menu-right" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  187. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  188. ' placeholder="姓名/手机 检索" autocomplete="off"></div>\n' +
  189. ' <dl class="list-unstyled book-list">\n' + divhtml +
  190. ' </dl>\n' +
  191. ' </div>\n' +
  192. ' </div>\n' +
  193. ' </span>\n' +
  194. ' </span>\n' +
  195. ' </li>';
  196. return html;
  197. }
  198. });