sp_shenpi.js 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/10/09
  7. * @version
  8. */
  9. let auditUtils;
  10. const needYB = ['contract'];
  11. function getShenpiHtml (this_code) {
  12. const html = [];
  13. html.push('<table class="table table-hover table-bordered">');
  14. html.push('<thead>', '<tr>');
  15. html.push('<th>名称</th>');
  16. html.push('<th width="100">审批流程</th>');
  17. html.push('<th width="40">选择</th>');
  18. html.push('</tr>', '</thead>');
  19. for (const sp of sp_lc) {
  20. html.push('<tr>');
  21. html.push('<td>', sp.name, '</td>');
  22. html.push('<td>');
  23. const this_status = parseInt($('.' + sp.code + '_div').children('.lc-show').siblings('.form-group').find('input:checked').val());
  24. html.push(sp_status_list[this_status].name);
  25. if(this_status !== sp_status.sqspr) {
  26. const nameList = [];
  27. const aid_num = $('.' + sp.code + '_div').children('.lc-show').children('ul').find('.remove-audit').length;
  28. const aidList = [];
  29. for (let i = 0; i < aid_num; i++) {
  30. const aid = parseInt($('.' + sp.code + '_div').children('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
  31. aidList.push(aid);
  32. }
  33. if(aidList.length > 0) {
  34. for (const uid of aidList) {
  35. const user = _.find(accountList, { id: uid });
  36. if (user) nameList.push(user.name);
  37. }
  38. }
  39. html.push('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
  40. 'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
  41. }
  42. html.push('</td>');
  43. html.push('<td>', this_code !== sp.code ? '<input type="checkbox" data-code="'+ sp.code +'"' + (sp.groupList && sp.groupList.length > 0 ? 'disabled' : '') + '>' : '', '</td>');
  44. html.push('</tr>');
  45. }
  46. html.push('</table>');
  47. return html.join('');
  48. }
  49. $(document).ready(function () {
  50. auditUtils = {
  51. getAuditHtml: function(audit) {
  52. return '<span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  53. ' <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' +
  54. ' <div class="dropdown-menu">\n' +
  55. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  56. ' <div class="dropdown-divider"></div>\n' +
  57. ' <div class="px-2 py-1 text-center">\n' +
  58. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  59. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  60. ' </div>\n' +
  61. ' </div>\n' +
  62. ' </span> ' +
  63. ' </span></span>\n'
  64. },
  65. getAuditTypeHtml: function(code, type) {
  66. const html = [];
  67. html.push(`<span class="d-inline-block"><select class="form-control form-control-sm audit-type-key" data-type="${type}">`);
  68. for (const t of auditType.types) {
  69. if (t.valid && t.valid.indexOf(code) < 0) continue;
  70. html.push(`<option value="${t.value}" ${t.value === type ? 'selected' : ''}>${t.name}</option>`);
  71. }
  72. html.push('</select></span> ');
  73. return html.join('');
  74. },
  75. getSelectAuditHtml: function (code) {
  76. let divhtml = '';
  77. accountGroup.forEach((group, idx) => {
  78. let didivhtml = '';
  79. if(group) {
  80. group.groupList.forEach(item => {
  81. 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' +
  82. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  83. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  84. ' <span class="text-muted">' + item.role + '</span>\n' +
  85. ' </dd>\n' : '';
  86. });
  87. 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' +
  88. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  89. ' </div>\n';
  90. }
  91. });
  92. const html =
  93. ' <span class="d-inline-block">\n' +
  94. ' <div class="dropdown text-right">\n' +
  95. ' <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' +
  96. ' 选择审批人\n' +
  97. ' </button>\n' +
  98. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  99. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  100. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  101. ' <dl class="list-unstyled book-list">\n' + divhtml +
  102. ' </dl>\n' +
  103. ' </div>\n' +
  104. ' </div>\n' +
  105. ' </span>\n';
  106. return html;
  107. },
  108. // 以下i从1开始
  109. getAuditGroupInnerHtml: function(code, auditGroup, i) {
  110. const html = [];
  111. const type = auditGroup.length > 0 ? auditGroup[0].audit_type : auditType.key.common;
  112. html.push(`<span class="col-auto">${transFormToChinese(i)}审</span><span class="col-7 spr-span">`);
  113. html.push(this.getAuditTypeHtml(code, type));
  114. for (const audit of auditGroup) {
  115. html.push(this.getAuditHtml(audit));
  116. }
  117. if (type !== auditType.key.common || auditGroup.length === 0) {
  118. html.push(this.getSelectAuditHtml(code));
  119. }
  120. if (type === auditType.key.and && auditType.info[auditType.key.and].setValid.indexOf(code) >= 0 && auditGroup.length > 0) {
  121. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="and-set">会签设置</button>`);
  122. }
  123. if (type === auditType.key.or && auditType.info[auditType.key.or].setValid.indexOf(code) >= 0 && auditGroup.length > 0) {
  124. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="or-set">或签设置</button>`);
  125. }
  126. if (type === auditType.key.multi && auditGroup.length > 0) {
  127. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="multi-set">分组设置</button>`);
  128. }
  129. if (type === auditType.key.union && auditGroup.length > 0) {
  130. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="union-set">协同设置</button>`);
  131. }
  132. html.push('</span>');
  133. return html.join('');
  134. },
  135. getAuditGroupHtml: function (code, auditGroup, i) {
  136. return `<li class="d-flex justify-content-start align-items-center mb-3">${this.getAuditGroupInnerHtml(code, auditGroup, i)}</li>`;
  137. },
  138. getFinalAuditHtml: function (audit) {
  139. const html = [];
  140. html.push('<li class="d-flex justify-content-start mb-3"><span class="col-auto">终审</span><span class="col-7 spr-span">');
  141. html.push(this.getAuditHtml(audit));
  142. html.push('</span></span></li>');
  143. return html.join('');
  144. },
  145. getGroupHtml: function (flow, this_code) {
  146. let html = '';
  147. if (flow && flow.groupList && flow.groupList.length > 0) {
  148. let groupSelectHtml = '';
  149. for (const group of flow.groupList) {
  150. groupSelectHtml += `<option value="${group.id}" ${group.is_select === 1 ? 'selected' : ''}>${group.name}</option>`;
  151. }
  152. const selectGroup = flow.groupList.find(x => { return x.is_select === 1 });
  153. html += '<div class="d-flex justify-content-start align-items-center mb-3">\n' +
  154. ' <span class="col-auto">当前审批组:</span>\n' +
  155. ' <span style="width: 200px;">\n' +
  156. ' <select class="form-control form-control-sm group-list">\n' +
  157. groupSelectHtml +
  158. ' </select>\n' +
  159. ' </span>\n' +
  160. ` <span class="pl-3"><a href="javascript:void(0);" class="show-spzsave edit-spzsave" data-group="${selectGroup.id}" data-code="${this_code}"><i class="fa fa-edit"></i> 编辑审批组</a></span>\n` +
  161. ` <span class="pl-3"><a href="javascript:void(0);" class="show-spzsave" data-code="${this_code}"><i class="fa fa-plus"></i> 添加审批组</a></span>\n` +
  162. ' </div>';
  163. }
  164. return html;
  165. },
  166. getgdsplHtml(flow, this_code) {
  167. let addhtml = '';
  168. if (flow.auditGroupList.length !== 0) {
  169. for(const [i, auditGroup] of flow.auditGroupList.entries()) {
  170. addhtml += this.getAuditGroupHtml(this_code, auditGroup, i + 1);
  171. }
  172. const addGroupHtml = (this_code === 'change' || this_code === 'stage' || this_code === 'contract') && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
  173. `<span class="pl-3"><a href="javascript:void(0);" class="show-spzsave" data-code="${this_code}"><i class="fa fa-save"></i> 存为审批组</a></span>\n` : '';
  174. addhtml += '<li>\n' +
  175. ' <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>\n' + addGroupHtml +
  176. ' </li>';
  177. } else {
  178. addhtml += this.getAuditGroupHtml(this_code, [], 1);
  179. }
  180. return addhtml;
  181. },
  182. // 以下i从0开始
  183. addAudit: function (code, user, i) {
  184. const flow = sp_lc.find(x => { return x.code === code });
  185. if (!flow.auditGroupList) flow.auditGroupList = [];
  186. if (!flow.auditGroupList[i]) flow.auditGroupList[i] = [];
  187. flow.auditGroupList[i].push(user);
  188. return flow.auditGroupList[i];
  189. },
  190. removeAudit: function (code, audit_id, i) {
  191. const flow = sp_lc.find(x => { return x.code === code });
  192. if (flow.auditGroupList[i].length === 1) {
  193. flow.auditGroupList.splice(i, 1);
  194. return null;
  195. }
  196. flow.auditGroupList[i].splice(flow.auditGroupList[i].findIndex(x => { return x.audit_id === audit_id; }), 1);
  197. return flow.auditGroupList[i];
  198. },
  199. setAuditType: function (code, audit_type, i) {
  200. const flow = sp_lc.find(x => { return x.code === code });
  201. if (!flow || !flow.auditGroupList || !flow.auditGroupList[i]) return;
  202. flow.auditGroupList[i].forEach(x => { x.audit_type = audit_type});
  203. return flow.auditGroupList[i];
  204. }
  205. };
  206. let timer = null;
  207. let oldSearchVal = null;
  208. $('body').on('input propertychange', 'div[id$="_dropdownMenu"] .gr-search', function(e) {
  209. oldSearchVal = e.target.value;
  210. timer && clearTimeout(timer);
  211. timer = setTimeout(() => {
  212. const newVal = $(this).val();
  213. const code = $(this).attr('data-code');
  214. let html = '';
  215. if (newVal && newVal === oldSearchVal) {
  216. 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 => {
  217. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  218. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  219. class="ml-auto">${item.mobile || ''}</span></p>
  220. <span class="text-muted">${item.role || ''}</span>
  221. </dd>`
  222. });
  223. $('#' + code + '_dropdownMenu .book-list').empty();
  224. $('#' + code + '_dropdownMenu .book-list').append(html);
  225. } else {
  226. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  227. accountGroup.forEach((group, idx) => {
  228. if (!group) return;
  229. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  230. </a> ${group.groupName}</dt>
  231. <div class="dd-content" data-toggleid="${idx}">`;
  232. group.groupList.forEach(item => {
  233. if ((item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1))) {
  234. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  235. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  236. class="ml-auto">${item.mobile || ''}</span></p>
  237. <span class="text-muted">${item.role || ''}</span>
  238. </dd>`;
  239. }
  240. });
  241. html += '</div>';
  242. });
  243. $('#' + code + '_dropdownMenu .book-list').empty();
  244. $('#' + code + '_dropdownMenu .book-list').append(html);
  245. }
  246. }
  247. }, 400);
  248. });
  249. // 添加审批流程按钮逻辑
  250. $('body').on('click', 'div[id$="_dropdownMenu"] .book-list dt', function () {
  251. const idx = $(this).find('.acc-btn').attr('data-groupid');
  252. const type = $(this).find('.acc-btn').attr('data-type');
  253. if (type === 'hide') {
  254. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  255. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  256. $(this).find('.acc-btn').attr('data-type', 'show');
  257. })
  258. } else {
  259. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  260. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  261. $(this).find('.acc-btn').attr('data-type', 'hide');
  262. })
  263. }
  264. return false;
  265. });
  266. // 更改审批流程状态
  267. $('body').on('change', '.form-check input[type="radio"]', function () {
  268. // 获取所有审批的checked值并更新
  269. const this_status = parseInt($(this).val());
  270. const this_code = $(this).data('code');
  271. const spt = sp_status_list[this_status];
  272. $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
  273. // 拼接post json
  274. const prop = {
  275. code: this_code,
  276. status: this_status
  277. };
  278. const _self = $(this);
  279. postData('/sp/' + spid + '/shenpi/save', prop, function (data) {
  280. if (this_status === sp_status.sqspr) {
  281. _self.parents('.form-group').siblings('.lc-show').html('');
  282. } else if (this_status === sp_status.gdspl) {
  283. const flow = sp_lc.find(x => { return x.code === this_code; });
  284. flow.auditGroupList = data.auditList;
  285. flow.groupList = data.groupList;
  286. let addhtml = auditUtils.getGroupHtml(flow, this_code);
  287. addhtml += '<ul class="list-unstyled">\n';
  288. addhtml += auditUtils.getgdsplHtml(flow, this_code);
  289. addhtml += '</ul>\n';
  290. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  291. } else if (this_status === sp_status.gdzs) {
  292. let addhtml = '<ul class="list-unstyled">\n' +
  293. ' <li class="d-flex justify-content-start mb-3">\n' +
  294. ' <span class="col-auto">授权审批人</span>\n' +
  295. ' <span class="col-7">\n' +
  296. ' <span class="d-inline-block"></span>\n' +
  297. ' </span>\n' +
  298. ' </li>\n';
  299. addhtml += data.auditList ? makeAudit(data.auditList) : makeSelectAudit(this_code);
  300. addhtml += '</ul>\n';
  301. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  302. }
  303. if(this_code === 'stage') {
  304. if(this_status === sp_status.gdspl) {
  305. $('#stage_cooperation').show();
  306. } else {
  307. $('#stage_cooperation').hide();
  308. }
  309. }
  310. });
  311. });
  312. // 选中审批人
  313. $('body').on('click', 'div[id$="_dropdownMenu"] dl dd', function () {
  314. const id = parseInt($(this).data('id'));
  315. if (!id) return;
  316. let this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  317. if (!this_code) this_code = $(this).parents('.dropdown').data('code');
  318. const user = _.find(accountList, function (item) {
  319. return item.id === id;
  320. });
  321. if (this_code === 'audit-ass') {
  322. auditAss.setAuditAssist(user);
  323. } else {
  324. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  325. if (this_status === sp_status.gdspl) {
  326. // 判断是否已存在审批人
  327. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  328. for (let i = 0; i < aid_num; i++) {
  329. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  330. if (aid === id) {
  331. toastr.warning('该审核人已存在,请勿重复添加');
  332. return;
  333. }
  334. }
  335. }
  336. const prop = {
  337. status: this_status,
  338. code: sp_type[this_code],
  339. audit_id: id,
  340. type: 'add',
  341. };
  342. if (this_status === sp_status.gdspl) {
  343. prop.audit_type = parseInt($(this).parents('li').find('select[class*="audit-type-key"]')[0].value);
  344. prop.audit_order = $(this).parents('li').index() + 1;
  345. }
  346. const _self = $(this);
  347. postData('/sp/' + spid + '/shenpi/audit/save', prop, function (data) {
  348. if (this_status === sp_status.gdspl) {
  349. const auditGroup = auditUtils.addAudit(this_code, data, prop.audit_order - 1);
  350. if (_self.parents('ul').find('.add-audit').length === 0) {
  351. const flow = sp_lc.find(x => { return x.code === this_code; });
  352. const addGroupHtml = (this_code === 'change'||this_code ==='stage' || this_code === 'contract') && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
  353. `<span class="pl-3"><a href="javascript:void(0);" class="show-spzsave" data-code="${this_code}"><i class="fa fa-save"></i> 存为审批组</a></span>\n` : '';
  354. _self.parents('ul').append('<li>\n' +
  355. ' <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>\n' + addGroupHtml +
  356. ' </li>');
  357. }
  358. _self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, prop.audit_order));
  359. } else {
  360. _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  361. '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <span class="dropdown">\n' +
  362. ' <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' +
  363. ' <div class="dropdown-menu">\n' +
  364. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  365. ' <div class="dropdown-divider"></div>\n' +
  366. ' <div class="px-2 py-1 text-center">\n' +
  367. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + user.id + '">移除</button>\n' +
  368. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  369. ' </div>\n' +
  370. ' </div>\n' +
  371. ' </span> ' +
  372. ' </span></span></span>\n');
  373. }
  374. });
  375. }
  376. });
  377. // 移除审批人
  378. $('body').on('click', '.remove-audit', function () {
  379. const id = parseInt($(this).data('id'));
  380. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  381. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  382. const prop = {
  383. status: this_status,
  384. code: sp_type[this_code],
  385. audit_id: id,
  386. type: 'del',
  387. };
  388. const _self = $(this);
  389. postData('/sp/' + spid + '/shenpi/audit/save', prop, function (data) {
  390. if (this_status === sp_status.gdspl) {
  391. const index = _self.parents('li').index();
  392. const auditGroup = auditUtils.removeAudit(this_code, id, index);
  393. if (auditGroup) {
  394. _self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, index + 1));
  395. } else {
  396. const _selflc = _self.parents('.lc-show');
  397. _self.parents('li').remove();
  398. const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
  399. if (aid_num === 0) {
  400. _selflc.children('ul').html(auditUtils.getAuditGroupHtml(this_code, [], 1));
  401. } else {
  402. for (let i = 0; i < aid_num; i++) {
  403. _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  404. }
  405. }
  406. }
  407. } else if (this_status === sp_status.gdzs) {
  408. let addhtml = '<ul class="list-unstyled">\n' +
  409. ' <li class="d-flex justify-content-start mb-3">\n' +
  410. ' <span class="col-auto">授权审批人</span>\n' +
  411. ' <span class="col-7">\n' +
  412. ' <span class="d-inline-block"></span>\n' +
  413. ' </span>\n' +
  414. ' </li>\n';
  415. addhtml += makeSelectAudit(this_code);
  416. addhtml += '</ul>\n';
  417. _self.parents('.lc-show').html(addhtml);
  418. }
  419. })
  420. });
  421. // 固定审批流-添加流程
  422. $('body').on('click', '.add-audit', function () {
  423. const num = $(this).parents('ul').children('li').length;
  424. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  425. //const addhtml = makeSelectAudit(this_code, transFormToChinese(num));
  426. const addhtml = auditUtils.getAuditGroupHtml(this_code, [], num);
  427. $(this).parents('ul').append(addhtml);
  428. $(this).parents('li').remove();
  429. });
  430. // $('body').on('click', '.set-otherTender', function () {
  431. // const this_code = $(this).data('code');
  432. // const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  433. // const lis = $(this).siblings('.lc-show').find('li');
  434. // const auditList = [], aidList = [];
  435. //
  436. // const flow = sp_lc.find(x => { return x.code === this_code; });
  437. // lis.each((i, li) => {
  438. // const removes = $(li).find('.remove-audit');
  439. // if (removes.length === 0) return;
  440. //
  441. // const select = $(li).find('select[class*="audit-type-key"]');
  442. // const audit_type = select.length > 0 ? parseInt(select.val()) : 1;
  443. // const multiData = flow.auditGroupList.find(x => { return x[0].audit_order == i+1; });
  444. // for (const remove of removes) {
  445. // const auditData = { audit_id: parseInt(remove.getAttribute('data-id')), audit_type, audit_order: i + 1 };
  446. // const removeMultiData = multiData.find(x => { return x.audit_id === auditData.audit_id; });
  447. // auditData.audit_group = removeMultiData ? removeMultiData.audit_group : '';
  448. // auditData.audit_group_order = removeMultiData ? removeMultiData.audit_group_order : 0;
  449. // auditData.audit_group_limit = removeMultiData ? removeMultiData.audit_group_limit : 0;
  450. // auditList.push(auditData);
  451. // aidList.push(parseInt(remove.getAttribute('data-id')));
  452. // }
  453. // });
  454. // $('#shenpi-name').text($(this).data('name'));
  455. // $('#shenpi_code').val(this_code);
  456. // $('#shenpi_status').val(this_status);
  457. // $('#shenpi_auditors').val(JSON.stringify(auditList));
  458. // $('#search-audit').val('');
  459. // $('#search-result').text('0/0');
  460. // $('#up-search').attr('disabled', true);
  461. // $('#down-search').attr('disabled', true);
  462. // });
  463. // $('#save-other-tender').click(function () {
  464. // $(this).attr('disabled', true);
  465. // const num = $('#tender-list input:checked').length;
  466. // if (num < 2) {
  467. // toastr.warning('请选择需要设置审批同步的标段');
  468. // $(this).removeAttr('disabled');
  469. // return;
  470. // }
  471. // const data = {
  472. // type: 'copy2ot',
  473. // status: parseInt($('#shenpi_status').val()),
  474. // code: $('#shenpi_code').val(),
  475. // };
  476. // if(data.status !== shenpi_status.gdspl) {
  477. // data.auditList = JSON.parse($('#shenpi_auditors').val());
  478. // }
  479. // // 获取已选中的标段
  480. // const tenderList = [];
  481. // for (let i = 0; i < num; i++) {
  482. // const tid = parseInt($('#tender-list input:checked').eq(i).data('tid'));
  483. // if (tid !== cur_tenderid) {
  484. // tenderList.push(tid);
  485. // }
  486. // }
  487. // data.tidList = tenderList.join(',');
  488. // postData('/sp/' + spid + '/shenpi/audit/save', data, function () {
  489. // toastr.success('设置成功');
  490. // setTimeout(function () {
  491. // window.location.reload();
  492. // }, 1000)
  493. // })
  494. // });
  495. $('body').on('click', '.set-otherShenpi', function () {
  496. let canSetOther = true;
  497. const this_code = $(this).data('code');
  498. // if (['stage', 'change'].indexOf(this_code) !== -1) {
  499. // const select = $(this).siblings('.lc-show').find('select[class*="audit-type-key"]');
  500. // select.each((i, s) => {
  501. // if (s.value !== '1') canSetOther = false;
  502. // });
  503. // }
  504. // if (!canSetOther) {
  505. // toastr.warning('该流程含有会签或签,不可同步至其他流程');
  506. // $('#batch2').modal('hide');
  507. // return;
  508. // }
  509. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  510. const copyFlow = [];
  511. const flow = $('li.d-flex', $(this).siblings('.lc-show'));
  512. for (const f of flow) {
  513. const audit_type = $('select', f).val() || 1;
  514. const auditors = $('.remove-audit', f);
  515. if (auditors.length === 0) continue;
  516. const aid = [];
  517. for (const a of auditors) {
  518. aid.push(a.getAttribute('data-id'));
  519. }
  520. copyFlow.push(`${audit_type}:${aid.join(',')}`);
  521. }
  522. const html = getShenpiHtml(this_code);
  523. $('#shenpi-name2').text($(this).data('name'));
  524. $('#shenpi_code2').val(this_code);
  525. $('#shenpi_status2').val(this_status);
  526. $('#shenpi_auditors2').val(copyFlow.join(';'));
  527. $('#shenpi-list').html(html);
  528. setTimeout(function () { $("#shenpi-list [data-toggle='tooltip']").tooltip(); },800);
  529. $('#batch2').modal('show');
  530. });
  531. $('#save-other-shenpi').click(function () {
  532. $(this).attr('disabled', true);
  533. const num = $('#shenpi-list input:checked').length;
  534. if (num < 1) {
  535. toastr.warning('请选择需要设置审批同步的流程');
  536. $(this).removeAttr('disabled');
  537. return;
  538. }
  539. const data = {
  540. type: 'copy2os',
  541. status: parseInt($('#shenpi_status2').val()),
  542. code: $('#shenpi_code2').val(),
  543. };
  544. if(data.status !== shenpi_status.gdspl) {
  545. data.flowList = $('#shenpi_auditors2').val();
  546. }
  547. // 获取已选中的标段
  548. const shenpiList = [];
  549. for (let i = 0; i < num; i++) {
  550. const code = $('#shenpi-list input:checked').eq(i).data('code');
  551. shenpiList.push(code);
  552. }
  553. data.shenpiList = shenpiList.join(',');
  554. postData('/sp/' + spid + '/shenpi/audit/save', data, function () {
  555. toastr.success('设置成功');
  556. setTimeout(function () {
  557. window.location.reload();
  558. }, 1000)
  559. })
  560. });
  561. // 设置会签、或签
  562. $('body').on('change', 'select[class*="audit-type-key"]', function() {
  563. const removes = $(this).parents('.d-flex').find('.remove-audit');
  564. if (removes.length === 0) return;
  565. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  566. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  567. const ids = [];
  568. const liParent = $(this).parents('li');
  569. removes.each((i, r) => { ids.push(parseInt(r.getAttribute('data-id'))); });
  570. const prop = {
  571. status: this_status,
  572. code: sp_type[this_code],
  573. audit_id: ids,
  574. audit_type: parseInt(this.value),
  575. type: 'audit-type',
  576. };
  577. if (prop.audit_type === auditType.key.common && ids.length > 1) {
  578. toastr.warning('设置个人审批前请先删除多余的审批人');
  579. this.value = this.getAttribute('data-type');
  580. return;
  581. }
  582. const _self = this;
  583. postData('/sp/' + spid + '/shenpi/audit/save', prop, function () {
  584. _self.setAttribute('data-type', _self.value);
  585. const auditGroup = auditUtils.setAuditType(this_code, prop.audit_type, liParent.index());
  586. liParent.html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, liParent.index() + 1));
  587. });
  588. });
  589. class AuditUnion {
  590. constructor() {
  591. this.spread = SpreadJsObj.createNewSpread($('#union-spread')[0]);
  592. this.sheet = this.spread.getActiveSheet();
  593. this.tree = createNewPathTree('base', {
  594. id: 'ledger_id',
  595. pid: 'ledger_pid',
  596. order: 'order',
  597. level: 'level',
  598. rootId: -1,
  599. });
  600. this.selectUnion = [{ value: 0, text: '' }];
  601. this.spreadSetting = {
  602. cols: [
  603. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 165, formatter: '@', cellType: 'tree', readOnly: true },
  604. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 185, formatter: '@', readOnly: true },
  605. {title: '协同人', colSpan: '1', rowSpan: '1', field: 'audit_id', hAlign: 1, width: 100, cellType: 'customizeCombo', comboItems: this.selectUnion },
  606. ],
  607. emptyRows: 0,
  608. headRows: 1,
  609. headRowHeight: [32],
  610. defaultRowHeight: 21,
  611. headerFont: '12px 微软雅黑',
  612. font: '12px 微软雅黑',
  613. };
  614. sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  615. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  616. const self = this;
  617. SpreadJsObj.addDeleteBind(this.spread, function() { return; });
  618. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  619. this.spread.bind(spreadNS.Events.EditEnded, function(e, info) {
  620. const node = SpreadJsObj.getSelectObject(info.sheet);
  621. if (!node) return;
  622. const refreshAuditId = [];
  623. if (node.audit_id) refreshAuditId.push(node.audit_id);
  624. const col = info.sheet.zh_setting.cols[info.col];
  625. node[col.field] = info.editingText;
  626. if (node.audit_id) refreshAuditId.push(node.audit_id);
  627. self.refreshUnionCount(refreshAuditId);
  628. });
  629. $('#union').on('shown.bs.modal', function() {
  630. self.spread.refresh();
  631. });
  632. $('#union-ok').click(function() {
  633. const data = self.getUnionAuditLedgerData();
  634. postData(`/sp/${spid}/shenpi/union/save`, data, function(result) {
  635. $('#union').modal('hide');
  636. });
  637. });
  638. $('body').on('click', '[name=clear-union]', function() {
  639. const aid = parseInt(this.getAttribute('aid'));
  640. for (const node of self.tree.nodes) {
  641. if (node.audit_id === aid) node.audit_id = 0;
  642. }
  643. SpreadJsObj.reloadColData(self.sheet, 2);
  644. self.refreshUnionCount(aid);
  645. });
  646. }
  647. _refreshUnionTree() {
  648. const ledgerAss = {};
  649. for (const a of this.auditors) {
  650. a.lid.forEach(l => { ledgerAss[l] = a; });
  651. }
  652. for (const n of this.tree.nodes) {
  653. const la = ledgerAss[n.ledger_id];
  654. n.audit_id = la ? la.audit_id : 0;
  655. n.audit_name = la ? la.name : '';
  656. }
  657. SpreadJsObj.reloadColData(this.sheet, 2);
  658. }
  659. setUnionAuditors(auditors) {
  660. this.auditors = auditors;
  661. this.selectUnion.length = 1;
  662. const html = [];
  663. for (const auditor of auditors) {
  664. auditor.lid = auditor.audit_ledger_id ? auditor.audit_ledger_id.split(',') : [];
  665. html.push(`<tr><td>${auditor.name}</td><td>${auditor.company}</td><td><span aid="${auditor.audit_id}">${auditor.lid.length}</span><button class="ml-2 btn btn-sm btn-outline-danger" name="clear-union" aid="${auditor.audit_id}">清空</button></td></tr>`);
  666. this.selectUnion.push({ value: auditor.audit_id, text: auditor.name });
  667. }
  668. $('#union_table').html(html.join(''));
  669. this._refreshUnionTree();
  670. }
  671. refreshUnionCount(auditId) {
  672. const auditIds = auditId instanceof Array ? auditId : [auditId];
  673. for (const aid of auditIds) {
  674. const unionNodes = this.tree.nodes.filter(x => { return x.audit_id === aid; });
  675. $(`span[aid=${aid}]`).html(unionNodes.length);
  676. }
  677. }
  678. loadUnionData(sp_type, audit_order) {
  679. const data = { sp_type, audit_order };
  680. if (!this.loaded) data.ledger = 1;
  681. const self = this;
  682. postData(`/sp/${spid}/shenpi/union/load`, data, function(result) {
  683. self.loaded = true;
  684. if (result.ledgerList) {
  685. self.tree.loadDatas(result.ledgerList);
  686. SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
  687. }
  688. self.setUnionAuditors(result.unionAuditors);
  689. if (self.auditors.length > 0) {
  690. $('#union').modal('show');
  691. } else {
  692. toastr.warning(`${audit_order}审未添加任何协同人,请先添加协同人再分配协同台账`);
  693. }
  694. });
  695. }
  696. getUnionAuditLedgerData() {
  697. this.auditors.forEach(a => { a.lid = []; });
  698. for (const node of this.tree.nodes) {
  699. if (node.audit_id > 0) {
  700. const relaAudit = this.auditors.find(x => { return x.audit_id === node.audit_id; });
  701. if (relaAudit) relaAudit.lid.push(node.ledger_id);
  702. }
  703. }
  704. return this.auditors.map(a => {
  705. return { id: a.id, audit_ledger_id: a.lid.join(',') };
  706. });
  707. }
  708. }
  709. const auditUnion = new AuditUnion();
  710. $('body').on('click', '[name=union-set]', function() {
  711. auditUnion.loadUnionData(this.getAttribute('sp_type'), this.getAttribute('audit_order'));
  712. });
  713. class AuditMulti {
  714. constructor() {
  715. this.spread = SpreadJsObj.createNewSpread($('#multi-spread')[0]);
  716. this.sheet = this.spread.getActiveSheet();
  717. this.spreadSetting = {
  718. cols: [
  719. {title: '审批人', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 1, width: 80, formatter: '@', readOnly: true },
  720. {title: '分组/部门', colSpan: '1', rowSpan: '1', field: 'audit_group', hAlign: 0, width: 100, formatter: '@' },
  721. {title: '顺序', colSpan: '1', rowSpan: '1', field: 'audit_group_order', hAlign: 1, width: 80 },
  722. {title: '受限', colSpan: '1', rowSpan: '1', field: 'audit_group_limit', hAlign: 1, width: 60, cellType: 'checkbox' },
  723. {title: '允许退回', colSpan: '1', rowSpan: '1', field: 'audit_checkno_valid', hAlign: 1, width: 60, cellType: 'checkbox' },
  724. {title: '最少审批', colSpan: '1', rowSpan: '1', field: 'audit_group_need', hAlign: 1, width: 80 },
  725. ],
  726. emptyRows: 0,
  727. headRows: 1,
  728. headRowHeight: [32],
  729. defaultRowHeight: 21,
  730. headerFont: '12px 微软雅黑',
  731. font: '12px 微软雅黑',
  732. };
  733. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  734. const self = this;
  735. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  736. $('#multi').on('shown.bs.modal', function() {
  737. self.spread.refresh();
  738. });
  739. $('#multi-ok').click(function() {
  740. const data = self.getAuditData();
  741. if (self.audit_type === auditType.key.and) {
  742. const exist = !data[0].audit_group_order ? data.find(x => { return !!x.audit_group_order; }) : data.find(x => { return !x.audit_group_order; });
  743. if (exist) {
  744. toastr.error('如需设置顺序,所有审批人均应配置顺序');
  745. return;
  746. }
  747. } else if (self.audit_type === auditType.key.multi) {
  748. const exist = data.find(x => { return !x.audit_group || !x.audit_group_order; });
  749. if (exist) {
  750. toastr.error('分组审批时,分组/部门、顺序均不可为空');
  751. return;
  752. }
  753. } else if (self.audit_type === auditType.key.or) {
  754. for (const d of data) {
  755. if (!d.audit_group_need) {
  756. toastr.error('或签必须设置最少审批人数');
  757. return;
  758. }
  759. if (d.audit_group_need < 1 || d.audit_group_need >= data.length) {
  760. toastr.error('最少审批人数必须大于0,小于审批人数');
  761. return;
  762. }
  763. }
  764. }
  765. postData(`/sp/${spid}/shenpi/multi/save`, data, function(result) {
  766. const flow = sp_lc.find(x => { return x.code === self.sp_type; });
  767. const multiData = flow.auditGroupList.find(x => { return x[0].audit_order == self.audit_order});
  768. for (const d of result) {
  769. const md = multiData.find(x => { return x.id === d.id; });
  770. if (!md) continue;
  771. for (const prop in d) {
  772. md[prop] = d[prop];
  773. }
  774. }
  775. multiData.sort((a, b) => {
  776. if (a.audit_group === b.audit_group) {
  777. return a.audit_group_order - b.audit_group_order;
  778. } else {
  779. return a.audit_group === b.audit_group ? 0 : (a.audit_group < b.audit_group ? -1 : 1)
  780. }
  781. });
  782. $('#multi').modal('hide');
  783. $(self.multiBtn).parent().parent().html(auditUtils.getAuditGroupInnerHtml(self.sp_type, multiData, self.audit_order));
  784. });
  785. });
  786. }
  787. loadData(audit_type, sp_type, audit_order, multiBtn) {
  788. this.audit_type = audit_type;
  789. if (this.audit_type === auditType.key.multi) {
  790. $('#multi-title').html('分组审批');
  791. } else if (this.audit_type === auditType.key.and) {
  792. $('#multi-title').html('会签设置');
  793. } else if (this.audit_type === auditType.key.or) {
  794. $('#multi-title').html('或签设置');
  795. }
  796. $('[name=set-hint]').hide();
  797. $(`[name=set-hint][htype=${audit_type}]`).show();
  798. this.multiBtn = multiBtn;
  799. this.sp_type = sp_type;
  800. this.audit_order = audit_order;
  801. const flow = sp_lc.find(x => { return x.code === sp_type; });
  802. const multiData = flow.auditGroupList.find(x => { return x[0].audit_order == audit_order});
  803. this.data = JSON.parse(JSON.stringify(multiData));
  804. const typeNeedCol = [
  805. { key: auditType.key.multi, cols: ['name', 'audit_group', 'audit_group_limit', 'audit_group_order', 'audit_checkno_valid'] },
  806. { key: auditType.key.and, cols: ['name', 'audit_group_order', 'audit_checkno_valid'] },
  807. { key: auditType.key.or, cols: ['name', 'audit_group_need'] },
  808. ];
  809. const needCol = typeNeedCol.find(x => { return x.key === this.audit_type; });
  810. this.sheet.zh_setting.cols.forEach(c => {
  811. c.visible = needCol.cols.indexOf(c.field) >= 0;
  812. });
  813. SpreadJsObj.refreshColumnVisible(this.sheet);
  814. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.data);
  815. $('#multi').modal('show');
  816. }
  817. getAuditData() {
  818. const sheet = this.sheet;
  819. const col = { group: 1, order: 2, limit: 3, checkno: 4, need: 5, };
  820. const updateData = this.data.map((x, i) => {
  821. const data = { id: x.id };
  822. data.audit_group = this.audit_type === auditType.key.multi ? sheet.getText(i, col.group) : '';
  823. const order = sheet.getText(i, col.order);
  824. data.audit_group_order = order ? _.parseInt(order) || 0 : 0;
  825. data.audit_group_limit = this.audit_type === auditType.key.multi ? (sheet.getValue(i, col.limit) ? 1 : 0) : 0;
  826. data.audit_checkno_valid = sheet.getValue(i, col.checkno) ? 1 : 0;
  827. const need = sheet.getText(i, col.need);
  828. data.audit_group_need = this.audit_type === auditType.key.or ? (need ? _.parseInt(need) || 1 : 1) : 1;
  829. return data;
  830. });
  831. return updateData;
  832. }
  833. }
  834. const auditMulti = new AuditMulti();
  835. $('body').on('click', '[name=multi-set]', function() {
  836. auditMulti.loadData(auditType.key.multi, this.getAttribute('sp_type'), this.getAttribute('audit_order'), this);
  837. });
  838. $('body').on('click', '[name=and-set]', function() {
  839. auditMulti.loadData(auditType.key.and, this.getAttribute('sp_type'), this.getAttribute('audit_order'), this);
  840. });
  841. $('body').on('click', '[name=or-set]', function() {
  842. auditMulti.loadData(auditType.key.or, this.getAttribute('sp_type'), this.getAttribute('audit_order'), this);
  843. });
  844. $.subMenu({
  845. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  846. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  847. key: 'menu.1.0.0',
  848. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  849. callback: function (info) {
  850. if (info.mini) {
  851. $('.panel-title').addClass('fluid');
  852. $('#sub-menu').removeClass('panel-sidebar');
  853. } else {
  854. $('.panel-title').removeClass('fluid');
  855. $('#sub-menu').addClass('panel-sidebar');
  856. }
  857. autoFlashHeight();
  858. }
  859. });
  860. // let timer2 = null;
  861. // let oldSearchVal2 = null;
  862. // $('body').on('input propertychange', '#batch input[name="audit-name"]', function(e) {
  863. // oldSearchVal2 = e.target.value;
  864. // timer2 && clearTimeout(timer2);
  865. // timer2 = setTimeout(() => {
  866. // const newVal = $(this).val();
  867. //
  868. // const resultLength = $('#tender-list').find('.result').length;
  869. // if (resultLength > 0) {
  870. // let content = $('#tender-list').html();
  871. // const replaceStr = $('#tender-list').find('.result').eq(0).html();
  872. // const regExp2 = new RegExp('<span class="result" style="background: yellow;">' + replaceStr + '</span>', 'g');
  873. // content = content.replace(regExp2, replaceStr);
  874. // const regExp3 = new RegExp('<span class="result" style="background: orange;">' + replaceStr + '</span>', 'g');
  875. // content = content.replace(regExp3, replaceStr);
  876. // $('#tender-list').html(content);
  877. // }
  878. // $('#search-result').text('0/0');
  879. // $('#up-search').attr('disabled', true);
  880. // $('#down-search').attr('disabled', true);
  881. // if (newVal && newVal === oldSearchVal2) {
  882. // const regExp = new RegExp(newVal, 'g');
  883. // for (let i = 0; i < $('#tender-list tr').length; i++) {
  884. // if (_.includes($('#tender-list tr').eq(i).children('td').eq(2).html(), newVal)) {
  885. // $('#tender-list tr').eq(i).children('td').eq(2).html($('#tender-list tr').eq(i).children('td').eq(2).html().replace(regExp, '<span class="result" style="background: yellow;">' + newVal + '</span>'))
  886. // }
  887. // }
  888. // const resultLength2 = $('#tender-list').find('.result').length;
  889. // if (resultLength2 > 0) {
  890. // $('#tender-list').find('.result').eq(0).css('background', 'orange');
  891. // $('#search-result').text('1/' + resultLength2);
  892. // $('#up-search').attr('disabled', false);
  893. // $('#down-search').attr('disabled', false);
  894. // }
  895. // }
  896. // if($('#tender-list').find('.result').length > 0) {
  897. // const X = $('#tender-list').find('.result').eq(0).offset().top;
  898. // $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  899. // }
  900. // }, 400);
  901. // });
  902. // $('#up-search').on('click', function () {
  903. // const cur = parseInt($('#search-result').text().split('/')[0]);
  904. // const total = parseInt($('#search-result').text().split('/')[1]);
  905. // const now = cur - 1 !== 0 ? cur - 1: total;
  906. // $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  907. // $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  908. // // $('#tender-list tr').eq(searchUser[cur-1]).children('td').eq(2).html($('#tender-list tr').eq(searchUser[cur-1]).children('td').eq(2).html().replace('<span class="result" style="background:orange;">', '<span class="result" style="background:yellow;">'))
  909. // // $('#tender-list tr').eq(searchUser[now-1]).children('td').eq(2).html($('#tender-list tr').eq(searchUser[now-1]).children('td').eq(2).html().replace('<span class="result" style="background:yellow;">', '<span class="result" style="background:orange;">'))
  910. // $('#search-result').text(now + '/' + total);
  911. // const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  912. // $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  913. // });
  914. //
  915. // $('#down-search').on('click', function () {
  916. // const cur = parseInt($('#search-result').text().split('/')[0]);
  917. // const total = parseInt($('#search-result').text().split('/')[1]);
  918. // const now = cur + 1 > total ? 1: cur + 1;
  919. // $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  920. // $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  921. // // $('#tender-list tr').eq(searchUser[cur-1]).children('td').eq(2).html($('#tender-list tr').eq(searchUser[cur-1]).children('td').eq(2).html().replace('<span class="result" style="background:orange;">', '<span class="result" style="background:yellow;">'))
  922. // // $('#tender-list tr').eq(searchUser[now-1]).children('td').eq(2).html($('#tender-list tr').eq(searchUser[now-1]).children('td').eq(2).html().replace('<span class="result" style="background:yellow;">', '<span class="result" style="background:orange;">'))
  923. // $('#search-result').text(now + '/' + total);
  924. // const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  925. // $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() -30);
  926. // });
  927. // 审批组
  928. $('body').on('click', '.show-spzsave', function () {
  929. const this_code = $(this).attr('data-code');
  930. const groupId = $(this).attr('data-group') || null;
  931. const flow = sp_lc.find(x => { return x.code === this_code; });
  932. $('#save-code').val(this_code);
  933. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  934. if (group) {
  935. $('#save-group-id').val(group.id);
  936. $('#spzsave input[name="group_name"]').val(group.name);
  937. $('#show-delete-group-btn').show();
  938. } else {
  939. $('#save-group-id').val('');
  940. $('#spzsave input[name="group_name"]').val('');
  941. $('#show-delete-group-btn').hide();
  942. }
  943. if (this_code === 'contract') {
  944. if (group) {
  945. $('#show-contract-type input').each(function () {
  946. if (group.change_type[$(this).data('type')]) {
  947. $(this).prop('checked', true);
  948. } else {
  949. $(this).prop('checked', false);
  950. }
  951. });
  952. } else {
  953. $('#show-contract-type input').each(function () {
  954. $(this).prop('checked', false);
  955. });
  956. $('#show-contract-type input[data-type="contract"]').prop('checked', true);
  957. }
  958. $('#show-contract-type input').removeAttr('disabled');
  959. $('#show-contract-type').show();
  960. } else {
  961. $('#show-contract-type input').attr('disabled', true);
  962. $('#show-contract-type').hide();
  963. }
  964. $('#spzsave').modal('show');
  965. });
  966. $('#save-group-btn').click(function () {
  967. const name = _.trim($('#spzsave input[name="group_name"]').val());
  968. if (!name) {
  969. toastr.error('审批组名称不能为空');
  970. return false;
  971. }
  972. if (name.length > 50) {
  973. toastr.error('审批组名称不能超过50个字符');
  974. return false;
  975. }
  976. const code = $('#save-code').val();
  977. const prop = {
  978. type: 'save-group',
  979. name,
  980. code,
  981. }
  982. const groupId = $('#save-group-id').val();
  983. const flow = sp_lc.find(x => { return x.code === code; });
  984. if (flow.groupList && flow.groupList.length >= 0 && _.findIndex(flow.groupList, function (item) {
  985. return item.name === name && item.id !== parseInt(groupId);
  986. }) !== -1) {
  987. toastr.error('审批组名称已存在, 请更改名称');
  988. return false;
  989. }
  990. if (groupId) {
  991. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  992. if (!group) {
  993. toastr.error('审批组不存在');
  994. return false;
  995. }
  996. prop.groupId = group.id;
  997. }
  998. if (code === 'change') {
  999. const change_type = {};
  1000. let change_flag = false;
  1001. $('#show-change-type input').each(function () {
  1002. change_type[$(this).data('type')] = $(this).prop('checked');
  1003. if ($(this).prop('checked')) {
  1004. change_flag = true;
  1005. }
  1006. });
  1007. if (!change_flag) {
  1008. toastr.error('请至少选择一种变更显示模块');
  1009. return false;
  1010. }
  1011. prop.change_type = change_type;
  1012. } else if (code === 'contract') {
  1013. const change_type = {};
  1014. let contract_flag = false;
  1015. $('#show-contract-type input').each(function () {
  1016. change_type[$(this).data('type')] = $(this).prop('checked');
  1017. if ($(this).prop('checked')) {
  1018. contract_flag = true;
  1019. }
  1020. });
  1021. if (!contract_flag) {
  1022. toastr.error('请至少选择一种合同显示模块');
  1023. return false;
  1024. }
  1025. prop.change_type = change_type;
  1026. }
  1027. console.log(prop);
  1028. postData('/sp/' + spid + '/shenpi/audit/save', prop, function (data) {
  1029. flow.auditGroupList = data.group.auditGroupList || [];
  1030. if (groupId) {
  1031. const index = flow.groupList.findIndex(x => { return x.id === parseInt(groupId); });
  1032. flow.groupList[index] = data.group;
  1033. } else {
  1034. if (!flow.groupList) flow.groupList = [];
  1035. for (const g of flow.groupList) {
  1036. g.is_select = 0;
  1037. }
  1038. flow.groupList.push(data.group);
  1039. }
  1040. // 配置页面
  1041. let addhtml = auditUtils.getGroupHtml(flow, code);
  1042. addhtml += '<ul class="list-unstyled">\n';
  1043. addhtml += auditUtils.getgdsplHtml(flow, code);
  1044. addhtml += '</ul>\n';
  1045. $('.' + code + '_div').children('.lc-show').html(addhtml);
  1046. $('#spzsave').modal('hide');
  1047. });
  1048. });
  1049. // 切换审批组
  1050. $('body').on('change', '.group-list', function () {
  1051. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  1052. const flow = sp_lc.find(x => { return x.code === this_code; });
  1053. const groupId = parseInt($(this).val());
  1054. const _self = $(this);
  1055. const prop = {
  1056. type: 'change-group',
  1057. groupId,
  1058. }
  1059. postData('/sp/' + spid + '/shenpi/audit/save', prop, function (data) {
  1060. flow.groupList.forEach(function (item) {
  1061. item.is_select = 0;
  1062. });
  1063. const group = flow.groupList.find(x => { return x.id === groupId; });
  1064. group.is_select = 1;
  1065. flow.auditGroupList = group.auditGroupList;
  1066. const addhtml = auditUtils.getgdsplHtml(flow, this_code);
  1067. _self.parents('.lc-show').children('ul').html(addhtml);
  1068. _self.parents('.lc-show').find('.edit-spzsave').attr('data-group', groupId);
  1069. });
  1070. });
  1071. $('#show-delete-group-btn').click(function () {
  1072. const code = $('#save-code').val();
  1073. const groupId = $('#save-group-id').val();
  1074. const flow = sp_lc.find(x => { return x.code === code; });
  1075. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1076. if (!group) {
  1077. toastr.error('该审批组不存在');
  1078. return false;
  1079. }
  1080. $('#delete-group-name').text(group.name);
  1081. $('#delete-group-id').val(group.id);
  1082. $('#delete-code').val(code);
  1083. $('#spzsave').modal('hide');
  1084. $('#spzdelete').modal('show');
  1085. });
  1086. $('#delete-group-btn').click(function () {
  1087. const code = $('#delete-code').val();
  1088. const groupId = $('#delete-group-id').val();
  1089. const flow = sp_lc.find(x => { return x.code === code; });
  1090. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1091. if (!group) {
  1092. toastr.error('该审批组不存在');
  1093. return false;
  1094. }
  1095. const prop = {
  1096. type: 'delete-group',
  1097. groupId: group.id,
  1098. }
  1099. console.log(prop);
  1100. postData('/sp/' + spid + '/shenpi/audit/save', prop, function (data) {
  1101. // const flow = findSplc(code);
  1102. const index = flow.groupList.findIndex(x => { return x.id === group.id; });
  1103. flow.groupList.splice(index, 1);
  1104. flow.auditGroupList = flow.groupList.length > 0 ? flow.groupList[0].auditGroupList : [];
  1105. if (flow.groupList.length > 0) flow.groupList[0].is_select = 1;
  1106. // 配置页面
  1107. let addhtml = auditUtils.getGroupHtml(flow, code);
  1108. addhtml += '<ul class="list-unstyled">\n';
  1109. addhtml += auditUtils.getgdsplHtml(flow, code);
  1110. addhtml += '</ul>\n';
  1111. $('.' + code + '_div').children('.lc-show').html(addhtml);
  1112. $('#spzdelete').modal('hide');
  1113. });
  1114. });
  1115. });
  1116. // 审批流程-审批人html 生成
  1117. function makeAudit(audit, i = '终') {
  1118. return '<li class="d-flex justify-content-start mb-3">\n' +
  1119. ' <span class="col-auto">'+ i +'审</span>\n' +
  1120. ' <span class="col-7 spr-span">\n' +
  1121. ' <span class="d-inline-block"></span>\n' +
  1122. ' <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  1123. ' <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' +
  1124. ' <div class="dropdown-menu">\n' +
  1125. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  1126. ' <div class="dropdown-divider"></div>\n' +
  1127. ' <div class="px-2 py-1 text-center">\n' +
  1128. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  1129. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  1130. ' </div>\n' +
  1131. ' </div>\n' +
  1132. ' </span> ' +
  1133. // '<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' +
  1134. ' </span></span></span>\n' +
  1135. ' </li>';
  1136. }
  1137. // 审批流程-选择审批人html 生成
  1138. function makeSelectAudit(code, i = '终') {
  1139. let divhtml = '';
  1140. accountGroup.forEach((group, idx) => {
  1141. let didivhtml = '';
  1142. if(group) {
  1143. group.groupList.forEach(item => {
  1144. 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' +
  1145. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  1146. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  1147. ' <span class="text-muted">' + item.role + '</span>\n' +
  1148. ' </dd>\n' : '';
  1149. });
  1150. 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' +
  1151. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  1152. ' </div>\n';
  1153. }
  1154. });
  1155. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  1156. ' <span class="col-auto">' + i + '审</span>\n' +
  1157. ' <span class="col-7 spr-span">\n' +
  1158. ' <span class="d-inline-block">\n' +
  1159. ' <div class="dropdown text-right">\n' +
  1160. ' <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' +
  1161. ' 选择审批人\n' +
  1162. ' </button>\n' +
  1163. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  1164. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  1165. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  1166. ' <dl class="list-unstyled book-list">\n' + divhtml +
  1167. ' </dl>\n' +
  1168. ' </div>\n' +
  1169. ' </div>\n' +
  1170. ' </span>\n' +
  1171. ' </span>\n' +
  1172. ' </li>';
  1173. return html;
  1174. }