shenpi.js 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/10/09
  7. * @version
  8. */
  9. // 冲突解决,要把这里丢tenderTree改成tenderTree2
  10. const tenderTree2 = [];
  11. let parentId2 = 0;
  12. let selects;
  13. let auditUtils;
  14. const needYB = ['advance', 'ledger', 'revise', 'change', 'audit-ass', 'contract'];
  15. // 查询方法
  16. function findNode2 (key, value, arr) {
  17. for (const a of arr) {
  18. if (a[key] && a[key] === value) {
  19. return a;
  20. }
  21. }
  22. }
  23. // 分类数据排序
  24. function sortCategory2() {
  25. category.sort(function (a, b) {
  26. return a.level ? (b.level ? a.level - b.level : -1) : a.id - b.id;
  27. });
  28. }
  29. // 初始化TenderTree数据
  30. function initTenderTree2 () {
  31. const levelCategory = category.filter(function (c) {
  32. return c.level && c.level > 0;
  33. });
  34. function findCategoryNode2(cid, value, array) {
  35. for (const a of array) {
  36. if (a.cid === cid && a.vid === value) {
  37. return a;
  38. }
  39. }
  40. }
  41. function getCategoryNode2(category, value, parent, i = null) {
  42. const array = parent ? parent.children : tenderTree2;
  43. let cate = findCategoryNode2(category.id, value, array);
  44. if (!cate) {
  45. const cateValue = findNode2('id', value, category.value);
  46. if (!cateValue) return null;
  47. cate = {
  48. cid: category.id,
  49. vid: value,
  50. name: cateValue.value,
  51. children: [],
  52. level: i ? i : category.level,
  53. sort_id: ++parentId2,
  54. sort: cateValue.sort,
  55. };
  56. array.push(cate);
  57. }
  58. return cate;
  59. }
  60. function loadTenderCategory2 (tender) {
  61. let tenderCategory = null;
  62. for (const [index,lc] of levelCategory.entries()) {
  63. const tenderCate = findNode2('cid', lc.id, tender.category);
  64. if (tenderCate) {
  65. tenderCategory = getCategoryNode2(lc, tenderCate.value, tenderCategory);
  66. } else {
  67. if (index === 0 && tender.category) {
  68. for (const [i,c] of tender.category.entries()) {
  69. const cate = findNode2('id', c.cid, category);
  70. if (cate) tenderCategory = getCategoryNode2(cate, c.value, tenderCategory, i+1);
  71. }
  72. }
  73. return tenderCategory;
  74. }
  75. }
  76. return tenderCategory;
  77. }
  78. function calculateTender2(tender) {
  79. if (tender.lastStage) {
  80. tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp);
  81. tender.end_contract_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp);
  82. tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp);
  83. tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp);
  84. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  85. tender.yf_tp = ZhCalc.add(tender.lastStage.yf_tp);
  86. tender.end_yf_tp = ZhCalc.add(tender.lastStage.pre_yf_tp, tender.yf_tp);
  87. }
  88. }
  89. tenderTree2.splice(0, tenderTree2.length);
  90. for (const t of tenders) {
  91. calculateTender2(t);
  92. t.valid = true;
  93. delete t.level;
  94. if (t.category && levelCategory.length > 0) {
  95. const parent = loadTenderCategory2(t);
  96. if (parent) {
  97. t.level = parent.level + 1;
  98. parent.children.push(t);
  99. } else {
  100. tenderTree2.push(t);
  101. }
  102. } else {
  103. tenderTree2.push(t);
  104. }
  105. }
  106. sortTenderTree(tenderTree2);
  107. console.log(tenderTree2);
  108. }
  109. function recursiveGetTenderNodeHtml2 (node, arr, pid, this_code, this_status, aidList = []) {
  110. const html = [];
  111. html.push('<tr pid="' + pid + '">');
  112. // 名称
  113. html.push('<td class="in-' + node.level + '">');
  114. if (node.cid) {
  115. html.push('<i class="fa fa-folder-o"></i> ', node.name);
  116. } else {
  117. html.push('<span class="text-muted mr-2">');
  118. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  119. html.push('</span>');
  120. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  121. html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');
  122. }
  123. html.push('</td>');
  124. // 创建人
  125. // html.push('<td>', sp_status_list[node.shenpiInfo[shenpi_type]].name, '</td>');
  126. html.push('<td>');
  127. if (!node.cid) {
  128. if(cur_tenderid === node.id) {
  129. html.push(sp_status_list[this_status].name);
  130. } else {
  131. html.push(sp_status_list[node.shenpiInfo[this_code]].name);
  132. }
  133. }
  134. html.push('</td>');
  135. html.push('<td>');
  136. if (!node.cid) {
  137. let auditList = [];
  138. let tender_status = 1;
  139. if(cur_tenderid === node.id) {
  140. auditList = aidList;
  141. tender_status = this_status;
  142. } else {
  143. auditList = node.shenpiauditList[this_code];
  144. tender_status = node.shenpiInfo[this_code];
  145. }
  146. if(tender_status === sp_status.gdspl || tender_status === sp_status.gdzs) {
  147. const nameList = [];
  148. if(auditList) {
  149. for (const uid of auditList) {
  150. const user = _.find(accountList, { id: uid });
  151. if (user) nameList.push(user.name);
  152. }
  153. }
  154. // html.push('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
  155. // 'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
  156. html.push(nameList.length > 0 ? nameList.join('-') : '');
  157. }
  158. }
  159. html.push('</td>');
  160. html.push('<td>');
  161. if (!node.cid) {
  162. html.push('<input data-tid="'+ node.id +'" type="checkbox"'+ (cur_tenderid === node.id ? ' checked disabled' : '') +'>');
  163. }
  164. html.push('</td>');
  165. html.push('</tr>');
  166. if (node.children) {
  167. for (const c of node.children) {
  168. html.push(recursiveGetTenderNodeHtml2(c, node.children, node.sort_id, this_code, this_status, aidList));
  169. }
  170. }
  171. return html.join('');
  172. }
  173. // 根据TenderTree数据获取Html代码
  174. function getTenderTreeHtml2 (this_code, this_status, aidList = []) {
  175. if (tenderTree2.length > 0) {
  176. const html = [];
  177. html.push('<table class="table table-hover table-bordered">');
  178. html.push('<thead>', '<tr>');
  179. html.push('<th>名称</th>');
  180. html.push('<th width="80">流程模式</th>');
  181. html.push('<th>详细流程</th>');
  182. html.push('<th width="40">选择</th>');
  183. html.push('</tr>', '</thead>');
  184. parentId2 = 0;
  185. for (const t of tenderTree2) {
  186. html.push(recursiveGetTenderNodeHtml2(t, tenderTree2, '', this_code, this_status, aidList));
  187. }
  188. html.push('</table>');
  189. return html.join('');
  190. } else {
  191. return EmptyTenderHtml.join('');
  192. }
  193. }
  194. function getShenpiHtml (this_code) {
  195. const html = [];
  196. html.push('<table class="table table-hover table-bordered">');
  197. html.push('<thead>', '<tr>');
  198. html.push('<th>名称</th>');
  199. html.push('<th width="100">审批流程</th>');
  200. html.push('<th width="40">选择</th>');
  201. html.push('</tr>', '</thead>');
  202. for (const sp of sp_lc) {
  203. html.push('<tr>');
  204. html.push('<td>', sp.name, '</td>');
  205. html.push('<td>');
  206. const this_status = parseInt($('.' + sp.code + '_div').children('.lc-show').siblings('.form-group').find('input:checked').val());
  207. html.push(sp_status_list[this_status].name);
  208. if(this_status !== sp_status.sqspr) {
  209. const nameList = [];
  210. const aid_num = $('.' + sp.code + '_div').children('.lc-show').children('ul').find('.remove-audit').length;
  211. const aidList = [];
  212. for (let i = 0; i < aid_num; i++) {
  213. const aid = parseInt($('.' + sp.code + '_div').children('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
  214. aidList.push(aid);
  215. }
  216. if(aidList.length > 0) {
  217. for (const uid of aidList) {
  218. const user = _.find(accountList, { id: uid });
  219. if (user) nameList.push(user.name);
  220. }
  221. }
  222. html.push('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
  223. 'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
  224. }
  225. html.push('</td>');
  226. html.push('<td>', this_code !== sp.code ? '<input type="checkbox" data-code="'+ sp.code +'"' + (sp.groupList && sp.groupList.length > 0 ? 'disabled' : '') + '>' : '', '</td>');
  227. html.push('</tr>');
  228. }
  229. html.push('</table>');
  230. return html.join('');
  231. }
  232. $(document).ready(function () {
  233. auditUtils = {
  234. getAuditHtml: function(audit) {
  235. return '<span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  236. ' <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' +
  237. ' <div class="dropdown-menu">\n' +
  238. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  239. ' <div class="dropdown-divider"></div>\n' +
  240. ' <div class="px-2 py-1 text-center">\n' +
  241. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  242. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  243. ' </div>\n' +
  244. ' </div>\n' +
  245. ' </span> ' +
  246. ' </span></span>\n'
  247. },
  248. getAuditTypeHtml: function(code, type) {
  249. const html = [];
  250. html.push(`<span class="d-inline-block"><select class="form-control form-control-sm audit-type-key" data-type="${type}">`);
  251. for (const t of auditType.types) {
  252. if (t.valid && t.valid.indexOf(code) < 0) continue;
  253. html.push(`<option value="${t.value}" ${t.value === type ? 'selected' : ''}>${t.name}</option>`);
  254. }
  255. html.push('</select></span> ');
  256. return html.join('');
  257. },
  258. getSelectAuditHtml: function (code) {
  259. let divhtml = '';
  260. accountGroup.forEach((group, idx) => {
  261. let didivhtml = '';
  262. if(group) {
  263. group.groupList.forEach(item => {
  264. 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' +
  265. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  266. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  267. ' <span class="text-muted">' + item.role + '</span>\n' +
  268. ' </dd>\n' : '';
  269. });
  270. 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' +
  271. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  272. ' </div>\n';
  273. }
  274. });
  275. const html =
  276. ' <span class="d-inline-block">\n' +
  277. ' <div class="dropdown text-right">\n' +
  278. ' <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' +
  279. ' 选择审批人\n' +
  280. ' </button>\n' +
  281. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  282. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  283. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  284. ' <dl class="list-unstyled book-list">\n' + divhtml +
  285. ' </dl>\n' +
  286. ' </div>\n' +
  287. ' </div>\n' +
  288. ' </span>\n';
  289. return html;
  290. },
  291. // 以下i从1开始
  292. getAuditGroupInnerHtml: function(code, auditGroup, i) {
  293. const html = [];
  294. const type = auditGroup.length > 0 ? auditGroup[0].audit_type : auditType.key.common;
  295. html.push(`<span class="col-auto">${transFormToChinese(i)}审</span><span class="col-7 spr-span">`);
  296. html.push(this.getAuditTypeHtml(code, type));
  297. for (const audit of auditGroup) {
  298. html.push(this.getAuditHtml(audit));
  299. }
  300. if (type !== auditType.key.common || auditGroup.length === 0) {
  301. html.push(this.getSelectAuditHtml(code));
  302. }
  303. if (type === auditType.key.and && auditType.info[auditType.key.and].setValid.indexOf(code) >= 0 && auditGroup.length > 0) {
  304. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="and-set">会签设置</button>`);
  305. }
  306. if (type === auditType.key.or && auditType.info[auditType.key.or].setValid.indexOf(code) >= 0 && auditGroup.length > 0) {
  307. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="or-set">或签设置</button>`);
  308. }
  309. if (type === auditType.key.multi && auditGroup.length > 0) {
  310. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="multi-set">分组设置</button>`);
  311. }
  312. if (type === auditType.key.union && auditGroup.length > 0) {
  313. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="union-set">协同设置</button>`);
  314. }
  315. html.push('</span>');
  316. return html.join('');
  317. },
  318. getAuditGroupHtml: function (code, auditGroup, i) {
  319. return `<li class="d-flex justify-content-start align-items-center mb-3">${this.getAuditGroupInnerHtml(code, auditGroup, i)}</li>`;
  320. },
  321. getFinalAuditHtml: function (audit) {
  322. const html = [];
  323. html.push('<li class="d-flex justify-content-start mb-3"><span class="col-auto">终审</span><span class="col-7 spr-span">');
  324. html.push(this.getAuditHtml(audit));
  325. html.push('</span></span></li>');
  326. return html.join('');
  327. },
  328. getGroupHtml: function (flow, this_code) {
  329. let html = '';
  330. if (flow && flow.groupList && flow.groupList.length > 0) {
  331. let groupSelectHtml = '';
  332. for (const group of flow.groupList) {
  333. groupSelectHtml += `<option value="${group.id}" ${group.is_select === 1 ? 'selected' : ''}>${group.name}</option>`;
  334. }
  335. const selectGroup = flow.groupList.find(x => { return x.is_select === 1 });
  336. html += '<div class="d-flex justify-content-start align-items-center mb-3">\n' +
  337. ' <span class="col-auto">当前审批组:</span>\n' +
  338. ' <span style="width: 200px;">\n' +
  339. ' <select class="form-control form-control-sm group-list">\n' +
  340. groupSelectHtml +
  341. ' </select>\n' +
  342. ' </span>\n' +
  343. ` <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` +
  344. ` <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` +
  345. ' </div>';
  346. }
  347. return html;
  348. },
  349. getgdsplHtml(flow, this_code) {
  350. let addhtml = '';
  351. if (flow.auditGroupList.length !== 0) {
  352. for(const [i, auditGroup] of flow.auditGroupList.entries()) {
  353. addhtml += this.getAuditGroupHtml(this_code, auditGroup, i + 1);
  354. }
  355. const addGroupHtml = (this_code === 'change' || this_code === 'stage' || this_code === 'contract') && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
  356. `<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` : '';
  357. addhtml += '<li>\n' +
  358. ' <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>\n' + addGroupHtml +
  359. ' </li>';
  360. } else {
  361. addhtml += this.getAuditGroupHtml(this_code, [], 1);
  362. }
  363. return addhtml;
  364. },
  365. // 以下i从0开始
  366. addAudit: function (code, user, i) {
  367. const flow = sp_lc.find(x => { return x.code === code });
  368. if (!flow.auditGroupList) flow.auditGroupList = [];
  369. if (!flow.auditGroupList[i]) flow.auditGroupList[i] = [];
  370. flow.auditGroupList[i].push(user);
  371. return flow.auditGroupList[i];
  372. },
  373. removeAudit: function (code, audit_id, i) {
  374. const flow = sp_lc.find(x => { return x.code === code });
  375. if (flow.auditGroupList[i].length === 1) {
  376. flow.auditGroupList.splice(i, 1);
  377. return null;
  378. }
  379. flow.auditGroupList[i].splice(flow.auditGroupList[i].findIndex(x => { return x.audit_id === audit_id; }), 1);
  380. return flow.auditGroupList[i];
  381. },
  382. setAuditType: function (code, audit_type, i) {
  383. const flow = sp_lc.find(x => { return x.code === code });
  384. if (!flow || !flow.auditGroupList || !flow.auditGroupList[i]) return;
  385. flow.auditGroupList[i].forEach(x => { x.audit_type = audit_type});
  386. return flow.auditGroupList[i];
  387. }
  388. };
  389. let timer = null;
  390. let oldSearchVal = null;
  391. $('body').on('input propertychange', 'div[id$="_dropdownMenu"] .gr-search', function(e) {
  392. oldSearchVal = e.target.value;
  393. timer && clearTimeout(timer);
  394. timer = setTimeout(() => {
  395. const newVal = $(this).val();
  396. const code = $(this).attr('data-code');
  397. let html = '';
  398. if (newVal && newVal === oldSearchVal) {
  399. 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 => {
  400. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  401. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  402. class="ml-auto">${item.mobile || ''}</span></p>
  403. <span class="text-muted">${item.role || ''}</span>
  404. </dd>`
  405. });
  406. $('#' + code + '_dropdownMenu .book-list').empty();
  407. $('#' + code + '_dropdownMenu .book-list').append(html);
  408. } else {
  409. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  410. accountGroup.forEach((group, idx) => {
  411. if (!group) return;
  412. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  413. </a> ${group.groupName}</dt>
  414. <div class="dd-content" data-toggleid="${idx}">`;
  415. group.groupList.forEach(item => {
  416. if ((item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1))) {
  417. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  418. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  419. class="ml-auto">${item.mobile || ''}</span></p>
  420. <span class="text-muted">${item.role || ''}</span>
  421. </dd>`;
  422. }
  423. });
  424. html += '</div>';
  425. });
  426. $('#' + code + '_dropdownMenu .book-list').empty();
  427. $('#' + code + '_dropdownMenu .book-list').append(html);
  428. }
  429. }
  430. }, 400);
  431. });
  432. // 添加审批流程按钮逻辑
  433. $('body').on('click', 'div[id$="_dropdownMenu"] .book-list dt', function () {
  434. const idx = $(this).find('.acc-btn').attr('data-groupid');
  435. const type = $(this).find('.acc-btn').attr('data-type');
  436. if (type === 'hide') {
  437. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  438. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  439. $(this).find('.acc-btn').attr('data-type', 'show');
  440. })
  441. } else {
  442. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  443. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  444. $(this).find('.acc-btn').attr('data-type', 'hide');
  445. })
  446. }
  447. return false;
  448. });
  449. // 更改审批流程状态
  450. $('body').on('change', '.form-check input[type="radio"]', function () {
  451. // 获取所有审批的checked值并更新
  452. const this_status = parseInt($(this).val());
  453. const this_code = $(this).data('code');
  454. const spt = sp_status_list[this_status];
  455. $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
  456. // 拼接post json
  457. const prop = {
  458. code: this_code,
  459. status: this_status
  460. };
  461. const _self = $(this);
  462. postData('/tender/' + cur_tenderid + '/shenpi/save', prop, function (data) {
  463. if (this_status === sp_status.sqspr) {
  464. _self.parents('.form-group').siblings('.lc-show').html('');
  465. } else if (this_status === sp_status.gdspl) {
  466. const flow = sp_lc.find(x => { return x.code === this_code; });
  467. flow.auditGroupList = data.auditList;
  468. flow.groupList = data.groupList;
  469. let addhtml = auditUtils.getGroupHtml(flow, this_code);
  470. addhtml += '<ul class="list-unstyled">\n';
  471. addhtml += auditUtils.getgdsplHtml(flow, this_code);
  472. addhtml += '</ul>\n';
  473. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  474. } else if (this_status === sp_status.gdzs) {
  475. let addhtml = '<ul class="list-unstyled">\n' +
  476. ' <li class="d-flex justify-content-start mb-3">\n' +
  477. ' <span class="col-auto">授权审批人</span>\n' +
  478. ' <span class="col-7">\n' +
  479. ' <span class="d-inline-block"></span>\n' +
  480. ' </span>\n' +
  481. ' </li>\n';
  482. addhtml += data.auditList ? makeAudit(data.auditList) : makeSelectAudit(this_code);
  483. addhtml += '</ul>\n';
  484. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  485. }
  486. if(this_code === 'stage') {
  487. if(this_status === sp_status.gdspl) {
  488. $('#stage_cooperation').show();
  489. } else {
  490. $('#stage_cooperation').hide();
  491. }
  492. }
  493. });
  494. });
  495. // 选中审批人
  496. $('body').on('click', 'div[id$="_dropdownMenu"] dl dd', function () {
  497. const id = parseInt($(this).data('id'));
  498. if (!id) return;
  499. let this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  500. if (!this_code) this_code = $(this).parents('.dropdown').data('code');
  501. const user = _.find(accountList, function (item) {
  502. return item.id === id;
  503. });
  504. if (this_code === 'audit-ass') {
  505. auditAss.setAuditAssist(user);
  506. } else {
  507. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  508. if (this_status === sp_status.gdspl) {
  509. // 判断是否已存在审批人
  510. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  511. for (let i = 0; i < aid_num; i++) {
  512. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  513. if (aid === id) {
  514. toastr.warning('该审核人已存在,请勿重复添加');
  515. return;
  516. }
  517. }
  518. }
  519. const prop = {
  520. status: this_status,
  521. code: sp_type[this_code],
  522. audit_id: id,
  523. type: 'add',
  524. };
  525. if (this_status === sp_status.gdspl) {
  526. prop.audit_type = parseInt($(this).parents('li').find('select[class*="audit-type-key"]')[0].value);
  527. prop.audit_order = $(this).parents('li').index() + 1;
  528. }
  529. const _self = $(this);
  530. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  531. if (this_status === sp_status.gdspl) {
  532. const auditGroup = auditUtils.addAudit(this_code, data, prop.audit_order - 1);
  533. if (_self.parents('ul').find('.add-audit').length === 0) {
  534. const flow = sp_lc.find(x => { return x.code === this_code; });
  535. const addGroupHtml = (this_code === 'change'||this_code ==='stage' || this_code === 'contract') && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
  536. `<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` : '';
  537. _self.parents('ul').append('<li>\n' +
  538. ' <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>\n' + addGroupHtml +
  539. ' </li>');
  540. }
  541. _self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, prop.audit_order));
  542. } else {
  543. _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  544. '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <span class="dropdown">\n' +
  545. ' <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' +
  546. ' <div class="dropdown-menu">\n' +
  547. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  548. ' <div class="dropdown-divider"></div>\n' +
  549. ' <div class="px-2 py-1 text-center">\n' +
  550. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + user.id + '">移除</button>\n' +
  551. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  552. ' </div>\n' +
  553. ' </div>\n' +
  554. ' </span> ' +
  555. ' </span></span></span>\n');
  556. }
  557. });
  558. }
  559. });
  560. // 移除审批人
  561. $('body').on('click', '.remove-audit', function () {
  562. const id = parseInt($(this).data('id'));
  563. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  564. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  565. const prop = {
  566. status: this_status,
  567. code: sp_type[this_code],
  568. audit_id: id,
  569. type: 'del',
  570. };
  571. const _self = $(this);
  572. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  573. if (this_status === sp_status.gdspl) {
  574. const index = _self.parents('li').index();
  575. const auditGroup = auditUtils.removeAudit(this_code, id, index);
  576. if (auditGroup) {
  577. _self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, index + 1));
  578. } else {
  579. const _selflc = _self.parents('.lc-show');
  580. _self.parents('li').remove();
  581. const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
  582. if (aid_num === 0) {
  583. _selflc.children('ul').html(auditUtils.getAuditGroupHtml(this_code, [], 1));
  584. } else {
  585. for (let i = 0; i < aid_num; i++) {
  586. _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  587. }
  588. }
  589. }
  590. } else if (this_status === sp_status.gdzs) {
  591. let addhtml = '<ul class="list-unstyled">\n' +
  592. ' <li class="d-flex justify-content-start mb-3">\n' +
  593. ' <span class="col-auto">授权审批人</span>\n' +
  594. ' <span class="col-7">\n' +
  595. ' <span class="d-inline-block"></span>\n' +
  596. ' </span>\n' +
  597. ' </li>\n';
  598. addhtml += makeSelectAudit(this_code);
  599. addhtml += '</ul>\n';
  600. _self.parents('.lc-show').html(addhtml);
  601. }
  602. })
  603. });
  604. // 固定审批流-添加流程
  605. $('body').on('click', '.add-audit', function () {
  606. const num = $(this).parents('ul').children('li').length;
  607. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  608. //const addhtml = makeSelectAudit(this_code, transFormToChinese(num));
  609. const addhtml = auditUtils.getAuditGroupHtml(this_code, [], num);
  610. $(this).parents('ul').append(addhtml);
  611. $(this).parents('li').remove();
  612. });
  613. sortCategory2();
  614. initTenderTree2();
  615. $('body').on('click', '.set-otherTender', function () {
  616. const this_code = $(this).data('code');
  617. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  618. const lis = $(this).siblings('.lc-show').find('li');
  619. const auditList = [], aidList = [];
  620. const flow = sp_lc.find(x => { return x.code === this_code; });
  621. lis.each((i, li) => {
  622. const removes = $(li).find('.remove-audit');
  623. if (removes.length === 0) return;
  624. const select = $(li).find('select[class*="audit-type-key"]');
  625. const audit_type = select.length > 0 ? parseInt(select.val()) : 1;
  626. const multiData = flow.auditGroupList.find(x => { return x[0].audit_order == i+1; });
  627. for (const remove of removes) {
  628. const auditData = { audit_id: parseInt(remove.getAttribute('data-id')), audit_type, audit_order: i + 1 };
  629. const removeMultiData = multiData.find(x => { return x.audit_id === auditData.audit_id; });
  630. auditData.audit_group = removeMultiData ? removeMultiData.audit_group : '';
  631. auditData.audit_group_order = removeMultiData ? removeMultiData.audit_group_order : 0;
  632. auditData.audit_group_limit = removeMultiData ? removeMultiData.audit_group_limit : 0;
  633. auditData.audit_checkno_valid = removeMultiData ? removeMultiData.audit_checkno_valid : 0;
  634. auditData.audit_group_need = removeMultiData ? removeMultiData.audit_group_need : 0;
  635. auditList.push(auditData);
  636. aidList.push(parseInt(remove.getAttribute('data-id')));
  637. }
  638. });
  639. const html = getTenderTreeHtml2(this_code, this_status, aidList);
  640. $('#shenpi-name').text($(this).data('name'));
  641. $('#shenpi_code').val(this_code);
  642. $('#shenpi_status').val(this_status);
  643. $('#shenpi_auditors').val(JSON.stringify(auditList));
  644. $('#tender-list').html(html);
  645. $('#search-audit').val('');
  646. $('#search-result').text('0/0');
  647. $('#up-search').attr('disabled', true);
  648. $('#down-search').attr('disabled', true);
  649. setTimeout(function () { $("#tender-list [data-toggle='tooltip']").tooltip(); },800);
  650. });
  651. $('#save-other-tender').click(function () {
  652. $(this).attr('disabled', true);
  653. const num = $('#tender-list input:checked').length;
  654. if (num < 2) {
  655. toastr.warning('请选择需要设置审批同步的标段');
  656. $(this).removeAttr('disabled');
  657. return;
  658. }
  659. const data = {
  660. type: 'copy2ot',
  661. status: parseInt($('#shenpi_status').val()),
  662. code: $('#shenpi_code').val(),
  663. };
  664. if(data.status !== shenpi_status.gdspl) {
  665. data.auditList = JSON.parse($('#shenpi_auditors').val());
  666. }
  667. // 获取已选中的标段
  668. const tenderList = [];
  669. for (let i = 0; i < num; i++) {
  670. const tid = parseInt($('#tender-list input:checked').eq(i).data('tid'));
  671. if (tid !== cur_tenderid) {
  672. tenderList.push(tid);
  673. }
  674. }
  675. data.tidList = tenderList.join(',');
  676. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
  677. toastr.success('设置成功');
  678. setTimeout(function () {
  679. window.location.reload();
  680. }, 1000)
  681. })
  682. });
  683. $('body').on('click', '.set-otherShenpi', function () {
  684. let canSetOther = true;
  685. const this_code = $(this).data('code');
  686. // if (['stage', 'change'].indexOf(this_code) !== -1) {
  687. // const select = $(this).siblings('.lc-show').find('select[class*="audit-type-key"]');
  688. // select.each((i, s) => {
  689. // if (s.value !== '1') canSetOther = false;
  690. // });
  691. // }
  692. // if (!canSetOther) {
  693. // toastr.warning('该流程含有会签或签,不可同步至其他流程');
  694. // $('#batch2').modal('hide');
  695. // return;
  696. // }
  697. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  698. const copyFlow = [];
  699. const flow = $('li.d-flex', $(this).siblings('.lc-show'));
  700. for (const f of flow) {
  701. const audit_type = $('select', f).val() || 1;
  702. const auditors = $('.remove-audit', f);
  703. if (auditors.length === 0) continue;
  704. const aid = [];
  705. for (const a of auditors) {
  706. aid.push(a.getAttribute('data-id'));
  707. }
  708. copyFlow.push(`${audit_type}:${aid.join(',')}`);
  709. }
  710. const html = getShenpiHtml(this_code);
  711. $('#shenpi-name2').text($(this).data('name'));
  712. $('#shenpi_code2').val(this_code);
  713. $('#shenpi_status2').val(this_status);
  714. $('#shenpi_auditors2').val(copyFlow.join(';'));
  715. $('#shenpi-list').html(html);
  716. setTimeout(function () { $("#shenpi-list [data-toggle='tooltip']").tooltip(); },800);
  717. $('#batch2').modal('show');
  718. });
  719. $('#save-other-shenpi').click(function () {
  720. $(this).attr('disabled', true);
  721. const num = $('#shenpi-list input:checked').length;
  722. if (num < 1) {
  723. toastr.warning('请选择需要设置审批同步的流程');
  724. $(this).removeAttr('disabled');
  725. return;
  726. }
  727. const data = {
  728. type: 'copy2os',
  729. status: parseInt($('#shenpi_status2').val()),
  730. code: $('#shenpi_code2').val(),
  731. };
  732. if(data.status !== shenpi_status.gdspl) {
  733. data.flowList = $('#shenpi_auditors2').val();
  734. }
  735. // 获取已选中的标段
  736. const shenpiList = [];
  737. for (let i = 0; i < num; i++) {
  738. const code = $('#shenpi-list input:checked').eq(i).data('code');
  739. shenpiList.push(code);
  740. }
  741. data.shenpiList = shenpiList.join(',');
  742. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
  743. toastr.success('设置成功');
  744. setTimeout(function () {
  745. window.location.reload();
  746. }, 1000)
  747. })
  748. });
  749. // 设置会签、或签
  750. $('body').on('change', 'select[class*="audit-type-key"]', function() {
  751. const removes = $(this).parents('.d-flex').find('.remove-audit');
  752. if (removes.length === 0) return;
  753. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  754. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  755. const ids = [];
  756. const liParent = $(this).parents('li');
  757. removes.each((i, r) => { ids.push(parseInt(r.getAttribute('data-id'))); });
  758. const prop = {
  759. status: this_status,
  760. code: sp_type[this_code],
  761. audit_id: ids,
  762. audit_type: parseInt(this.value),
  763. type: 'audit-type',
  764. };
  765. if (prop.audit_type === auditType.key.common && ids.length > 1) {
  766. toastr.warning('设置个人审批前请先删除多余的审批人');
  767. this.value = this.getAttribute('data-type');
  768. return;
  769. }
  770. const _self = this;
  771. postData('/tender/'+ cur_tenderid +'/shenpi/audit/save', prop, function () {
  772. _self.setAttribute('data-type', _self.value);
  773. const auditGroup = auditUtils.setAuditType(this_code, prop.audit_type, liParent.index());
  774. liParent.html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, liParent.index() + 1));
  775. });
  776. });
  777. class AuditAss {
  778. constructor() {
  779. this.spread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  780. this.sheet = this.spread.getActiveSheet();
  781. this.tree = createNewPathTree('base', {
  782. id: 'ledger_id',
  783. pid: 'ledger_pid',
  784. order: 'order',
  785. level: 'level',
  786. rootId: -1,
  787. });
  788. this.spreadSetting = {
  789. cols: [
  790. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 165, formatter: '@', cellType: 'tree'},
  791. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  792. {title: '协同人', colSpan: '1', rowSpan: '2', field: 'ass_name', hAlign: 1, width: 100, formatter: '@'},
  793. ],
  794. emptyRows: 0,
  795. headRows: 1,
  796. headRowHeight: [25, 25],
  797. defaultRowHeight: 21,
  798. headerFont: '12px 微软雅黑',
  799. font: '12px 微软雅黑',
  800. readOnly: true,
  801. localCache: {
  802. key: 'ledger-cooperation',
  803. colWidth: true,
  804. }
  805. };
  806. sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  807. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  808. const self = this;
  809. SpreadJsObj.addDeleteBind(this.spread, function() { return; });
  810. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  811. this.spread.bind(spreadNS.Events.SelectionChanged, function() {
  812. self.refreshOperate();
  813. });
  814. $('#stage_audits').change(function () {
  815. self.uid = $(this).val();
  816. });
  817. // 多人协同
  818. $('#cooperation').on('shown.bs.modal', function () {
  819. // 执行一些动作...
  820. // 更新新的多人协同表格信息
  821. const newUidList = [];
  822. $('.stage_div ul li').each(function (k, v) {
  823. const audit_type = parseInt($(v).find('select').val());
  824. if (audit_type !== auditType.key.common) return;
  825. const uid = $(v).find('button').eq(0).data('id');
  826. if(uid) newUidList.push({ order: k + 1, audit_id: uid });
  827. });
  828. const yb = _.find(accountList, { 'id': cur_uid });
  829. let newhtml = '<option value="' + yb.id + '">' + yb.name + '(原报)</option>';
  830. if(newUidList.length > 0) {
  831. for (const id of newUidList) {
  832. const audit = _.find(accountList, { 'id': id.audit_id });
  833. newhtml += '<option value="' + audit.id + '">' + audit.name + '(' + transFormToChinese(id.order) + '审)</option>';
  834. }
  835. }
  836. $('#stage_audits').html(newhtml);
  837. self.uid = cur_uid;
  838. self.initLedgerTree(cur_uid);
  839. });
  840. $('#del-audit-ass').click(function () {
  841. self.setAuditAssist();
  842. });
  843. $('body').on('click', 'button[asid]', function () {
  844. self.removeAuditAss(parseInt(this.getAttribute('asid')));
  845. });
  846. }
  847. set uid(id) {
  848. this._uid = parseInt(id);
  849. this._refreshAss();
  850. }
  851. get uid() {
  852. return this._uid;
  853. }
  854. _refreshAssTable(){
  855. $('#stage_audit').text($("#stage_audits option:selected").text());
  856. const html = [];
  857. for (const sa of this.showAssList) {
  858. const lid = sa.ass_ledger_id ? sa.ass_ledger_id.split(',') : [];
  859. html.push(`<tr><td>${sa.name}</td><td>${sa.company}</td><td>${lid.length}<button class="ml-2 btn btn-sm btn-outline-danger" asid="${sa.id}">移除</button></td></tr>`);
  860. }
  861. $('#coo_table').html(html.join(''));
  862. }
  863. _refreshAssTree() {
  864. const ledgerAss = {};
  865. for (const sa of this.showAssList) {
  866. const ledger = sa.ass_ledger_id ? sa.ass_ledger_id.split(',') : [];
  867. ledger.forEach(l => { ledgerAss[l] = sa; });
  868. }
  869. for (const n of this.tree.nodes) {
  870. const la = ledgerAss[n.ledger_id];
  871. n.ass_audit_id = la ? la.ass_user_id : null;
  872. n.ass_name = la ? la.name : '';
  873. }
  874. SpreadJsObj.reloadColData(this.sheet, 2);
  875. }
  876. _refreshAss() {
  877. this.showAssList = _.filter(this.assList, { 'user_id': parseInt(this.uid) });
  878. this._refreshAssTable();
  879. this._refreshAssTree();
  880. }
  881. initLedgerTree(uid) {
  882. if (this.loaded && this.tid && this.tid === cur_tenderid) return;
  883. this.spread.refresh();
  884. const self = this;
  885. postData('/tender/' + cur_tenderid + '/shenpi/ass/load', {}, function (data) {
  886. self.loaded = true;
  887. self.tid = cur_tenderid;
  888. self.assList = data.auditAssList;
  889. self.tree.loadDatas(data.ledgerList);
  890. SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
  891. self.uid = uid;
  892. self.refreshOperate();
  893. }, null, true);
  894. }
  895. loadPostData(data) {
  896. if (data.add) {
  897. this.assList.push(data.add);
  898. }
  899. if (data.del) {
  900. this.assList.splice(this.assList.findIndex(x => { return x.id === data.del.id }), 1);
  901. }
  902. if (data.update) {
  903. for (const d of data.update) {
  904. const od = this.assList.find(x => { return x.id === d.id });
  905. if (!od) continue;
  906. od.ass_ledger_id = d.ass_ledger_id;
  907. }
  908. }
  909. this._refreshAss();
  910. }
  911. setAuditAssist(assist){
  912. const node = SpreadJsObj.getSelectObject(this.sheet);
  913. if (assist && node.ass_audit_id === assist.id) return;
  914. if (assist && assist.id === this.uid) {
  915. toastr.warning('请勿添加本人');
  916. return;
  917. }
  918. const self = this;
  919. const data = { type: 'audit-ass'};
  920. if (assist) {
  921. const newAss = this.showAssList.find(x => { return x.ass_user_id === assist.id; });
  922. if (!newAss) {
  923. data.add = { user_id: this.uid, ass_user_id: assist.id, name: assist.name, company: assist.company, role: assist.role, ass_ledger_id: node.ledger_id + '' };
  924. } else {
  925. data.update = [{ id: newAss.id, ass_ledger_id: newAss.ass_ledger_id + ',' + node.ledger_id}];
  926. }
  927. }
  928. if (node.ass_audit_id) {
  929. const orgAss = this.showAssList.find(x => { return x.ass_user_id === node.ass_audit_id; });
  930. const rela_lid = orgAss.ass_ledger_id ? orgAss.ass_ledger_id.split(',') : [];
  931. rela_lid.splice(rela_lid.indexOf(node.ledger_id + ''), 1);
  932. if (rela_lid.length === 0) {
  933. data.del = { id: orgAss.id };
  934. } else {
  935. if (!data.update) data.update = [];
  936. data.update.push({ id: orgAss.id, ass_ledger_id: rela_lid.join(',')});
  937. }
  938. }
  939. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function (result) {
  940. self.loadPostData(result);
  941. self.refreshOperate();
  942. });
  943. }
  944. removeAuditAss(assistId) {
  945. const self = this;
  946. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', { type: 'audit-ass', del: { id: assistId } }, function (result) {
  947. self.loadPostData(result);
  948. self.refreshOperate();
  949. });
  950. }
  951. refreshOperate() {
  952. const node = SpreadJsObj.getSelectObject(this.sheet);
  953. if (node && node.ass_audit_id) {
  954. $('#del-audit-ass').show();
  955. $('#audit-ass_dropdownMenuButton')[0].innerHTML = '替换协同人';
  956. } else {
  957. $('#del-audit-ass').hide();
  958. $('#audit-ass_dropdownMenuButton')[0].innerHTML = '添加协同人';
  959. }
  960. }
  961. }
  962. const auditAss = new AuditAss();
  963. class AuditUnion {
  964. constructor() {
  965. this.spread = SpreadJsObj.createNewSpread($('#union-spread')[0]);
  966. this.sheet = this.spread.getActiveSheet();
  967. this.tree = createNewPathTree('base', {
  968. id: 'ledger_id',
  969. pid: 'ledger_pid',
  970. order: 'order',
  971. level: 'level',
  972. rootId: -1,
  973. });
  974. this.selectUnion = [{ value: 0, text: '' }];
  975. this.spreadSetting = {
  976. cols: [
  977. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 165, formatter: '@', cellType: 'tree', readOnly: true },
  978. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 185, formatter: '@', readOnly: true },
  979. {title: '协同人', colSpan: '1', rowSpan: '1', field: 'audit_id', hAlign: 1, width: 100, cellType: 'customizeCombo', comboItems: this.selectUnion },
  980. ],
  981. emptyRows: 0,
  982. headRows: 1,
  983. headRowHeight: [32],
  984. defaultRowHeight: 21,
  985. headerFont: '12px 微软雅黑',
  986. font: '12px 微软雅黑',
  987. };
  988. sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  989. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  990. const self = this;
  991. SpreadJsObj.addDeleteBind(this.spread, function() { return; });
  992. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  993. this.spread.bind(spreadNS.Events.EditEnded, function(e, info) {
  994. const node = SpreadJsObj.getSelectObject(info.sheet);
  995. if (!node) return;
  996. const refreshAuditId = [];
  997. if (node.audit_id) refreshAuditId.push(node.audit_id);
  998. const col = info.sheet.zh_setting.cols[info.col];
  999. node[col.field] = info.editingText;
  1000. if (node.audit_id) refreshAuditId.push(node.audit_id);
  1001. self.refreshUnionCount(refreshAuditId);
  1002. });
  1003. $('#union').on('shown.bs.modal', function() {
  1004. self.spread.refresh();
  1005. });
  1006. $('#union-ok').click(function() {
  1007. const data = self.getUnionAuditLedgerData();
  1008. postData(`/tender/${cur_tenderid}/shenpi/union/save`, data, function(result) {
  1009. $('#union').modal('hide');
  1010. });
  1011. });
  1012. $('body').on('click', '[name=clear-union]', function() {
  1013. const aid = parseInt(this.getAttribute('aid'));
  1014. for (const node of self.tree.nodes) {
  1015. if (node.audit_id === aid) node.audit_id = 0;
  1016. }
  1017. SpreadJsObj.reloadColData(self.sheet, 2);
  1018. self.refreshUnionCount(aid);
  1019. });
  1020. }
  1021. _refreshUnionTree() {
  1022. const ledgerAss = {};
  1023. for (const a of this.auditors) {
  1024. a.lid.forEach(l => { ledgerAss[l] = a; });
  1025. }
  1026. for (const n of this.tree.nodes) {
  1027. const la = ledgerAss[n.ledger_id];
  1028. n.audit_id = la ? la.audit_id : 0;
  1029. n.audit_name = la ? la.name : '';
  1030. }
  1031. SpreadJsObj.reloadColData(this.sheet, 2);
  1032. }
  1033. setUnionAuditors(auditors) {
  1034. this.auditors = auditors;
  1035. this.selectUnion.length = 1;
  1036. const html = [];
  1037. for (const auditor of auditors) {
  1038. auditor.lid = auditor.audit_ledger_id ? auditor.audit_ledger_id.split(',') : [];
  1039. 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>`);
  1040. this.selectUnion.push({ value: auditor.audit_id, text: auditor.name });
  1041. }
  1042. $('#union_table').html(html.join(''));
  1043. this._refreshUnionTree();
  1044. }
  1045. refreshUnionCount(auditId) {
  1046. const auditIds = auditId instanceof Array ? auditId : [auditId];
  1047. for (const aid of auditIds) {
  1048. const unionNodes = this.tree.nodes.filter(x => { return x.audit_id === aid; });
  1049. $(`span[aid=${aid}]`).html(unionNodes.length);
  1050. }
  1051. }
  1052. loadUnionData(sp_type, audit_order) {
  1053. const data = { sp_type, audit_order };
  1054. if (!this.loaded) data.ledger = 1;
  1055. const self = this;
  1056. postData(`/tender/${cur_tenderid}/shenpi/union/load`, data, function(result) {
  1057. self.loaded = true;
  1058. if (result.ledgerList) {
  1059. self.tree.loadDatas(result.ledgerList);
  1060. SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
  1061. }
  1062. self.setUnionAuditors(result.unionAuditors);
  1063. if (self.auditors.length > 0) {
  1064. $('#union').modal('show');
  1065. } else {
  1066. toastr.warning(`${audit_order}审未添加任何协同人,请先添加协同人再分配协同台账`);
  1067. }
  1068. });
  1069. }
  1070. getUnionAuditLedgerData() {
  1071. this.auditors.forEach(a => { a.lid = []; });
  1072. for (const node of this.tree.nodes) {
  1073. if (node.audit_id > 0) {
  1074. const relaAudit = this.auditors.find(x => { return x.audit_id === node.audit_id; });
  1075. if (relaAudit) relaAudit.lid.push(node.ledger_id);
  1076. }
  1077. }
  1078. return this.auditors.map(a => {
  1079. return { id: a.id, audit_ledger_id: a.lid.join(',') };
  1080. });
  1081. }
  1082. }
  1083. const auditUnion = new AuditUnion();
  1084. $('body').on('click', '[name=union-set]', function() {
  1085. auditUnion.loadUnionData(this.getAttribute('sp_type'), this.getAttribute('audit_order'));
  1086. });
  1087. class AuditMulti {
  1088. constructor() {
  1089. this.spread = SpreadJsObj.createNewSpread($('#multi-spread')[0]);
  1090. this.sheet = this.spread.getActiveSheet();
  1091. this.spreadSetting = {
  1092. cols: [
  1093. {title: '审批人', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 1, width: 80, formatter: '@', readOnly: true },
  1094. {title: '分组/部门', colSpan: '1', rowSpan: '1', field: 'audit_group', hAlign: 0, width: 100, formatter: '@' },
  1095. {title: '顺序', colSpan: '1', rowSpan: '1', field: 'audit_group_order', hAlign: 1, width: 80 },
  1096. {title: '受限', colSpan: '1', rowSpan: '1', field: 'audit_group_limit', hAlign: 1, width: 60, cellType: 'checkbox' },
  1097. {title: '允许退回', colSpan: '1', rowSpan: '1', field: 'audit_checkno_valid', hAlign: 1, width: 60, cellType: 'checkbox' },
  1098. {title: '最少审批', colSpan: '1', rowSpan: '1', field: 'audit_group_need', hAlign: 1, width: 80 },
  1099. ],
  1100. emptyRows: 0,
  1101. headRows: 1,
  1102. headRowHeight: [32],
  1103. defaultRowHeight: 21,
  1104. headerFont: '12px 微软雅黑',
  1105. font: '12px 微软雅黑',
  1106. };
  1107. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1108. const self = this;
  1109. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  1110. $('#multi').on('shown.bs.modal', function() {
  1111. self.spread.refresh();
  1112. });
  1113. $('#multi-ok').click(function() {
  1114. const data = self.getAuditData();
  1115. if (self.audit_type === auditType.key.and) {
  1116. const exist = !data[0].audit_group_order ? data.find(x => { return !!x.audit_group_order; }) : data.find(x => { return !x.audit_group_order; });
  1117. if (exist) {
  1118. toastr.error('如需设置顺序,所有审批人均应配置顺序');
  1119. return;
  1120. }
  1121. } else if (self.audit_type === auditType.key.multi) {
  1122. const exist = data.find(x => { return !x.audit_group || !x.audit_group_order; });
  1123. if (exist) {
  1124. toastr.error('分组审批时,分组/部门、顺序均不可为空');
  1125. return;
  1126. }
  1127. } else if (self.audit_type === auditType.key.or) {
  1128. for (const d of data) {
  1129. if (!d.audit_group_need) {
  1130. toastr.error('或签必须设置最少审批人数');
  1131. return;
  1132. }
  1133. if (d.audit_group_need < 1 || d.audit_group_need >= data.length) {
  1134. toastr.error('最少审批人数必须大于0,小于审批人数');
  1135. return;
  1136. }
  1137. }
  1138. }
  1139. postData(`/tender/${cur_tenderid}/shenpi/multi/save`, data, function(result) {
  1140. const flow = sp_lc.find(x => { return x.code === self.sp_type; });
  1141. const multiData = flow.auditGroupList.find(x => { return x[0].audit_order == self.audit_order});
  1142. for (const d of result) {
  1143. const md = multiData.find(x => { return x.id === d.id; });
  1144. if (!md) continue;
  1145. for (const prop in d) {
  1146. md[prop] = d[prop];
  1147. }
  1148. }
  1149. multiData.sort((a, b) => {
  1150. if (a.audit_group === b.audit_group) {
  1151. return a.audit_group_order - b.audit_group_order;
  1152. } else {
  1153. return a.audit_group === b.audit_group ? 0 : (a.audit_group < b.audit_group ? -1 : 1)
  1154. }
  1155. });
  1156. $('#multi').modal('hide');
  1157. $(self.multiBtn).parent().parent().html(auditUtils.getAuditGroupInnerHtml(self.sp_type, multiData, self.audit_order));
  1158. });
  1159. });
  1160. }
  1161. loadData(audit_type, sp_type, audit_order, multiBtn) {
  1162. this.audit_type = audit_type;
  1163. if (this.audit_type === auditType.key.multi) {
  1164. $('#multi-title').html('分组审批');
  1165. } else if (this.audit_type === auditType.key.and) {
  1166. $('#multi-title').html('会签设置');
  1167. } else if (this.audit_type === auditType.key.or) {
  1168. $('#multi-title').html('或签设置');
  1169. }
  1170. $('[name=set-hint]').hide();
  1171. $(`[name=set-hint][htype=${audit_type}]`).show();
  1172. this.multiBtn = multiBtn;
  1173. this.sp_type = sp_type;
  1174. this.audit_order = audit_order;
  1175. const flow = sp_lc.find(x => { return x.code === sp_type; });
  1176. const multiData = flow.auditGroupList.find(x => { return x[0].audit_order == audit_order});
  1177. this.data = JSON.parse(JSON.stringify(multiData));
  1178. const typeNeedCol = [
  1179. { key: auditType.key.multi, cols: ['name', 'audit_group', 'audit_group_limit', 'audit_group_order', 'audit_checkno_valid'] },
  1180. { key: auditType.key.and, cols: ['name', 'audit_group_order', 'audit_checkno_valid'] },
  1181. { key: auditType.key.or, cols: ['name', 'audit_group_need'] },
  1182. ];
  1183. const needCol = typeNeedCol.find(x => { return x.key === this.audit_type; });
  1184. this.sheet.zh_setting.cols.forEach(c => {
  1185. c.visible = needCol.cols.indexOf(c.field) >= 0;
  1186. });
  1187. SpreadJsObj.refreshColumnVisible(this.sheet);
  1188. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.data);
  1189. $('#multi').modal('show');
  1190. }
  1191. getAuditData() {
  1192. const sheet = this.sheet;
  1193. const col = { group: 1, order: 2, limit: 3, checkno: 4, need: 5, };
  1194. const updateData = this.data.map((x, i) => {
  1195. const data = { id: x.id };
  1196. data.audit_group = this.audit_type === auditType.key.multi ? sheet.getText(i, col.group) : '';
  1197. const order = sheet.getText(i, col.order);
  1198. data.audit_group_order = order ? _.parseInt(order) || 0 : 0;
  1199. data.audit_group_limit = this.audit_type === auditType.key.multi ? (sheet.getValue(i, col.limit) ? 1 : 0) : 0;
  1200. data.audit_checkno_valid = sheet.getValue(i, col.checkno) ? 1 : 0;
  1201. const need = sheet.getText(i, col.need);
  1202. data.audit_group_need = this.audit_type === auditType.key.or ? (need ? _.parseInt(need) || 1 : 1) : 1;
  1203. return data;
  1204. });
  1205. return updateData;
  1206. }
  1207. }
  1208. const auditMulti = new AuditMulti();
  1209. $('body').on('click', '[name=multi-set]', function() {
  1210. auditMulti.loadData(auditType.key.multi, this.getAttribute('sp_type'), this.getAttribute('audit_order'), this);
  1211. });
  1212. $('body').on('click', '[name=and-set]', function() {
  1213. auditMulti.loadData(auditType.key.and, this.getAttribute('sp_type'), this.getAttribute('audit_order'), this);
  1214. });
  1215. $('body').on('click', '[name=or-set]', function() {
  1216. auditMulti.loadData(auditType.key.or, this.getAttribute('sp_type'), this.getAttribute('audit_order'), this);
  1217. });
  1218. $.subMenu({
  1219. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1220. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1221. key: 'menu.1.0.0',
  1222. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1223. callback: function (info) {
  1224. if (info.mini) {
  1225. $('.panel-title').addClass('fluid');
  1226. $('#sub-menu').removeClass('panel-sidebar');
  1227. } else {
  1228. $('.panel-title').removeClass('fluid');
  1229. $('#sub-menu').addClass('panel-sidebar');
  1230. }
  1231. autoFlashHeight();
  1232. }
  1233. });
  1234. let timer2 = null;
  1235. let oldSearchVal2 = null;
  1236. $('body').on('input propertychange', '#batch input[name="audit-name"]', function(e) {
  1237. oldSearchVal2 = e.target.value;
  1238. timer2 && clearTimeout(timer2);
  1239. timer2 = setTimeout(() => {
  1240. const newVal = $(this).val();
  1241. const resultLength = $('#tender-list').find('.result').length;
  1242. if (resultLength > 0) {
  1243. let content = $('#tender-list').html();
  1244. const replaceStr = $('#tender-list').find('.result').eq(0).html();
  1245. const regExp2 = new RegExp('<span class="result" style="background: yellow;">' + replaceStr + '</span>', 'g');
  1246. content = content.replace(regExp2, replaceStr);
  1247. const regExp3 = new RegExp('<span class="result" style="background: orange;">' + replaceStr + '</span>', 'g');
  1248. content = content.replace(regExp3, replaceStr);
  1249. $('#tender-list').html(content);
  1250. }
  1251. $('#search-result').text('0/0');
  1252. $('#up-search').attr('disabled', true);
  1253. $('#down-search').attr('disabled', true);
  1254. if (newVal && newVal === oldSearchVal2) {
  1255. const regExp = new RegExp(newVal, 'g');
  1256. for (let i = 0; i < $('#tender-list tr').length; i++) {
  1257. if (_.includes($('#tender-list tr').eq(i).children('td').eq(2).html(), newVal)) {
  1258. $('#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>'))
  1259. }
  1260. }
  1261. const resultLength2 = $('#tender-list').find('.result').length;
  1262. if (resultLength2 > 0) {
  1263. $('#tender-list').find('.result').eq(0).css('background', 'orange');
  1264. $('#search-result').text('1/' + resultLength2);
  1265. $('#up-search').attr('disabled', false);
  1266. $('#down-search').attr('disabled', false);
  1267. }
  1268. }
  1269. if($('#tender-list').find('.result').length > 0) {
  1270. const X = $('#tender-list').find('.result').eq(0).offset().top;
  1271. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  1272. }
  1273. }, 400);
  1274. });
  1275. $('#up-search').on('click', function () {
  1276. const cur = parseInt($('#search-result').text().split('/')[0]);
  1277. const total = parseInt($('#search-result').text().split('/')[1]);
  1278. const now = cur - 1 !== 0 ? cur - 1: total;
  1279. $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  1280. $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  1281. // $('#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;">'))
  1282. // $('#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;">'))
  1283. $('#search-result').text(now + '/' + total);
  1284. const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  1285. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  1286. });
  1287. $('#down-search').on('click', function () {
  1288. const cur = parseInt($('#search-result').text().split('/')[0]);
  1289. const total = parseInt($('#search-result').text().split('/')[1]);
  1290. const now = cur + 1 > total ? 1: cur + 1;
  1291. $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  1292. $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  1293. // $('#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;">'))
  1294. // $('#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;">'))
  1295. $('#search-result').text(now + '/' + total);
  1296. const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  1297. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() -30);
  1298. });
  1299. // 审批组
  1300. $('body').on('click', '.show-spzsave', function () {
  1301. const this_code = $(this).attr('data-code');
  1302. const groupId = $(this).attr('data-group') || null;
  1303. const flow = sp_lc.find(x => { return x.code === this_code; });
  1304. $('#save-code').val(this_code);
  1305. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1306. if (group) {
  1307. $('#save-group-id').val(group.id);
  1308. $('#spzsave input[name="group_name"]').val(group.name);
  1309. $('#show-delete-group-btn').show();
  1310. } else {
  1311. $('#save-group-id').val('');
  1312. $('#spzsave input[name="group_name"]').val('');
  1313. $('#show-delete-group-btn').hide();
  1314. }
  1315. if (this_code === 'change') {
  1316. if (group) {
  1317. $('#show-change-type input').each(function () {
  1318. if (group.change_type[$(this).data('type')]) {
  1319. $(this).prop('checked', true);
  1320. } else {
  1321. $(this).prop('checked', false);
  1322. }
  1323. });
  1324. } else {
  1325. $('#show-change-type input').each(function () {
  1326. $(this).prop('checked', false);
  1327. });
  1328. $('#show-change-type input[data-type="change"]').prop('checked', true);
  1329. }
  1330. $('#show-contract-type input').attr('disabled', true);
  1331. $('#show-contract-type').hide();
  1332. $('#show-change-type input').removeAttr('disabled');
  1333. $('#show-change-type').show();
  1334. } else if (this_code === 'contract') {
  1335. if (group) {
  1336. $('#show-contract-type input').each(function () {
  1337. if (group.change_type[$(this).data('type')]) {
  1338. $(this).prop('checked', true);
  1339. } else {
  1340. $(this).prop('checked', false);
  1341. }
  1342. });
  1343. } else {
  1344. $('#show-contract-type input').each(function () {
  1345. $(this).prop('checked', false);
  1346. });
  1347. $('#show-contract-type input[data-type="contract"]').prop('checked', true);
  1348. }
  1349. $('#show-change-type input').attr('disabled', true);
  1350. $('#show-change-type').hide();
  1351. $('#show-contract-type input').removeAttr('disabled');
  1352. $('#show-contract-type').show();
  1353. } else {
  1354. $('#show-change-type input').attr('disabled', true);
  1355. $('#show-change-type').hide();
  1356. $('#show-contract-type input').attr('disabled', true);
  1357. $('#show-contract-type').hide();
  1358. }
  1359. $('#spzsave').modal('show');
  1360. });
  1361. $('#save-group-btn').click(function () {
  1362. const name = _.trim($('#spzsave input[name="group_name"]').val());
  1363. if (!name) {
  1364. toastr.error('审批组名称不能为空');
  1365. return false;
  1366. }
  1367. if (name.length > 50) {
  1368. toastr.error('审批组名称不能超过50个字符');
  1369. return false;
  1370. }
  1371. const code = $('#save-code').val();
  1372. const prop = {
  1373. type: 'save-group',
  1374. name,
  1375. code,
  1376. }
  1377. const groupId = $('#save-group-id').val();
  1378. const flow = sp_lc.find(x => { return x.code === code; });
  1379. if (flow.groupList && flow.groupList.length >= 0 && _.findIndex(flow.groupList, function (item) {
  1380. return item.name === name && item.id !== parseInt(groupId);
  1381. }) !== -1) {
  1382. toastr.error('审批组名称已存在, 请更改名称');
  1383. return false;
  1384. }
  1385. if (groupId) {
  1386. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1387. if (!group) {
  1388. toastr.error('审批组不存在');
  1389. return false;
  1390. }
  1391. prop.groupId = group.id;
  1392. }
  1393. if (code === 'change') {
  1394. const change_type = {};
  1395. let change_flag = false;
  1396. $('#show-change-type input').each(function () {
  1397. change_type[$(this).data('type')] = $(this).prop('checked');
  1398. if ($(this).prop('checked')) {
  1399. change_flag = true;
  1400. }
  1401. });
  1402. if (!change_flag) {
  1403. toastr.error('请至少选择一种变更显示模块');
  1404. return false;
  1405. }
  1406. prop.change_type = change_type;
  1407. } else if (code === 'contract') {
  1408. const change_type = {};
  1409. let contract_flag = false;
  1410. $('#show-contract-type input').each(function () {
  1411. change_type[$(this).data('type')] = $(this).prop('checked');
  1412. if ($(this).prop('checked')) {
  1413. contract_flag = true;
  1414. }
  1415. });
  1416. if (!contract_flag) {
  1417. toastr.error('请至少选择一种合同显示模块');
  1418. return false;
  1419. }
  1420. prop.change_type = change_type;
  1421. }
  1422. console.log(prop);
  1423. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  1424. flow.auditGroupList = data.group.auditGroupList || [];
  1425. if (groupId) {
  1426. const index = flow.groupList.findIndex(x => { return x.id === parseInt(groupId); });
  1427. flow.groupList[index] = data.group;
  1428. } else {
  1429. if (!flow.groupList) flow.groupList = [];
  1430. for (const g of flow.groupList) {
  1431. g.is_select = 0;
  1432. }
  1433. flow.groupList.push(data.group);
  1434. }
  1435. // 配置页面
  1436. let addhtml = auditUtils.getGroupHtml(flow, code);
  1437. addhtml += '<ul class="list-unstyled">\n';
  1438. addhtml += auditUtils.getgdsplHtml(flow, code);
  1439. addhtml += '</ul>\n';
  1440. $('.' + code + '_div').children('.lc-show').html(addhtml);
  1441. $('#spzsave').modal('hide');
  1442. });
  1443. });
  1444. // 切换审批组
  1445. $('body').on('change', '.group-list', function () {
  1446. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  1447. const flow = sp_lc.find(x => { return x.code === this_code; });
  1448. const groupId = parseInt($(this).val());
  1449. const _self = $(this);
  1450. const prop = {
  1451. type: 'change-group',
  1452. groupId,
  1453. }
  1454. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  1455. flow.groupList.forEach(function (item) {
  1456. item.is_select = 0;
  1457. });
  1458. const group = flow.groupList.find(x => { return x.id === groupId; });
  1459. group.is_select = 1;
  1460. flow.auditGroupList = group.auditGroupList;
  1461. const addhtml = auditUtils.getgdsplHtml(flow, this_code);
  1462. _self.parents('.lc-show').children('ul').html(addhtml);
  1463. _self.parents('.lc-show').find('.edit-spzsave').attr('data-group', groupId);
  1464. });
  1465. });
  1466. $('#show-delete-group-btn').click(function () {
  1467. const code = $('#save-code').val();
  1468. const groupId = $('#save-group-id').val();
  1469. const flow = sp_lc.find(x => { return x.code === code; });
  1470. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1471. if (!group) {
  1472. toastr.error('该审批组不存在');
  1473. return false;
  1474. }
  1475. $('#delete-group-name').text(group.name);
  1476. $('#delete-group-id').val(group.id);
  1477. $('#delete-code').val(code);
  1478. $('#spzsave').modal('hide');
  1479. $('#spzdelete').modal('show');
  1480. });
  1481. $('#delete-group-btn').click(function () {
  1482. const code = $('#delete-code').val();
  1483. const groupId = $('#delete-group-id').val();
  1484. const flow = sp_lc.find(x => { return x.code === code; });
  1485. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1486. if (!group) {
  1487. toastr.error('该审批组不存在');
  1488. return false;
  1489. }
  1490. const prop = {
  1491. type: 'delete-group',
  1492. groupId: group.id,
  1493. }
  1494. console.log(prop);
  1495. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  1496. // const flow = findSplc(code);
  1497. const index = flow.groupList.findIndex(x => { return x.id === group.id; });
  1498. flow.groupList.splice(index, 1);
  1499. flow.auditGroupList = flow.groupList.length > 0 ? flow.groupList[0].auditGroupList : [];
  1500. if (flow.groupList.length > 0) flow.groupList[0].is_select = 1;
  1501. // 配置页面
  1502. let addhtml = auditUtils.getGroupHtml(flow, code);
  1503. addhtml += '<ul class="list-unstyled">\n';
  1504. addhtml += auditUtils.getgdsplHtml(flow, code);
  1505. addhtml += '</ul>\n';
  1506. $('.' + code + '_div').children('.lc-show').html(addhtml);
  1507. $('#spzdelete').modal('hide');
  1508. });
  1509. });
  1510. });
  1511. // 审批流程-审批人html 生成
  1512. function makeAudit(audit, i = '终') {
  1513. return '<li class="d-flex justify-content-start mb-3">\n' +
  1514. ' <span class="col-auto">'+ i +'审</span>\n' +
  1515. ' <span class="col-7 spr-span">\n' +
  1516. ' <span class="d-inline-block"></span>\n' +
  1517. ' <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  1518. ' <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' +
  1519. ' <div class="dropdown-menu">\n' +
  1520. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  1521. ' <div class="dropdown-divider"></div>\n' +
  1522. ' <div class="px-2 py-1 text-center">\n' +
  1523. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  1524. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  1525. ' </div>\n' +
  1526. ' </div>\n' +
  1527. ' </span> ' +
  1528. // '<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' +
  1529. ' </span></span></span>\n' +
  1530. ' </li>';
  1531. }
  1532. // 审批流程-选择审批人html 生成
  1533. function makeSelectAudit(code, i = '终') {
  1534. let divhtml = '';
  1535. accountGroup.forEach((group, idx) => {
  1536. let didivhtml = '';
  1537. if(group) {
  1538. group.groupList.forEach(item => {
  1539. 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' +
  1540. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  1541. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  1542. ' <span class="text-muted">' + item.role + '</span>\n' +
  1543. ' </dd>\n' : '';
  1544. });
  1545. 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' +
  1546. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  1547. ' </div>\n';
  1548. }
  1549. });
  1550. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  1551. ' <span class="col-auto">' + i + '审</span>\n' +
  1552. ' <span class="col-7 spr-span">\n' +
  1553. ' <span class="d-inline-block">\n' +
  1554. ' <div class="dropdown text-right">\n' +
  1555. ' <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' +
  1556. ' 选择审批人\n' +
  1557. ' </button>\n' +
  1558. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  1559. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  1560. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  1561. ' <dl class="list-unstyled book-list">\n' + divhtml +
  1562. ' </dl>\n' +
  1563. ' </div>\n' +
  1564. ' </div>\n' +
  1565. ' </span>\n' +
  1566. ' </span>\n' +
  1567. ' </li>';
  1568. return html;
  1569. }