payment_process.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. $(function () {
  2. autoFlashHeight();
  3. // 全选报表
  4. $('#select_all_rpt_checkbox').click(function () {
  5. $('#rpt_table input[name="rptId[]"]').prop('checked', true);
  6. $(this).prop('checked', false);
  7. });
  8. $('#add_rpt_btn').click(function () {
  9. const checkArray = [];
  10. $('#rpt_table input[name="rptId[]"]:checked').each(function() {
  11. checkArray.push({
  12. id: parseInt($(this).val()),
  13. name: $(this).attr('data-name'),
  14. }); //向数组中添加元素
  15. });
  16. postData('/payment/' + tenderId + '/process/save', { type: 'add-rpt', rpt_list: checkArray }, function (result) {
  17. const html = [];
  18. for (const data of result) {
  19. html.push(`<tr data-id="${data.id}">\n`);
  20. html.push(`<td>${data.rpt_name}</td>\n`);
  21. html.push(`<td>${data.user_name}</td>\n`);
  22. html.push('</tr>\n');
  23. }
  24. $('#tender_rpt_table').html(html.join(''));
  25. $('#add-rpt').modal('hide');
  26. tenderRptList = result;
  27. })
  28. });
  29. let timer = null;
  30. let oldSearchVal = null;
  31. $('body').on('input propertychange', '.gr-search', function(e) {
  32. oldSearchVal = e.target.value;
  33. timer && clearTimeout(timer);
  34. timer = setTimeout(() => {
  35. const newVal = $(this).val();
  36. const code = $(this).attr('data-trid');
  37. let html = '';
  38. if (newVal && newVal === oldSearchVal) {
  39. accountList.filter(item => item && item.id !== cur_uid && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  40. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  41. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  42. class="ml-auto">${item.mobile || ''}</span></p>
  43. <span class="text-muted">${item.role || ''}</span>
  44. </dd>`
  45. });
  46. $('#' + code + '_dropdownMenu .book-list').empty();
  47. $('#' + code + '_dropdownMenu .book-list').append(html);
  48. } else {
  49. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  50. accountGroup.forEach((group, idx) => {
  51. if (!group) return;
  52. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  53. </a> ${group.groupName}</dt>
  54. <div class="dd-content" data-toggleid="${idx}">`;
  55. group.groupList.forEach(item => {
  56. if (item.id !== cur_uid) {
  57. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  58. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  59. class="ml-auto">${item.mobile || ''}</span></p>
  60. <span class="text-muted">${item.role || ''}</span>
  61. </dd>`;
  62. }
  63. });
  64. html += '</div>';
  65. });
  66. $('#' + code + '_dropdownMenu .book-list').empty();
  67. $('#' + code + '_dropdownMenu .book-list').append(html);
  68. }
  69. }
  70. }, 400);
  71. });
  72. function setLcShowHtml(this_status, this_tr_id, data) {
  73. if (this_status === sp_status.sqspr) {
  74. $('#process_set').find('.lc-show').html('');
  75. } else if (this_status === sp_status.gdspl) {
  76. let addhtml = '<ul class="list-unstyled">\n';
  77. if (data.length !== 0) {
  78. for(const [i, audit] of data.entries()) {
  79. addhtml += makeAudit(audit, transFormToChinese(i+1));
  80. }
  81. addhtml += '<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>';
  82. } else {
  83. addhtml += makeSelectAudit(this_tr_id, '一');
  84. }
  85. addhtml += '</ul>\n';
  86. $('#process_set').find('.lc-show').html(addhtml);
  87. } else if (this_status === sp_status.gdzs) {
  88. let addhtml = '<ul class="list-unstyled">\n' +
  89. ' <li class="d-flex justify-content-start mb-3">\n' +
  90. ' <span class="col-auto">授权审批人</span>\n' +
  91. ' <span class="col-7">\n' +
  92. ' <span class="d-inline-block"></span>\n' +
  93. ' </span>\n' +
  94. ' </li>\n';
  95. addhtml += data ? makeAudit(data) : makeSelectAudit(this_tr_id);
  96. addhtml += '</ul>\n';
  97. $('#process_set').find('.lc-show').html(addhtml);
  98. }
  99. }
  100. // 初始化选中table
  101. if ($('#tender_rpt_table tr').length > 0) {
  102. $('#tender_rpt_table tr').eq(0).addClass('table-warning');
  103. const tr_id = parseInt($('#tender_rpt_table tr').eq(0).attr('data-id'));
  104. $('#process_set').show();
  105. makeProcess(tr_id);
  106. }
  107. // 选中切换table
  108. $('#tender_rpt_table tr').click(function () {
  109. if (!$(this).hasClass('table-warning')) {
  110. $('#tender_rpt_table tr').removeClass('table-warning');
  111. $(this).addClass('table-warning');
  112. const tr_id = parseInt($(this).attr('data-id'));
  113. makeProcess(tr_id);
  114. }
  115. });
  116. // 初始化审批流程
  117. function makeProcess(tr_id) {
  118. const trInfo = _.find(tenderRptList, { id: tr_id });
  119. $('#process_set').find('.card-title').text(trInfo.rpt_name);
  120. $('#process_set input[name="tender_process"][value="'+ trInfo.sp_status +'"]').prop('checked', true);
  121. const spt = sp_status_list[trInfo.sp_status];
  122. $('#process_set').find('.alert-warning').text(spt.name + ':' + spt.msg);
  123. const prop = {
  124. type: 'get-audits',
  125. tr_id: trInfo.id,
  126. status: trInfo.sp_status,
  127. };
  128. postData('/payment/' + tenderId + '/process/save', prop, function (data) {
  129. setLcShowHtml(trInfo.sp_status, trInfo.id, data);
  130. });
  131. }
  132. // 添加审批流程按钮逻辑
  133. $('body').on('click', '.book-list dt', function () {
  134. const idx = $(this).find('.acc-btn').attr('data-groupid');
  135. const type = $(this).find('.acc-btn').attr('data-type');
  136. if (type === 'hide') {
  137. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  138. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  139. $(this).find('.acc-btn').attr('data-type', 'show');
  140. })
  141. } else {
  142. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  143. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  144. $(this).find('.acc-btn').attr('data-type', 'hide');
  145. })
  146. }
  147. return false;
  148. });
  149. // 更改审批流程状态
  150. $('#process_set .form-check input').on('change', function () {
  151. // 获取所有审批的checked值并更新
  152. const this_status = parseInt($(this).val());
  153. const this_tr_id = parseInt($('#tender_rpt_table').find('.table-warning').attr('data-id'));
  154. const spt = sp_status_list[this_status];
  155. $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
  156. // 拼接post json
  157. const prop = {
  158. type: 'change-status',
  159. tr_id: this_tr_id,
  160. status: this_status
  161. };
  162. postData('/payment/' + tenderId + '/process/save', prop, function (data) {
  163. setLcShowHtml(this_status, this_tr_id, data);
  164. });
  165. });
  166. // 选中审批人
  167. $('body').on('click', 'dl dd', function () {
  168. const id = parseInt($(this).data('id'));
  169. if (!id) return;
  170. let this_tr_id = parseInt($('#tender_rpt_table').find('.table-warning').attr('data-id'));
  171. if (!this_tr_id) this_tr_id = $(this).parents('.dropdown').attr('data-trid');
  172. const user = _.find(accountList, function (item) {
  173. return item.id === id;
  174. });
  175. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  176. if (this_status === sp_status.gdspl) {
  177. // 判断是否已存在审批人
  178. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  179. for (let i = 0; i < aid_num; i++) {
  180. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  181. if (aid === id) {
  182. toastr.warning('该审核人已存在,请勿重复添加');
  183. return;
  184. }
  185. }
  186. }
  187. const prop = {
  188. status: this_status,
  189. tr_id: this_tr_id,
  190. audit_id: id,
  191. type: 'add-audit',
  192. };
  193. const _self = $(this);
  194. postData('/payment/' + tenderId + '/process/save', prop, function (data) {
  195. if (this_status === sp_status.gdspl) {
  196. _self.parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
  197. }
  198. _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  199. '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <span class="dropdown">\n' +
  200. ' <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' +
  201. ' <div class="dropdown-menu">\n' +
  202. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  203. ' <div class="dropdown-divider"></div>\n' +
  204. ' <div class="px-2 py-1 text-center">\n' +
  205. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + user.id + '">移除</button>\n' +
  206. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  207. ' </div>\n' +
  208. ' </div>\n' +
  209. ' </span> ' +
  210. ' </span></span></span>\n');
  211. // <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>');
  212. });
  213. });
  214. // 移除审批人
  215. $('body').on('click', '.remove-audit', function () {
  216. const id = parseInt($(this).data('id'));
  217. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  218. const this_tr_id = parseInt($('#tender_rpt_table').find('.table-warning').attr('data-id'));
  219. const prop = {
  220. status: this_status,
  221. tr_id: this_tr_id,
  222. audit_id: id,
  223. type: 'del-audit',
  224. };
  225. const _self = $(this);
  226. postData('/payment/' + tenderId + '/process/save', prop, function (data) {
  227. if (this_status === sp_status.gdspl) {
  228. const _selflc = _self.parents('.lc-show');
  229. _self.parents('li').remove();
  230. const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
  231. if (aid_num === 0) {
  232. let addhtml = '<ul class="list-unstyled">\n';
  233. addhtml += makeSelectAudit(this_tr_id, '一');
  234. addhtml += '</ul>\n';
  235. _selflc.html(addhtml);
  236. } else {
  237. for (let i = 0; i < aid_num; i++) {
  238. _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  239. }
  240. }
  241. } else if (this_status === sp_status.gdzs) {
  242. let addhtml = '<ul class="list-unstyled">\n' +
  243. ' <li class="d-flex justify-content-start mb-3">\n' +
  244. ' <span class="col-auto">授权审批人</span>\n' +
  245. ' <span class="col-7">\n' +
  246. ' <span class="d-inline-block"></span>\n' +
  247. ' </span>\n' +
  248. ' </li>\n';
  249. addhtml += makeSelectAudit(this_tr_id);
  250. addhtml += '</ul>\n';
  251. _self.parents('.lc-show').html(addhtml);
  252. }
  253. })
  254. });
  255. // 固定审批流-添加流程
  256. $('body').on('click', '.add-audit', function () {
  257. const num = $(this).parents('ul').children('li').length;
  258. const this_tr_id = parseInt($('#tender_rpt_table').find('.table-warning').attr('data-id'));
  259. const addhtml = makeSelectAudit(this_tr_id, transFormToChinese(num));
  260. $(this).parents('ul').append(addhtml);
  261. $(this).parents('li').remove();
  262. });
  263. // 审批流程-审批人html 生成
  264. function makeAudit(audit, i = '终') {
  265. return '<li class="d-flex justify-content-start mb-3">\n' +
  266. ' <span class="col-auto">'+ i +'审</span>\n' +
  267. ' <span class="col-7 spr-span">\n' +
  268. ' <span class="d-inline-block"></span>\n' +
  269. ' <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  270. ' <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' +
  271. ' <div class="dropdown-menu">\n' +
  272. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  273. ' <div class="dropdown-divider"></div>\n' +
  274. ' <div class="px-2 py-1 text-center">\n' +
  275. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  276. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  277. ' </div>\n' +
  278. ' </div>\n' +
  279. ' </span> ' +
  280. // '<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' +
  281. ' </span></span></span>\n' +
  282. ' </li>';
  283. }
  284. // 审批流程-选择审批人html 生成
  285. function makeSelectAudit(tr_id, i = '终') {
  286. let divhtml = '';
  287. accountGroup.forEach((group, idx) => {
  288. let didivhtml = '';
  289. if(group) {
  290. group.groupList.forEach(item => {
  291. didivhtml += item.id !== cur_uid ? '<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
  292. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  293. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  294. ' <span class="text-muted">' + item.role + '</span>\n' +
  295. ' </dd>\n' : '';
  296. });
  297. 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' +
  298. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  299. ' </div>\n';
  300. }
  301. });
  302. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  303. ' <span class="col-auto">' + i + '审</span>\n' +
  304. ' <span class="col-7 spr-span">\n' +
  305. ' <span class="d-inline-block">\n' +
  306. ' <div class="dropdown text-right">\n' +
  307. ' <button class="btn btn-outline-primary btn-sm dropdown-toggle" type="button" id="' + tr_id + '_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  308. ' 选择审批人\n' +
  309. ' </button>\n' +
  310. ' <div class="dropdown-menu dropdown-menu-right" id="' + tr_id + '_dropdownMenu" aria-labelledby="' + tr_id + '_dropdownMenuButton" style="width:220px">\n' +
  311. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  312. ' placeholder="姓名/手机 检索" autocomplete="off" data-trid="' + tr_id + '"></div>\n' +
  313. ' <dl class="list-unstyled book-list">\n' + divhtml +
  314. ' </dl>\n' +
  315. ' </div>\n' +
  316. ' </div>\n' +
  317. ' </span>\n' +
  318. ' </span>\n' +
  319. ' </li>';
  320. return html;
  321. }
  322. });