payment_process.js 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. $(function () {
  2. autoFlashHeight();
  3. // 全选报表
  4. $('#select_all_rpt_checkbox').click(function () {
  5. $(this).prop('checked', false);
  6. $('#rpt_table input[name="rptId[]"]').each(function () {
  7. if (parseInt($(this).val()) !== -1) {
  8. $(this).prop('checked', true);
  9. }
  10. });
  11. });
  12. $('#add_rpt_btn').click(function () {
  13. const checkArray = [];
  14. $('#rpt_table input[name="rptId[]"]:checked').each(function() {
  15. checkArray.push({
  16. id: parseInt($(this).val()),
  17. name: $(this).attr('data-name'),
  18. }); //向数组中添加元素
  19. });
  20. postData('/sp/' + spid + '/payment/' + tenderId + '/process/save', { type: 'add-rpt', rpt_list: checkArray }, function (result) {
  21. const html = [];
  22. for (const data of result) {
  23. html.push(`<tr data-id="${data.id}">\n`);
  24. html.push(`<td>${data.rpt_name}</td>\n`);
  25. html.push(`<td>${data.user_name}</td>\n`);
  26. html.push(`<td>${data.uid ? _.find(accountList, { id: data.uid }).name : ''}</td>\n`);
  27. html.push('</tr>\n');
  28. }
  29. tenderRptList = result;
  30. $('#tender_rpt_table').html(html.join(''));
  31. if (result.length === 0) {
  32. $('#process_set').hide();
  33. } else {
  34. fisrtSetProcess();
  35. }
  36. $('#add-rpt').modal('hide');
  37. })
  38. });
  39. let timer = null;
  40. let oldSearchVal = null;
  41. $('#process_set').on('input propertychange', '.gr-search', function(e) {
  42. oldSearchVal = e.target.value;
  43. timer && clearTimeout(timer);
  44. timer = setTimeout(() => {
  45. const newVal = $(this).val();
  46. const code = $(this).attr('data-trid');
  47. let html = '';
  48. if (newVal && newVal === oldSearchVal) {
  49. accountList.filter(item => item && (!cur_uid || item.id !== cur_uid) && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  50. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  51. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  52. class="ml-auto">${item.mobile || ''}</span></p>
  53. <span class="text-muted">${item.role || ''}</span>
  54. </dd>`
  55. });
  56. $(this).parents('.dropdown-menu').children('.book-list').empty();
  57. $(this).parents('.dropdown-menu').children('.book-list').append(html);
  58. // $('#' + code + '_dropdownMenu .book-list').empty();
  59. // $('#' + code + '_dropdownMenu .book-list').append(html);
  60. } else {
  61. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  62. accountGroup.forEach((group, idx) => {
  63. if (!group) return;
  64. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  65. </a> ${group.groupName}</dt>
  66. <div class="dd-content" data-toggleid="${idx}">`;
  67. group.groupList.forEach(item => {
  68. if (!cur_uid || item.id !== cur_uid) {
  69. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  70. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  71. class="ml-auto">${item.mobile || ''}</span></p>
  72. <span class="text-muted">${item.role || ''}</span>
  73. </dd>`;
  74. }
  75. });
  76. html += '</div>';
  77. });
  78. // $('#' + code + '_dropdownMenu .book-list').empty();
  79. // $('#' + code + '_dropdownMenu .book-list').append(html);
  80. $(this).parents('.dropdown-menu').children('.book-list').empty();
  81. $(this).parents('.dropdown-menu').children('.book-list').append(html);
  82. }
  83. }
  84. }, 400);
  85. });
  86. function setLcShowHtml(this_status, this_tr_id, data) {
  87. if (this_status === sp_status.sqspr) {
  88. $('#process_set').find('.lc-show').html('');
  89. } else if (this_status === sp_status.gdspl) {
  90. let addhtml = '<ul class="list-unstyled">\n';
  91. if (data.length !== 0) {
  92. for(const [i, audit] of data.entries()) {
  93. addhtml += makeAudit(audit, transFormToChinese(i+1));
  94. }
  95. addhtml += '<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>';
  96. } else {
  97. addhtml += makeSelectAudit(this_tr_id, '一');
  98. }
  99. addhtml += '</ul>\n';
  100. $('#process_set').find('.lc-show').html(addhtml);
  101. } else if (this_status === sp_status.gdzs) {
  102. let addhtml = '<ul class="list-unstyled">\n' +
  103. ' <li class="d-flex justify-content-start mb-3">\n' +
  104. ' <span class="col-auto">授权审批人</span>\n' +
  105. ' <span class="col-7">\n' +
  106. ' <span class="d-inline-block"></span>\n' +
  107. ' </span>\n' +
  108. ' </li>\n';
  109. addhtml += data ? makeAudit(data) : makeSelectAudit(this_tr_id);
  110. addhtml += '</ul>\n';
  111. $('#process_set').find('.lc-show').html(addhtml);
  112. }
  113. }
  114. function fisrtSetProcess() {
  115. $('#tender_rpt_table tr').eq(0).addClass('table-warning');
  116. const tr_id = parseInt($('#tender_rpt_table tr').eq(0).attr('data-id'));
  117. $('#process_set').show();
  118. makeProcess(tr_id);
  119. }
  120. // 初始化选中table
  121. if ($('#tender_rpt_table tr').length > 0) {
  122. fisrtSetProcess();
  123. }
  124. // 选中切换table
  125. $('body').on('click', '#tender_rpt_table tr', function () {
  126. if (!$(this).hasClass('table-warning')) {
  127. $('#tender_rpt_table tr').removeClass('table-warning');
  128. $(this).addClass('table-warning');
  129. const tr_id = parseInt($(this).attr('data-id'));
  130. makeProcess(tr_id);
  131. }
  132. });
  133. // 初始化审批流程
  134. function makeProcess(tr_id) {
  135. const trInfo = _.find(tenderRptList, { id: tr_id });
  136. $('#process_set').find('.card-title').text(trInfo.rpt_name);
  137. cur_uid = trInfo.uid;
  138. let html = '<div class="mr-2">上报人<b class="text-danger">*</b></div>';
  139. let divhtml = '';
  140. accountGroup.forEach((group, idx) => {
  141. let didivhtml = '';
  142. if(group) {
  143. group.groupList.forEach(item => {
  144. didivhtml += item.id !== cur_uid ? '<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
  145. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  146. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  147. ' <span class="text-muted">' + item.role + '</span>\n' +
  148. ' </dd>\n' : '';
  149. });
  150. 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' +
  151. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  152. ' </div>\n';
  153. }
  154. });
  155. if (trInfo.uid) {
  156. const userInfo = _.find(accountList, { id: trInfo.uid });
  157. html += '<div class="mr-2">'+ userInfo.name +'</div>\n' +
  158. '<div><span class="d-inline-block">\n' +
  159. ' <div class="dropdown text-right">\n' +
  160. ' <button class="btn btn-sm btn-primary dropdown-toggle" type="button" id="' + tr_id + '_dropdownMenuButton1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  161. ' 替换\n' +
  162. ' </button>\n' +
  163. ' <div class="dropdown-menu dropdown-menu-right" id="' + tr_id + '_dropdownMenu1" aria-labelledby="' + tr_id + '_dropdownMenuButton1" style="width:220px">\n' +
  164. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  165. ' placeholder="姓名/手机 检索" autocomplete="off" data-trid="' + tr_id + '"></div>\n' +
  166. ' <dl class="list-unstyled book-list">\n' + divhtml +
  167. ' </dl>\n' +
  168. ' </div>\n' +
  169. ' </div>\n' +
  170. ' </span>\n' +
  171. '</div>';;
  172. } else {
  173. html +='<div><span class="d-inline-block">\n' +
  174. ' <div class="dropdown text-right">\n' +
  175. ' <button class="btn btn-outline-primary btn-sm dropdown-toggle" type="button" id="' + tr_id + '_dropdownMenuButton2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  176. ' 选择上报人\n' +
  177. ' </button>\n' +
  178. ' <div class="dropdown-menu dropdown-menu-right" id="' + tr_id + '_dropdownMenu2" aria-labelledby="' + tr_id + '_dropdownMenuButton2" style="width:220px">\n' +
  179. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  180. ' placeholder="姓名/手机 检索" autocomplete="off" data-trid="' + tr_id + '"></div>\n' +
  181. ' <dl class="list-unstyled book-list">\n' + divhtml +
  182. ' </dl>\n' +
  183. ' </div>\n' +
  184. ' </div>\n' +
  185. ' </span>\n' +
  186. '</div>';
  187. }
  188. $('#rpt_user').html(html);
  189. $('input[name="tender_process"][value="'+ trInfo.sp_status +'"]', '#process_set').prop('checked', true);
  190. const spt = sp_status_list[trInfo.sp_status];
  191. $('#process_set').find('.alert-warning').text(spt.name + ':' + spt.msg);
  192. const prop = {
  193. type: 'get-audits',
  194. tr_id: trInfo.id,
  195. status: trInfo.sp_status,
  196. };
  197. postData('/sp/' + spid + '/payment/' + tenderId + '/process/save', prop, function (data) {
  198. setLcShowHtml(trInfo.sp_status, trInfo.id, data);
  199. });
  200. }
  201. // 添加审批流程按钮逻辑
  202. $('body').on('click', '.book-list dt', function () {
  203. const idx = $(this).find('.acc-btn').attr('data-groupid');
  204. const type = $(this).find('.acc-btn').attr('data-type');
  205. if (type === 'hide') {
  206. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  207. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  208. $(this).find('.acc-btn').attr('data-type', 'show');
  209. })
  210. } else {
  211. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  212. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  213. $(this).find('.acc-btn').attr('data-type', 'hide');
  214. })
  215. }
  216. return false;
  217. });
  218. // 更改审批流程状态
  219. $('#process_set').on('change', `.form-check input`, function () {
  220. // 获取所有审批的checked值并更新
  221. const this_status = parseInt($(this).val());
  222. const this_tr_id = parseInt($('#tender_rpt_table').find('.table-warning').attr('data-id'));
  223. const spt = sp_status_list[this_status];
  224. $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
  225. // 拼接post json
  226. const prop = {
  227. type: 'change-status',
  228. tr_id: this_tr_id,
  229. status: this_status
  230. };
  231. postData('/sp/' + spid + '/payment/' + tenderId + '/process/save', prop, function (data) {
  232. const trInfo = _.find(tenderRptList, { id: this_tr_id });
  233. trInfo.sp_status = this_status;
  234. setLcShowHtml(this_status, this_tr_id, data);
  235. });
  236. });
  237. // 选中审批流里的审批人
  238. $('body').on('click', '#process_set .lc-show dl dd', function () {
  239. const id = parseInt($(this).data('id'));
  240. if (!id) return;
  241. let this_tr_id = parseInt($('#tender_rpt_table').find('.table-warning').attr('data-id'));
  242. if (!this_tr_id) this_tr_id = $(this).parents('.dropdown').attr('data-trid');
  243. const user = _.find(accountList, function (item) {
  244. return item.id === id;
  245. });
  246. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  247. if (this_status === sp_status.gdspl) {
  248. // 判断是否已存在审批人
  249. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  250. for (let i = 0; i < aid_num; i++) {
  251. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  252. if (aid === id) {
  253. toastr.warning('该审核人已存在,请勿重复添加');
  254. return;
  255. }
  256. }
  257. }
  258. const prop = {
  259. status: this_status,
  260. tr_id: this_tr_id,
  261. audit_id: id,
  262. type: 'add-audit',
  263. };
  264. const _self = $(this);
  265. postData('/sp/' + spid + '/payment/' + tenderId + '/process/save', prop, function (data) {
  266. if (this_status === sp_status.gdspl) {
  267. _self.parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
  268. }
  269. _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  270. '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <span class="dropdown">\n' +
  271. ' <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' +
  272. ' <div class="dropdown-menu">\n' +
  273. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  274. ' <div class="dropdown-divider"></div>\n' +
  275. ' <div class="px-2 py-1 text-center">\n' +
  276. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + user.id + '">移除</button>\n' +
  277. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  278. ' </div>\n' +
  279. ' </div>\n' +
  280. ' </span> ' +
  281. ' </span></span></span>\n');
  282. // <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>');
  283. });
  284. });
  285. // 选中上报人
  286. $('body').on('click', '#rpt_user dl dd', function () {
  287. const id = parseInt($(this).data('id'));
  288. if (!id) return;
  289. console.log(id);
  290. let this_tr_id = parseInt($('#tender_rpt_table').find('.table-warning').attr('data-id'));
  291. if (!this_tr_id) this_tr_id = $(this).parents('.dropdown').attr('data-trid');
  292. const user = _.find(accountList, function (item) {
  293. return item.id === id;
  294. });
  295. if (!user) toastr.error('用户列表不存在此人');
  296. const prop = {
  297. tr_id: this_tr_id,
  298. uid: id,
  299. type: 'update-report',
  300. };
  301. postData('/sp/' + spid + '/payment/' + tenderId + '/process/save', prop, function (result) {
  302. tenderRptList = result.list;
  303. if (result.updateRows) {
  304. toastr.warning('上报人不能同时作为审批人,审批流已移除 ' + user.name);
  305. }
  306. $('#tender_rpt_table tr[data-id="'+ this_tr_id +'"]').children('td').eq(2).html(user.name);
  307. makeProcess(this_tr_id);
  308. });
  309. //
  310. // const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  311. // if (this_status === sp_status.gdspl) {
  312. // // 判断是否已存在审批人
  313. // const aid_num = $(this).parents('ul').find('.remove-audit').length;
  314. // for (let i = 0; i < aid_num; i++) {
  315. // const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  316. // if (aid === id) {
  317. // toastr.warning('该审核人已存在,请勿重复添加');
  318. // return;
  319. // }
  320. // }
  321. //
  322. // }
  323. // const prop = {
  324. // status: this_status,
  325. // tr_id: this_tr_id,
  326. // audit_id: id,
  327. // type: 'add-audit',
  328. // };
  329. // const _self = $(this);
  330. // postData('/sp/' + spid + '/payment/' + tenderId + '/process/save', prop, function (data) {
  331. // if (this_status === sp_status.gdspl) {
  332. // _self.parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
  333. // }
  334. // _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  335. // '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <span class="dropdown">\n' +
  336. // ' <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' +
  337. // ' <div class="dropdown-menu">\n' +
  338. // ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  339. // ' <div class="dropdown-divider"></div>\n' +
  340. // ' <div class="px-2 py-1 text-center">\n' +
  341. // ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + user.id + '">移除</button>\n' +
  342. // ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  343. // ' </div>\n' +
  344. // ' </div>\n' +
  345. // ' </span> ' +
  346. // ' </span></span></span>\n');
  347. // // <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>');
  348. // });
  349. });
  350. // 移除审批人
  351. $('body').on('click', '#process_set .remove-audit', function () {
  352. const id = parseInt($(this).data('id'));
  353. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  354. const this_tr_id = parseInt($('#tender_rpt_table').find('.table-warning').attr('data-id'));
  355. const prop = {
  356. status: this_status,
  357. tr_id: this_tr_id,
  358. audit_id: id,
  359. type: 'del-audit',
  360. };
  361. const _self = $(this);
  362. postData('/sp/' + spid + '/payment/' + tenderId + '/process/save', prop, function (data) {
  363. if (this_status === sp_status.gdspl) {
  364. const _selflc = _self.parents('.lc-show');
  365. _self.parents('li').remove();
  366. const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
  367. if (aid_num === 0) {
  368. let addhtml = '<ul class="list-unstyled">\n';
  369. addhtml += makeSelectAudit(this_tr_id, '一');
  370. addhtml += '</ul>\n';
  371. _selflc.html(addhtml);
  372. } else {
  373. for (let i = 0; i < aid_num; i++) {
  374. _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  375. }
  376. }
  377. } else if (this_status === sp_status.gdzs) {
  378. let addhtml = '<ul class="list-unstyled">\n' +
  379. ' <li class="d-flex justify-content-start mb-3">\n' +
  380. ' <span class="col-auto">授权审批人</span>\n' +
  381. ' <span class="col-7">\n' +
  382. ' <span class="d-inline-block"></span>\n' +
  383. ' </span>\n' +
  384. ' </li>\n';
  385. addhtml += makeSelectAudit(this_tr_id);
  386. addhtml += '</ul>\n';
  387. _self.parents('.lc-show').html(addhtml);
  388. }
  389. })
  390. });
  391. // 固定审批流-添加流程
  392. $('body').on('click', '#process_set .add-audit', function () {
  393. const num = $(this).parents('ul').children('li').length;
  394. const this_tr_id = parseInt($('#tender_rpt_table').find('.table-warning').attr('data-id'));
  395. const addhtml = makeSelectAudit(this_tr_id, transFormToChinese(num));
  396. $(this).parents('ul').append(addhtml);
  397. $(this).parents('li').remove();
  398. });
  399. // 审批流程-审批人html 生成
  400. function makeAudit(audit, i = '终') {
  401. return '<li class="d-flex justify-content-start mb-3">\n' +
  402. ' <span class="col-auto">'+ i +'审</span>\n' +
  403. ' <span class="col-7 spr-span">\n' +
  404. ' <span class="d-inline-block"></span>\n' +
  405. ' <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  406. ' <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' +
  407. ' <div class="dropdown-menu">\n' +
  408. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  409. ' <div class="dropdown-divider"></div>\n' +
  410. ' <div class="px-2 py-1 text-center">\n' +
  411. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  412. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  413. ' </div>\n' +
  414. ' </div>\n' +
  415. ' </span> ' +
  416. // '<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' +
  417. ' </span></span></span>\n' +
  418. ' </li>';
  419. }
  420. // 审批流程-选择审批人html 生成
  421. function makeSelectAudit(tr_id, i = '终') {
  422. let divhtml = '';
  423. accountGroup.forEach((group, idx) => {
  424. let didivhtml = '';
  425. if(group) {
  426. group.groupList.forEach(item => {
  427. didivhtml += item.id !== cur_uid ? '<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
  428. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  429. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  430. ' <span class="text-muted">' + item.role + '</span>\n' +
  431. ' </dd>\n' : '';
  432. });
  433. 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' +
  434. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  435. ' </div>\n';
  436. }
  437. });
  438. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  439. ' <span class="col-auto">' + i + '审</span>\n' +
  440. ' <span class="col-7 spr-span">\n' +
  441. ' <span class="d-inline-block">\n' +
  442. ' <div class="dropdown text-right" >\n' +
  443. ' <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' +
  444. ' 选择审批人\n' +
  445. ' </button>\n' +
  446. ' <div class="dropdown-menu dropdown-menu-right" id="' + tr_id + '_dropdownMenu" aria-labelledby="' + tr_id + '_dropdownMenuButton" style="width:220px">\n' +
  447. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  448. ' placeholder="姓名/手机 检索" autocomplete="off" data-trid="' + tr_id + '"></div>\n' +
  449. ' <dl class="list-unstyled book-list">\n' + divhtml +
  450. ' </dl>\n' +
  451. ' </div>\n' +
  452. ' </div>\n' +
  453. ' </span>\n' +
  454. ' </span>\n' +
  455. ' </li>';
  456. return html;
  457. };
  458. $('#add-rpt').on('show.bs.modal', function () {
  459. $('#rpt_table').find('input:checked:not(:disabled)').prop('checked', false);
  460. $('#rpt_table').find('input:not(:disabled)').each(function () {
  461. if (_.findIndex(tenderRptList, { rpt_id: parseInt($(this).val()) }) !== -1) {
  462. $(this).prop('checked', true);
  463. }
  464. });
  465. });
  466. $('#rpt_table input').on('click', function () {
  467. if ($(this).is(':checked') && parseInt($(this).val()) === -1) {
  468. $(this).prop('checked', false);
  469. const index = $("#rpt_table input").index(this);
  470. // 循环选中当前子项值
  471. checkedRptProjectList(rptProjectList[index].items);
  472. }
  473. });
  474. function checkedRptProjectList(items) {
  475. if (items && items.length > 0) {
  476. for (const item of items) {
  477. if (item.ID !== -1 && item.items === null) {
  478. console.log(item);
  479. $('#rpt_table input').eq(item.index).prop('checked', true);
  480. } else {
  481. checkedRptProjectList(item.items);
  482. }
  483. }
  484. }
  485. };
  486. // 安全生产费 流程设置相关
  487. class ProgressMaker {
  488. constructor (setting) {
  489. const self = this;
  490. this.domId = setting.domId;
  491. this.obj = $(setting.domId);
  492. if (setting.rptInfo) this.loadRptInfo(setting.rptInfo);
  493. // 选中上报人
  494. $(setting.domId).on('click', '[name=user] dl dd', function () {
  495. const uid = parseInt($(this).data('id'));
  496. if (!uid) return;
  497. let tr_id = self.rptInfo.id;
  498. const user = _.find(accountList, function (item) { return item.id === uid; });
  499. if (!user) {
  500. toastr.error('用户列表不存在此人');
  501. return;
  502. }
  503. const data = { tr_id, uid, type: 'update-report' };
  504. postData('process/save', data, function (result) {
  505. for (const prop in result.updateData) {
  506. self.rptInfo[prop] = result.updateData[prop];
  507. }
  508. self.refreshUserHtml();
  509. if (result.updateRows) {
  510. toastr.warning('上报人不能同时作为审批人,审批流已移除 ' + user.name);
  511. self.loadAuditList();
  512. }
  513. });
  514. });
  515. // 更改审批流程状态
  516. $(setting.domId).on('change', '[name=detail_process]', function () {
  517. // 获取所有审批的checked值并更新
  518. const status = parseInt($(this).val());
  519. let tr_id = self.rptInfo.id;
  520. const spt = sp_status_list[status];
  521. $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
  522. // 拼接post json
  523. const prop = { type: 'change-status', tr_id, status };
  524. postData('/sp/' + spid + '/payment/' + tenderId + '/process/save', prop, function (data) {
  525. self.rptInfo.sp_status = status;
  526. self.rptInfo.auditData = data;
  527. self.setLcShowHtml();
  528. });
  529. });
  530. // 选中审批流里的审批人
  531. $(setting.domId).on('click', '.lc-show dl dd', function () {
  532. const tr_id = self.rptInfo.id;
  533. const id = parseInt($(this).data('id'));
  534. if (!id) return;
  535. const user = _.find(accountList, function (item) {
  536. return item.id === id;
  537. });
  538. const status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  539. if (status === sp_status.gdspl) {
  540. // 判断是否已存在审批人
  541. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  542. for (let i = 0; i < aid_num; i++) {
  543. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  544. if (aid === id) {
  545. toastr.warning('该审核人已存在,请勿重复添加');
  546. return;
  547. }
  548. }
  549. }
  550. const prop = { status, tr_id, audit_id: id, type: 'add-audit' };
  551. const _self = $(this);
  552. postData('/sp/' + spid + '/payment/' + tenderId + '/process/save', prop, function (data) {
  553. if (status === sp_status.gdspl) {
  554. _self.parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
  555. }
  556. _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  557. '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <span class="dropdown">\n' +
  558. ' <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' +
  559. ' <div class="dropdown-menu">\n' +
  560. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  561. ' <div class="dropdown-divider"></div>\n' +
  562. ' <div class="px-2 py-1 text-center">\n' +
  563. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + user.id + '">移除</button>\n' +
  564. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  565. ' </div>\n' +
  566. ' </div>\n' +
  567. ' </span> ' +
  568. ' </span></span></span>\n');
  569. });
  570. });
  571. // 移除审批人
  572. $(setting.domId).on('click', '.remove-audit', function () {
  573. const id = parseInt($(this).data('id'));
  574. const status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  575. const tr_id = self.rptInfo.id;
  576. const prop = { status, tr_id, audit_id: id, type: 'del-audit' };
  577. const _self = $(this);
  578. postData('process/save', prop, function (data) {
  579. if (status === sp_status.gdspl) {
  580. const _selflc = _self.parents('.lc-show');
  581. _self.parents('li').remove();
  582. const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
  583. if (aid_num === 0) {
  584. let addhtml = '<ul class="list-unstyled">\n';
  585. addhtml += makeSelectAudit(tr_id, '一');
  586. addhtml += '</ul>\n';
  587. _selflc.html(addhtml);
  588. } else {
  589. for (let i = 0; i < aid_num; i++) {
  590. _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  591. }
  592. }
  593. } else if (status === sp_status.gdzs) {
  594. let addhtml = '<ul class="list-unstyled">\n' +
  595. ' <li class="d-flex justify-content-start mb-3">\n' +
  596. ' <span class="col-auto">授权审批人</span>\n' +
  597. ' <span class="col-7">\n' +
  598. ' <span class="d-inline-block"></span>\n' +
  599. ' </span>\n' +
  600. ' </li>\n';
  601. addhtml += self.getAuditSelectHtml();
  602. addhtml += '</ul>\n';
  603. _self.parents('.lc-show').html(addhtml);
  604. }
  605. })
  606. });
  607. // 固定审批流-添加流程
  608. $(setting.domId).on('click', '.add-audit', function () {
  609. const num = $(this).parents('ul').children('li').length;
  610. const addhtml = self.getAuditSelectHtml(transFormToChinese(num));
  611. $(this).parents('ul').append(addhtml);
  612. $(this).parents('li').remove();
  613. });
  614. $(setting.domId).on('input propertychange', '.gr-search', function(e) {
  615. oldSearchVal = e.target.value;
  616. timer && clearTimeout(timer);
  617. timer = setTimeout(() => {
  618. const newVal = $(this).val();
  619. const code = $(this).attr('data-trid');
  620. let html = '';
  621. if (newVal && newVal === oldSearchVal) {
  622. accountList
  623. .filter(item => item && (!self.rptInfo.uid || item.id !== self.rptInfo.uid) && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1)))
  624. .forEach(item => {
  625. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  626. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  627. class="ml-auto">${item.mobile || ''}</span></p>
  628. <span class="text-muted">${item.role || ''}</span>
  629. </dd>`
  630. });
  631. } else {
  632. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  633. accountGroup.forEach((group, idx) => {
  634. if (!group) return;
  635. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  636. </a> ${group.groupName}</dt>
  637. <div class="dd-content" data-toggleid="${idx}">`;
  638. group.groupList.forEach(item => {
  639. if (!self.rptInfo.uid || item.id !== self.rptInfo.uid) {
  640. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  641. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  642. class="ml-auto">${item.mobile || ''}</span></p>
  643. <span class="text-muted">${item.role || ''}</span>
  644. </dd>`;
  645. }
  646. });
  647. html += '</div>';
  648. });
  649. }
  650. }
  651. $(this).parents('.dropdown-menu').children('.book-list').empty();
  652. $(this).parents('.dropdown-menu').children('.book-list').append(html);
  653. }, 400);
  654. });
  655. }
  656. getAccountHtml(uid) {
  657. const html = [];
  658. accountGroup.forEach((group, idx) => {
  659. if (!group) return;
  660. const groupHtml = [];
  661. group.groupList.forEach(item => {
  662. if (item.id === uid) return;
  663. groupHtml.push('<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
  664. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  665. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  666. ' <span class="text-muted">' + item.role + '</span>\n' +
  667. ' </dd>\n');
  668. });
  669. html.push(`<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>`,
  670. `<div class="dd-content" data-toggleid="${idx}">${groupHtml.join('')}</div>`);
  671. });
  672. return html.join('');
  673. }
  674. getSelectHtml(name) {
  675. const tr_id = this.rptInfo.id;
  676. return '<span class="d-inline-block">\n' +
  677. ' <div class="dropdown text-right">\n' +
  678. ' <button class="btn btn-outline-primary btn-sm dropdown-toggle" type="button" id="' + tr_id + '_dropdownMenuButton2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  679. ` ${name}\n` +
  680. ' </button>\n' +
  681. ' <div class="dropdown-menu dropdown-menu-left" id="' + tr_id + '_dropdownMenu2" aria-labelledby="' + tr_id + '_dropdownMenuButton2" style="width:220px">\n' +
  682. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  683. ' placeholder="姓名/手机 检索" autocomplete="off" data-trid="' + tr_id + '"></div>\n' +
  684. ' <dl class="list-unstyled book-list">\n' + this.getAccountHtml(this.rptInfo.uid) +
  685. ' </dl>\n' +
  686. ' </div>\n' +
  687. ' </div>\n' +
  688. ' </span>\n';
  689. }
  690. getAuditSelectHtml(i = '终') {
  691. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  692. ' <span class="col-auto">' + i + '审</span>\n' +
  693. ' <span class="col-7 spr-span">\n' + this.getSelectHtml('选择审批人') +
  694. ' </span>\n' +
  695. ' </li>';
  696. return html;
  697. }
  698. refreshUserHtml() {
  699. const html = ['<div class="mr-2">上报人<b class="text-danger">*</b></div>'];
  700. if (this.rptInfo.uid) {
  701. const userInfo = _.find(accountList, { id: this.rptInfo.uid });
  702. if (userInfo) {
  703. html.push(`<div class="mr-2">${userInfo.name}</div>`, `<div>${this.getSelectHtml('替换')}</div>`);
  704. } else {
  705. html.push(`<div class="mr-2">上报人已失效</div>`, `<div>${this.getSelectHtml('替换')}</div>`);
  706. }
  707. } else {
  708. html.push(`<div>${this.getSelectHtml('选择上报人')}</div>`);
  709. }
  710. $('[name=user]', this.domId).html(html.join(''));
  711. }
  712. setLcShowHtml() {
  713. if (this.rptInfo.sp_status === sp_status.sqspr) {
  714. $('.lc-show', this.domId).html('');
  715. } else if (this.rptInfo.sp_status === sp_status.gdspl) {
  716. let addhtml = '<ul class="list-unstyled">\n';
  717. if (this.rptInfo.auditData.length !== 0) {
  718. for(const [i, audit] of this.rptInfo.auditData.entries()) {
  719. addhtml += makeAudit(audit, transFormToChinese(i+1));
  720. }
  721. addhtml += '<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>';
  722. } else {
  723. addhtml += this.getAuditSelectHtml('一');
  724. }
  725. addhtml += '</ul>\n';
  726. $('.lc-show', this.domId).html(addhtml);
  727. } else if (this.rptInfo.sp_status === sp_status.gdzs) {
  728. let addhtml = '<ul class="list-unstyled">\n' +
  729. ' <li class="d-flex justify-content-start mb-3">\n' +
  730. ' <span class="col-auto">授权审批人</span>\n' +
  731. ' <span class="col-7">\n' +
  732. ' <span class="d-inline-block"></span>\n' +
  733. ' </span>\n' +
  734. ' </li>\n';
  735. addhtml += this.rptInfo.auditData ? makeAudit(this.rptInfo.auditData) : this.getAuditSelectHtml();
  736. addhtml += '</ul>\n';
  737. $('.lc-show', this.domId).html(addhtml);
  738. }
  739. }
  740. async loadAuditList() {
  741. const prop = {
  742. type: 'get-audits',
  743. tr_id: this.rptInfo.id,
  744. status: this.rptInfo.sp_status,
  745. };
  746. this.rptInfo.auditData = await postDataAsync('process/save', prop);
  747. this.setLcShowHtml();
  748. }
  749. initProgress() {
  750. this.obj.attr('data-trid', this.rptInfo.id);
  751. $('.card-title', this.domId).find('.card-title').text(this.rptInfo.rpt_name);
  752. this.refreshUserHtml();
  753. $('input[name="detail_process"][value="'+ this.rptInfo.sp_status +'"]', this.obj).prop('checked', true).attr('data-trid', this.rptInfo.id);
  754. const spt = sp_status_list[this.rptInfo.sp_status];
  755. $('.alert-warning', this.domId).text(spt.name + ':' + spt.msg);
  756. this.loadAuditList();
  757. }
  758. loadRptInfo(rptInfo) {
  759. this.rptInfo = rptInfo;
  760. this.initProgress();
  761. }
  762. }
  763. const safeProgress = new ProgressMaker({ domId: '#safe', rptInfo: safeRpt });
  764. });