payment_process.js 20 KB

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