shenpi.js 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  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'];
  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. 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. 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.union && auditGroup.length > 0) {
  304. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="union-set">协同设置</button>`);
  305. }
  306. html.push('</span>');
  307. return html.join('');
  308. },
  309. getAuditGroupHtml: function (code, auditGroup, i) {
  310. return `<li class="d-flex justify-content-start align-items-center mb-3">${this.getAuditGroupInnerHtml(code, auditGroup, i)}</li>`;
  311. },
  312. getFinalAuditHtml: function (audit) {
  313. const html = [];
  314. html.push('<li class="d-flex justify-content-start mb-3"><span class="col-auto">终审</span><span class="col-7 spr-span">');
  315. html.push(this.getAuditHtml(audit));
  316. html.push('</span></span></li>');
  317. return html.join('');
  318. },
  319. getGroupHtml: function (flow, this_code) {
  320. let html = '';
  321. if (flow && flow.groupList && flow.groupList.length > 0) {
  322. let groupSelectHtml = '';
  323. for (const group of flow.groupList) {
  324. groupSelectHtml += `<option value="${group.id}" ${group.is_select === 1 ? 'selected' : ''}>${group.name}</option>`;
  325. }
  326. const selectGroup = flow.groupList.find(x => { return x.is_select === 1 });
  327. html += '<div class="d-flex justify-content-start align-items-center mb-3">\n' +
  328. ' <span class="col-auto">当前审批组:</span>\n' +
  329. ' <span style="width: 200px;">\n' +
  330. ' <select class="form-control form-control-sm group-list">\n' +
  331. groupSelectHtml +
  332. ' </select>\n' +
  333. ' </span>\n' +
  334. ` <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` +
  335. ` <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` +
  336. ' </div>';
  337. }
  338. return html;
  339. },
  340. getgdsplHtml(flow, this_code) {
  341. let addhtml = '';
  342. if (flow.auditGroupList.length !== 0) {
  343. for(const [i, auditGroup] of flow.auditGroupList.entries()) {
  344. addhtml += this.getAuditGroupHtml(this_code, auditGroup, i + 1);
  345. }
  346. const addGroupHtml = this_code === 'change' && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
  347. `<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` : '';
  348. addhtml += '<li>\n' +
  349. ' <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>\n' + addGroupHtml +
  350. ' </li>';
  351. } else {
  352. addhtml += this.getAuditGroupHtml(this_code, [], 1);
  353. }
  354. return addhtml;
  355. },
  356. // 以下i从0开始
  357. addAudit: function (code, user, i) {
  358. const flow = sp_lc.find(x => { return x.code === code });
  359. if (!flow.auditGroupList) flow.auditGroupList = [];
  360. if (!flow.auditGroupList[i]) flow.auditGroupList[i] = [];
  361. flow.auditGroupList[i].push(user);
  362. return flow.auditGroupList[i];
  363. },
  364. removeAudit: function (code, audit_id, i) {
  365. const flow = sp_lc.find(x => { return x.code === code });
  366. if (flow.auditGroupList[i].length === 1) {
  367. flow.auditGroupList.splice(i, 1);
  368. return null;
  369. }
  370. flow.auditGroupList[i].splice(flow.auditGroupList[i].findIndex(x => { return x.audit_id === audit_id; }), 1);
  371. return flow.auditGroupList[i];
  372. },
  373. setAuditType: function (code, audit_type, i) {
  374. const flow = sp_lc.find(x => { return x.code === code });
  375. if (!flow || !flow.auditGroupList || !flow.auditGroupList[i]) return;
  376. flow.auditGroupList[i].forEach(x => { x.audit_type = audit_type});
  377. return flow.auditGroupList[i];
  378. }
  379. };
  380. let timer = null;
  381. let oldSearchVal = null;
  382. $('body').on('input propertychange', 'div[id$="_dropdownMenu"] .gr-search', function(e) {
  383. oldSearchVal = e.target.value;
  384. timer && clearTimeout(timer);
  385. timer = setTimeout(() => {
  386. const newVal = $(this).val();
  387. const code = $(this).attr('data-code');
  388. let html = '';
  389. if (newVal && newVal === oldSearchVal) {
  390. 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 => {
  391. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  392. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  393. class="ml-auto">${item.mobile || ''}</span></p>
  394. <span class="text-muted">${item.role || ''}</span>
  395. </dd>`
  396. });
  397. $('#' + code + '_dropdownMenu .book-list').empty();
  398. $('#' + code + '_dropdownMenu .book-list').append(html);
  399. } else {
  400. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  401. accountGroup.forEach((group, idx) => {
  402. if (!group) return;
  403. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  404. </a> ${group.groupName}</dt>
  405. <div class="dd-content" data-toggleid="${idx}">`;
  406. group.groupList.forEach(item => {
  407. if ((item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1))) {
  408. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  409. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  410. class="ml-auto">${item.mobile || ''}</span></p>
  411. <span class="text-muted">${item.role || ''}</span>
  412. </dd>`;
  413. }
  414. });
  415. html += '</div>';
  416. });
  417. $('#' + code + '_dropdownMenu .book-list').empty();
  418. $('#' + code + '_dropdownMenu .book-list').append(html);
  419. }
  420. }
  421. }, 400);
  422. });
  423. // 添加审批流程按钮逻辑
  424. $('body').on('click', 'div[id$="_dropdownMenu"] .book-list dt', function () {
  425. const idx = $(this).find('.acc-btn').attr('data-groupid');
  426. const type = $(this).find('.acc-btn').attr('data-type');
  427. if (type === 'hide') {
  428. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  429. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  430. $(this).find('.acc-btn').attr('data-type', 'show');
  431. })
  432. } else {
  433. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  434. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  435. $(this).find('.acc-btn').attr('data-type', 'hide');
  436. })
  437. }
  438. return false;
  439. });
  440. // 更改审批流程状态
  441. $('body').on('change', '.form-check input[type="radio"]', function () {
  442. // 获取所有审批的checked值并更新
  443. const this_status = parseInt($(this).val());
  444. const this_code = $(this).data('code');
  445. const spt = sp_status_list[this_status];
  446. $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
  447. // 拼接post json
  448. const prop = {
  449. code: this_code,
  450. status: this_status
  451. };
  452. const _self = $(this);
  453. postData('/tender/' + cur_tenderid + '/shenpi/save', prop, function (data) {
  454. if (this_status === sp_status.sqspr) {
  455. _self.parents('.form-group').siblings('.lc-show').html('');
  456. } else if (this_status === sp_status.gdspl) {
  457. const flow = sp_lc.find(x => { return x.code === this_code; });
  458. flow.auditGroupList = data.auditList;
  459. flow.groupList = data.groupList;
  460. let addhtml = auditUtils.getGroupHtml(flow, this_code);
  461. addhtml += '<ul class="list-unstyled">\n';
  462. addhtml += auditUtils.getgdsplHtml(flow, this_code);
  463. addhtml += '</ul>\n';
  464. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  465. } else if (this_status === sp_status.gdzs) {
  466. let addhtml = '<ul class="list-unstyled">\n' +
  467. ' <li class="d-flex justify-content-start mb-3">\n' +
  468. ' <span class="col-auto">授权审批人</span>\n' +
  469. ' <span class="col-7">\n' +
  470. ' <span class="d-inline-block"></span>\n' +
  471. ' </span>\n' +
  472. ' </li>\n';
  473. addhtml += data.auditList ? makeAudit(data.auditList) : makeSelectAudit(this_code);
  474. addhtml += '</ul>\n';
  475. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  476. }
  477. if(this_code === 'stage') {
  478. if(this_status === sp_status.gdspl) {
  479. $('#stage_cooperation').show();
  480. } else {
  481. $('#stage_cooperation').hide();
  482. }
  483. }
  484. });
  485. });
  486. // 选中审批人
  487. $('body').on('click', 'div[id$="_dropdownMenu"] dl dd', function () {
  488. const id = parseInt($(this).data('id'));
  489. if (!id) return;
  490. let this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  491. if (!this_code) this_code = $(this).parents('.dropdown').data('code');
  492. const user = _.find(accountList, function (item) {
  493. return item.id === id;
  494. });
  495. if (this_code === 'audit-ass') {
  496. auditAss.setAuditAssist(user);
  497. } else {
  498. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  499. if (this_status === sp_status.gdspl) {
  500. // 判断是否已存在审批人
  501. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  502. for (let i = 0; i < aid_num; i++) {
  503. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  504. if (aid === id) {
  505. toastr.warning('该审核人已存在,请勿重复添加');
  506. return;
  507. }
  508. }
  509. }
  510. const prop = {
  511. status: this_status,
  512. code: sp_type[this_code],
  513. audit_id: id,
  514. type: 'add',
  515. };
  516. if (this_status === sp_status.gdspl) {
  517. prop.audit_type = parseInt($(this).parents('li').find('select[class*="audit-type-key"]')[0].value);
  518. prop.audit_order = $(this).parents('li').index() + 1;
  519. }
  520. const _self = $(this);
  521. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  522. if (this_status === sp_status.gdspl) {
  523. const auditGroup = auditUtils.addAudit(this_code, { audit_id: data.audit_id, name: user.name, audit_type: data.audit_type, audit_order: data.audit_order }, prop.audit_order - 1);
  524. if (_self.parents('ul').find('.add-audit').length === 0) {
  525. const flow = sp_lc.find(x => { return x.code === this_code; });
  526. const addGroupHtml = this_code === 'change' && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
  527. `<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` : '';
  528. _self.parents('ul').append('<li>\n' +
  529. ' <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>\n' + addGroupHtml +
  530. ' </li>');
  531. }
  532. _self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, prop.audit_order));
  533. } else {
  534. _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  535. '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <span class="dropdown">\n' +
  536. ' <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' +
  537. ' <div class="dropdown-menu">\n' +
  538. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  539. ' <div class="dropdown-divider"></div>\n' +
  540. ' <div class="px-2 py-1 text-center">\n' +
  541. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + user.id + '">移除</button>\n' +
  542. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  543. ' </div>\n' +
  544. ' </div>\n' +
  545. ' </span> ' +
  546. ' </span></span></span>\n');
  547. }
  548. });
  549. }
  550. });
  551. // 移除审批人
  552. $('body').on('click', '.remove-audit', function () {
  553. const id = parseInt($(this).data('id'));
  554. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  555. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  556. const prop = {
  557. status: this_status,
  558. code: sp_type[this_code],
  559. audit_id: id,
  560. type: 'del',
  561. };
  562. const _self = $(this);
  563. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  564. if (this_status === sp_status.gdspl) {
  565. const index = _self.parents('li').index();
  566. const auditGroup = auditUtils.removeAudit(this_code, id, index);
  567. if (auditGroup) {
  568. _self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, index + 1));
  569. } else {
  570. const _selflc = _self.parents('.lc-show');
  571. _self.parents('li').remove();
  572. const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
  573. if (aid_num === 0) {
  574. _selflc.children('ul').html(auditUtils.getAuditGroupHtml(this_code, [], 1));
  575. } else {
  576. for (let i = 0; i < aid_num; i++) {
  577. _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  578. }
  579. }
  580. }
  581. } else if (this_status === sp_status.gdzs) {
  582. let addhtml = '<ul class="list-unstyled">\n' +
  583. ' <li class="d-flex justify-content-start mb-3">\n' +
  584. ' <span class="col-auto">授权审批人</span>\n' +
  585. ' <span class="col-7">\n' +
  586. ' <span class="d-inline-block"></span>\n' +
  587. ' </span>\n' +
  588. ' </li>\n';
  589. addhtml += makeSelectAudit(this_code);
  590. addhtml += '</ul>\n';
  591. _self.parents('.lc-show').html(addhtml);
  592. }
  593. })
  594. });
  595. // 固定审批流-添加流程
  596. $('body').on('click', '.add-audit', function () {
  597. const num = $(this).parents('ul').children('li').length;
  598. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  599. //const addhtml = makeSelectAudit(this_code, transFormToChinese(num));
  600. const addhtml = auditUtils.getAuditGroupHtml(this_code, [], num);
  601. $(this).parents('ul').append(addhtml);
  602. $(this).parents('li').remove();
  603. });
  604. sortCategory2();
  605. initTenderTree2();
  606. $('body').on('click', '.set-otherTender', function () {
  607. const this_code = $(this).data('code');
  608. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  609. const lis = $(this).siblings('.lc-show').find('li');
  610. const auditList = [], aidList = [];
  611. lis.each((i, li) => {
  612. const removes = $(li).find('.remove-audit');
  613. if (removes.length === 0) return;
  614. const select = $(li).find('select[class*="audit-type-key"]');
  615. const audit_type = select.length > 0 ? parseInt(select.val()) : 1;
  616. for (const remove of removes) {
  617. auditList.push({ audit_id: parseInt(remove.getAttribute('data-id')), audit_type, audit_order: i + 1 });
  618. aidList.push(parseInt(remove.getAttribute('data-id')));
  619. }
  620. });
  621. const html = getTenderTreeHtml2(this_code, this_status, aidList);
  622. $('#shenpi-name').text($(this).data('name'));
  623. $('#shenpi_code').val(this_code);
  624. $('#shenpi_status').val(this_status);
  625. $('#shenpi_auditors').val(JSON.stringify(auditList));
  626. $('#tender-list').html(html);
  627. $('#search-audit').val('');
  628. $('#search-result').text('0/0');
  629. $('#up-search').attr('disabled', true);
  630. $('#down-search').attr('disabled', true);
  631. setTimeout(function () { $("#tender-list [data-toggle='tooltip']").tooltip(); },800);
  632. });
  633. $('#save-other-tender').click(function () {
  634. $(this).attr('disabled', true);
  635. const num = $('#tender-list input:checked').length;
  636. if (num < 2) {
  637. toastr.warning('请选择需要设置审批同步的标段');
  638. $(this).removeAttr('disabled');
  639. return;
  640. }
  641. const data = {
  642. type: 'copy2ot',
  643. status: parseInt($('#shenpi_status').val()),
  644. code: $('#shenpi_code').val(),
  645. };
  646. if(data.status !== shenpi_status.gdspl) {
  647. data.auditList = JSON.parse($('#shenpi_auditors').val());
  648. }
  649. // 获取已选中的标段
  650. const tenderList = [];
  651. for (let i = 0; i < num; i++) {
  652. const tid = parseInt($('#tender-list input:checked').eq(i).data('tid'));
  653. if (tid !== cur_tenderid) {
  654. tenderList.push(tid);
  655. }
  656. }
  657. data.tidList = tenderList.join(',');
  658. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
  659. toastr.success('设置成功');
  660. setTimeout(function () {
  661. window.location.reload();
  662. }, 1000)
  663. })
  664. });
  665. $('body').on('click', '.set-otherShenpi', function () {
  666. let canSetOther = true;
  667. const this_code = $(this).data('code');
  668. // if (['stage', 'change'].indexOf(this_code) !== -1) {
  669. // const select = $(this).siblings('.lc-show').find('select[class*="audit-type-key"]');
  670. // select.each((i, s) => {
  671. // if (s.value !== '1') canSetOther = false;
  672. // });
  673. // }
  674. // if (!canSetOther) {
  675. // toastr.warning('该流程含有会签或签,不可同步至其他流程');
  676. // $('#batch2').modal('hide');
  677. // return;
  678. // }
  679. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  680. const copyFlow = [];
  681. const flow = $('li.d-flex', $(this).siblings('.lc-show'));
  682. for (const f of flow) {
  683. const audit_type = $('select', f).val() || 1;
  684. const auditors = $('.remove-audit', f);
  685. if (auditors.length === 0) continue;
  686. const aid = [];
  687. for (const a of auditors) {
  688. aid.push(a.getAttribute('data-id'));
  689. }
  690. copyFlow.push(`${audit_type}:${aid.join(',')}`);
  691. }
  692. const html = getShenpiHtml(this_code);
  693. $('#shenpi-name2').text($(this).data('name'));
  694. $('#shenpi_code2').val(this_code);
  695. $('#shenpi_status2').val(this_status);
  696. $('#shenpi_auditors2').val(copyFlow.join(';'));
  697. $('#shenpi-list').html(html);
  698. setTimeout(function () { $("#shenpi-list [data-toggle='tooltip']").tooltip(); },800);
  699. $('#batch2').modal('show');
  700. });
  701. $('#save-other-shenpi').click(function () {
  702. $(this).attr('disabled', true);
  703. const num = $('#shenpi-list input:checked').length;
  704. if (num < 1) {
  705. toastr.warning('请选择需要设置审批同步的流程');
  706. $(this).removeAttr('disabled');
  707. return;
  708. }
  709. const data = {
  710. type: 'copy2os',
  711. status: parseInt($('#shenpi_status2').val()),
  712. code: $('#shenpi_code2').val(),
  713. };
  714. if(data.status !== shenpi_status.gdspl) {
  715. data.flowList = $('#shenpi_auditors2').val();
  716. }
  717. // 获取已选中的标段
  718. const shenpiList = [];
  719. for (let i = 0; i < num; i++) {
  720. const code = $('#shenpi-list input:checked').eq(i).data('code');
  721. shenpiList.push(code);
  722. }
  723. data.shenpiList = shenpiList.join(',');
  724. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
  725. toastr.success('设置成功');
  726. setTimeout(function () {
  727. window.location.reload();
  728. }, 1000)
  729. })
  730. });
  731. // 设置会签、或签
  732. $('body').on('change', 'select[class*="audit-type-key"]', function() {
  733. const removes = $(this).parents('.d-flex').find('.remove-audit');
  734. if (removes.length === 0) return;
  735. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  736. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  737. const ids = [];
  738. const liParent = $(this).parents('li');
  739. removes.each((i, r) => { ids.push(parseInt(r.getAttribute('data-id'))); });
  740. const prop = {
  741. status: this_status,
  742. code: sp_type[this_code],
  743. audit_id: ids,
  744. audit_type: parseInt(this.value),
  745. type: 'audit-type',
  746. };
  747. if (prop.audit_type === auditType.key.common && ids.length > 1) {
  748. toastr.warning('设置个人审批前请先删除多余的审批人');
  749. this.value = this.getAttribute('data-type');
  750. return;
  751. }
  752. const _self = this;
  753. postData('/tender/'+ cur_tenderid +'/shenpi/audit/save', prop, function () {
  754. _self.setAttribute('data-type', _self.value);
  755. const auditGroup = auditUtils.setAuditType(this_code, prop.audit_type, liParent.index());
  756. liParent.html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, liParent.index() + 1));
  757. });
  758. });
  759. class AuditAss {
  760. constructor() {
  761. this.spread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  762. this.sheet = this.spread.getActiveSheet();
  763. this.tree = createNewPathTree('base', {
  764. id: 'ledger_id',
  765. pid: 'ledger_pid',
  766. order: 'order',
  767. level: 'level',
  768. rootId: -1,
  769. });
  770. this.spreadSetting = {
  771. cols: [
  772. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 165, formatter: '@', cellType: 'tree'},
  773. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  774. {title: '协同人', colSpan: '1', rowSpan: '2', field: 'ass_name', hAlign: 1, width: 100, formatter: '@'},
  775. ],
  776. emptyRows: 0,
  777. headRows: 1,
  778. headRowHeight: [25, 25],
  779. defaultRowHeight: 21,
  780. headerFont: '12px 微软雅黑',
  781. font: '12px 微软雅黑',
  782. readOnly: true,
  783. localCache: {
  784. key: 'ledger-cooperation',
  785. colWidth: true,
  786. }
  787. };
  788. sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  789. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  790. const self = this;
  791. SpreadJsObj.addDeleteBind(this.spread, function() { return; });
  792. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  793. this.spread.bind(spreadNS.Events.SelectionChanged, function() {
  794. self.refreshOperate();
  795. });
  796. $('#stage_audits').change(function () {
  797. self.uid = $(this).val();
  798. });
  799. // 多人协同
  800. $('#cooperation').on('shown.bs.modal', function () {
  801. // 执行一些动作...
  802. // 更新新的多人协同表格信息
  803. const newUidList = [];
  804. $('.stage_div ul li').each(function (k, v) {
  805. const audit_type = parseInt($(v).find('select').val());
  806. if (audit_type !== auditType.key.common) return;
  807. const uid = $(v).find('button').eq(0).data('id');
  808. if(uid) newUidList.push({ order: k + 1, audit_id: uid });
  809. });
  810. const yb = _.find(accountList, { 'id': cur_uid });
  811. let newhtml = '<option value="' + yb.id + '">' + yb.name + '(原报)</option>';
  812. if(newUidList.length > 0) {
  813. for (const id of newUidList) {
  814. const audit = _.find(accountList, { 'id': id.audit_id });
  815. newhtml += '<option value="' + audit.id + '">' + audit.name + '(' + transFormToChinese(id.order) + '审)</option>';
  816. }
  817. }
  818. $('#stage_audits').html(newhtml);
  819. self.uid = cur_uid;
  820. self.initLedgerTree(cur_uid);
  821. });
  822. $('#del-audit-ass').click(function () {
  823. self.setAuditAssist();
  824. });
  825. $('body').on('click', 'button[asid]', function () {
  826. self.removeAuditAss(parseInt(this.getAttribute('asid')));
  827. });
  828. }
  829. set uid(id) {
  830. this._uid = parseInt(id);
  831. this._refreshAss();
  832. }
  833. get uid() {
  834. return this._uid;
  835. }
  836. _refreshAssTable(){
  837. $('#stage_audit').text($("#stage_audits option:selected").text());
  838. const html = [];
  839. for (const sa of this.showAssList) {
  840. const lid = sa.ass_ledger_id ? sa.ass_ledger_id.split(',') : [];
  841. 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>`);
  842. }
  843. $('#coo_table').html(html.join(''));
  844. }
  845. _refreshAssTree() {
  846. const ledgerAss = {};
  847. for (const sa of this.showAssList) {
  848. const ledger = sa.ass_ledger_id ? sa.ass_ledger_id.split(',') : [];
  849. ledger.forEach(l => { ledgerAss[l] = sa; });
  850. }
  851. for (const n of this.tree.nodes) {
  852. const la = ledgerAss[n.ledger_id];
  853. n.ass_audit_id = la ? la.ass_user_id : null;
  854. n.ass_name = la ? la.name : '';
  855. }
  856. SpreadJsObj.reloadColData(this.sheet, 2);
  857. }
  858. _refreshAss() {
  859. this.showAssList = _.filter(this.assList, { 'user_id': parseInt(this.uid) });
  860. this._refreshAssTable();
  861. this._refreshAssTree();
  862. }
  863. initLedgerTree(uid) {
  864. if (this.loaded) return;
  865. this.spread.refresh();
  866. const self = this;
  867. postData('/tender/' + cur_tenderid + '/shenpi/ass/load', {}, function (data) {
  868. self.loaded = true;
  869. self.assList = data.auditAssList;
  870. self.tree.loadDatas(data.ledgerList);
  871. SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
  872. self.uid = uid;
  873. self.refreshOperate();
  874. }, null, true);
  875. }
  876. loadPostData(data) {
  877. if (data.add) {
  878. this.assList.push(data.add);
  879. }
  880. if (data.del) {
  881. this.assList.splice(this.assList.findIndex(x => { return x.id === data.del.id }), 1);
  882. }
  883. if (data.update) {
  884. for (const d of data.update) {
  885. const od = this.assList.find(x => { return x.id === d.id });
  886. if (!od) continue;
  887. od.ass_ledger_id = d.ass_ledger_id;
  888. }
  889. }
  890. this._refreshAss();
  891. }
  892. setAuditAssist(assist){
  893. const node = SpreadJsObj.getSelectObject(this.sheet);
  894. if (assist && node.ass_audit_id === assist.id) return;
  895. if (assist && assist.id === this.uid) {
  896. toastr.warning('请勿添加本人');
  897. return;
  898. }
  899. const self = this;
  900. const data = { type: 'audit-ass'};
  901. if (assist) {
  902. const newAss = this.showAssList.find(x => { return x.ass_user_id === assist.id; });
  903. if (!newAss) {
  904. 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 + '' };
  905. } else {
  906. data.update = [{ id: newAss.id, ass_ledger_id: newAss.ass_ledger_id + ',' + node.ledger_id}];
  907. }
  908. }
  909. if (node.ass_audit_id) {
  910. const orgAss = this.showAssList.find(x => { return x.ass_user_id === node.ass_audit_id; });
  911. const rela_lid = orgAss.ass_ledger_id ? orgAss.ass_ledger_id.split(',') : [];
  912. rela_lid.splice(rela_lid.indexOf(node.ledger_id + ''), 1);
  913. if (rela_lid.length === 0) {
  914. data.del = { id: orgAss.id };
  915. } else {
  916. if (!data.update) data.update = [];
  917. data.update.push({ id: orgAss.id, ass_ledger_id: rela_lid.join(',')});
  918. }
  919. }
  920. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function (result) {
  921. self.loadPostData(result);
  922. self.refreshOperate();
  923. });
  924. }
  925. removeAuditAss(assistId) {
  926. const self = this;
  927. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', { type: 'audit-ass', del: { id: assistId } }, function (result) {
  928. self.loadPostData(result);
  929. self.refreshOperate();
  930. });
  931. }
  932. refreshOperate() {
  933. const node = SpreadJsObj.getSelectObject(this.sheet);
  934. if (node && node.ass_audit_id) {
  935. $('#del-audit-ass').show();
  936. $('#audit-ass_dropdownMenuButton')[0].innerHTML = '替换协同人';
  937. } else {
  938. $('#del-audit-ass').hide();
  939. $('#audit-ass_dropdownMenuButton')[0].innerHTML = '添加协同人';
  940. }
  941. }
  942. }
  943. const auditAss = new AuditAss();
  944. class AuditUnion {
  945. constructor() {
  946. this.spread = SpreadJsObj.createNewSpread($('#union-spread')[0]);
  947. this.sheet = this.spread.getActiveSheet();
  948. this.tree = createNewPathTree('base', {
  949. id: 'ledger_id',
  950. pid: 'ledger_pid',
  951. order: 'order',
  952. level: 'level',
  953. rootId: -1,
  954. });
  955. this.selectUnion = [{ value: 0, text: '' }];
  956. this.spreadSetting = {
  957. cols: [
  958. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 165, formatter: '@', cellType: 'tree', readOnly: true },
  959. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 185, formatter: '@', readOnly: true },
  960. {title: '协同人', colSpan: '1', rowSpan: '1', field: 'audit_id', hAlign: 1, width: 100, cellType: 'customizeCombo', comboItems: this.selectUnion },
  961. ],
  962. emptyRows: 0,
  963. headRows: 1,
  964. headRowHeight: [32],
  965. defaultRowHeight: 21,
  966. headerFont: '12px 微软雅黑',
  967. font: '12px 微软雅黑',
  968. };
  969. sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  970. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  971. const self = this;
  972. SpreadJsObj.addDeleteBind(this.spread, function() { return; });
  973. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  974. this.spread.bind(spreadNS.Events.EditEnded, function(e, info) {
  975. const node = SpreadJsObj.getSelectObject(info.sheet);
  976. if (!node) return;
  977. const refreshAuditId = [];
  978. if (node.audit_id) refreshAuditId.push(node.audit_id);
  979. const col = info.sheet.zh_setting.cols[info.col];
  980. node[col.field] = info.editingText;
  981. if (node.audit_id) refreshAuditId.push(node.audit_id);
  982. self.refreshUnionCount(refreshAuditId);
  983. });
  984. $('#union').on('shown.bs.modal', function() {
  985. self.spread.refresh();
  986. });
  987. $('#union-ok').click(function() {
  988. const data = self.getUnionAuditLedgerData();
  989. postData(`/tender/${cur_tenderid}/shenpi/union/save`, data, function(result) {
  990. $('#union').modal('hide');
  991. });
  992. });
  993. $('body').on('click', '[name=clear-union]', function() {
  994. const aid = parseInt(this.getAttribute('aid'));
  995. for (const node of self.tree.nodes) {
  996. if (node.audit_id === aid) node.audit_id = 0;
  997. }
  998. SpreadJsObj.reloadColData(self.sheet, 2);
  999. self.refreshUnionCount(aid);
  1000. });
  1001. }
  1002. _refreshUnionTree() {
  1003. const ledgerAss = {};
  1004. for (const a of this.auditors) {
  1005. a.lid.forEach(l => { ledgerAss[l] = a; });
  1006. }
  1007. for (const n of this.tree.nodes) {
  1008. const la = ledgerAss[n.ledger_id];
  1009. n.audit_id = la ? la.audit_id : 0;
  1010. n.audit_name = la ? la.name : '';
  1011. }
  1012. SpreadJsObj.reloadColData(this.sheet, 2);
  1013. }
  1014. setUnionAuditors(auditors) {
  1015. this.auditors = auditors;
  1016. this.selectUnion.length = 1;
  1017. const html = [];
  1018. for (const auditor of auditors) {
  1019. auditor.lid = auditor.audit_ledger_id ? auditor.audit_ledger_id.split(',') : [];
  1020. 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>`);
  1021. this.selectUnion.push({ value: auditor.audit_id, text: auditor.name });
  1022. }
  1023. $('#union_table').html(html.join(''));
  1024. this._refreshUnionTree();
  1025. }
  1026. refreshUnionCount(auditId) {
  1027. const auditIds = auditId instanceof Array ? auditId : [auditId];
  1028. for (const aid of auditIds) {
  1029. const unionNodes = this.tree.nodes.filter(x => { return x.audit_id === aid; });
  1030. $(`span[aid=${aid}]`).html(unionNodes.length);
  1031. }
  1032. }
  1033. loadUnionData(sp_type, audit_order) {
  1034. const data = { sp_type, audit_order };
  1035. if (!this.loaded) data.ledger = 1;
  1036. const self = this;
  1037. postData(`/tender/${cur_tenderid}/shenpi/union/load`, data, function(result) {
  1038. self.loaded = true;
  1039. if (result.ledgerList) {
  1040. self.tree.loadDatas(result.ledgerList);
  1041. SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
  1042. }
  1043. self.setUnionAuditors(result.unionAuditors);
  1044. if (self.auditors.length > 0) {
  1045. $('#union').modal('show');
  1046. } else {
  1047. toastr.warning(`${audit_order}审未添加任何协同人,请先添加协同人再分配协同台账`);
  1048. }
  1049. });
  1050. }
  1051. getUnionAuditLedgerData() {
  1052. this.auditors.forEach(a => { a.lid = []; });
  1053. for (const node of this.tree.nodes) {
  1054. if (node.audit_id > 0) {
  1055. const relaAudit = this.auditors.find(x => { return x.audit_id === node.audit_id; });
  1056. if (relaAudit) relaAudit.lid.push(node.ledger_id);
  1057. }
  1058. }
  1059. return this.auditors.map(a => {
  1060. return { id: a.id, audit_ledger_id: a.lid.join(',') };
  1061. });
  1062. }
  1063. }
  1064. const auditUnion = new AuditUnion();
  1065. $('body').on('click', '[name=union-set]', function() {
  1066. auditUnion.loadUnionData(this.getAttribute('sp_type'), this.getAttribute('audit_order'));
  1067. });
  1068. $.subMenu({
  1069. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1070. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1071. key: 'menu.1.0.0',
  1072. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1073. callback: function (info) {
  1074. if (info.mini) {
  1075. $('.panel-title').addClass('fluid');
  1076. $('#sub-menu').removeClass('panel-sidebar');
  1077. } else {
  1078. $('.panel-title').removeClass('fluid');
  1079. $('#sub-menu').addClass('panel-sidebar');
  1080. }
  1081. autoFlashHeight();
  1082. }
  1083. });
  1084. let timer2 = null;
  1085. let oldSearchVal2 = null;
  1086. $('body').on('input propertychange', '#batch input[name="audit-name"]', function(e) {
  1087. oldSearchVal2 = e.target.value;
  1088. timer2 && clearTimeout(timer2);
  1089. timer2 = setTimeout(() => {
  1090. const newVal = $(this).val();
  1091. const resultLength = $('#tender-list').find('.result').length;
  1092. if (resultLength > 0) {
  1093. let content = $('#tender-list').html();
  1094. const replaceStr = $('#tender-list').find('.result').eq(0).html();
  1095. const regExp2 = new RegExp('<span class="result" style="background: yellow;">' + replaceStr + '</span>', 'g');
  1096. content = content.replace(regExp2, replaceStr);
  1097. const regExp3 = new RegExp('<span class="result" style="background: orange;">' + replaceStr + '</span>', 'g');
  1098. content = content.replace(regExp3, replaceStr);
  1099. $('#tender-list').html(content);
  1100. }
  1101. $('#search-result').text('0/0');
  1102. $('#up-search').attr('disabled', true);
  1103. $('#down-search').attr('disabled', true);
  1104. if (newVal && newVal === oldSearchVal2) {
  1105. const regExp = new RegExp(newVal, 'g');
  1106. for (let i = 0; i < $('#tender-list tr').length; i++) {
  1107. if (_.includes($('#tender-list tr').eq(i).children('td').eq(2).html(), newVal)) {
  1108. $('#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>'))
  1109. }
  1110. }
  1111. const resultLength2 = $('#tender-list').find('.result').length;
  1112. if (resultLength2 > 0) {
  1113. $('#tender-list').find('.result').eq(0).css('background', 'orange');
  1114. $('#search-result').text('1/' + resultLength2);
  1115. $('#up-search').attr('disabled', false);
  1116. $('#down-search').attr('disabled', false);
  1117. }
  1118. }
  1119. if($('#tender-list').find('.result').length > 0) {
  1120. const X = $('#tender-list').find('.result').eq(0).offset().top;
  1121. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  1122. }
  1123. }, 400);
  1124. });
  1125. $('#up-search').on('click', function () {
  1126. const cur = parseInt($('#search-result').text().split('/')[0]);
  1127. const total = parseInt($('#search-result').text().split('/')[1]);
  1128. const now = cur - 1 !== 0 ? cur - 1: total;
  1129. $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  1130. $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  1131. // $('#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;">'))
  1132. // $('#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;">'))
  1133. $('#search-result').text(now + '/' + total);
  1134. const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  1135. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  1136. });
  1137. $('#down-search').on('click', function () {
  1138. const cur = parseInt($('#search-result').text().split('/')[0]);
  1139. const total = parseInt($('#search-result').text().split('/')[1]);
  1140. const now = cur + 1 > total ? 1: cur + 1;
  1141. $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  1142. $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  1143. // $('#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;">'))
  1144. // $('#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;">'))
  1145. $('#search-result').text(now + '/' + total);
  1146. const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  1147. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() -30);
  1148. });
  1149. // 审批组
  1150. $('body').on('click', '.show-spzsave', function () {
  1151. const this_code = $(this).attr('data-code');
  1152. const groupId = $(this).attr('data-group') || null;
  1153. const flow = sp_lc.find(x => { return x.code === this_code; });
  1154. $('#save-code').val(this_code);
  1155. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1156. if (group) {
  1157. $('#save-group-id').val(group.id);
  1158. $('#spzsave input[name="group_name"]').val(group.name);
  1159. $('#show-delete-group-btn').show();
  1160. } else {
  1161. $('#save-group-id').val('');
  1162. $('#spzsave input[name="group_name"]').val('');
  1163. $('#show-delete-group-btn').hide();
  1164. }
  1165. if (this_code === 'change') {
  1166. if (group) {
  1167. $('#show-change-type input').each(function () {
  1168. if (group.change_type[$(this).data('type')]) {
  1169. $(this).prop('checked', true);
  1170. } else {
  1171. $(this).prop('checked', false);
  1172. }
  1173. });
  1174. } else {
  1175. $('#show-change-type input').each(function () {
  1176. $(this).prop('checked', false);
  1177. });
  1178. $('#show-change-type input[data-type="change"]').prop('checked', true);
  1179. }
  1180. $('#show-change-type input').removeAttr('disabled');
  1181. $('#show-change-type').show();
  1182. } else {
  1183. $('#show-change-type input').attr('disabled', true);
  1184. $('#show-change-type').hide();
  1185. }
  1186. $('#spzsave').modal('show');
  1187. });
  1188. $('#save-group-btn').click(function () {
  1189. const name = _.trim($('#spzsave input[name="group_name"]').val());
  1190. if (!name) {
  1191. toastr.error('审批组名称不能为空');
  1192. return false;
  1193. }
  1194. if (name.length > 50) {
  1195. toastr.error('审批组名称不能超过50个字符');
  1196. return false;
  1197. }
  1198. const code = $('#save-code').val();
  1199. const prop = {
  1200. type: 'save-group',
  1201. name,
  1202. code,
  1203. }
  1204. const groupId = $('#save-group-id').val();
  1205. const flow = sp_lc.find(x => { return x.code === code; });
  1206. if (flow.groupList && flow.groupList.length >= 0 && _.findIndex(flow.groupList, function (item) {
  1207. return item.name === name && item.id !== parseInt(groupId);
  1208. }) !== -1) {
  1209. toastr.error('审批组名称已存在, 请更改名称');
  1210. return false;
  1211. }
  1212. if (groupId) {
  1213. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1214. if (!group) {
  1215. toastr.error('审批组不存在');
  1216. return false;
  1217. }
  1218. prop.groupId = group.id;
  1219. }
  1220. if (code === 'change') {
  1221. const change_type = {};
  1222. let change_flag = false;
  1223. $('#show-change-type input').each(function () {
  1224. change_type[$(this).data('type')] = $(this).prop('checked');
  1225. if ($(this).prop('checked')) {
  1226. change_flag = true;
  1227. }
  1228. });
  1229. if (!change_flag) {
  1230. toastr.error('请至少选择一种变更显示模块');
  1231. return false;
  1232. }
  1233. prop.change_type = change_type;
  1234. }
  1235. console.log(prop);
  1236. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  1237. flow.auditGroupList = data.group.auditGroupList || [];
  1238. if (groupId) {
  1239. const index = flow.groupList.findIndex(x => { return x.id === parseInt(groupId); });
  1240. flow.groupList[index] = data.group;
  1241. } else {
  1242. if (!flow.groupList) flow.groupList = [];
  1243. for (const g of flow.groupList) {
  1244. g.is_select = 0;
  1245. }
  1246. flow.groupList.push(data.group);
  1247. }
  1248. // 配置页面
  1249. let addhtml = auditUtils.getGroupHtml(flow, code);
  1250. addhtml += '<ul class="list-unstyled">\n';
  1251. addhtml += auditUtils.getgdsplHtml(flow, code);
  1252. addhtml += '</ul>\n';
  1253. $('.' + code + '_div').children('.lc-show').html(addhtml);
  1254. $('#spzsave').modal('hide');
  1255. });
  1256. });
  1257. // 切换审批组
  1258. $('body').on('change', '.group-list', function () {
  1259. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  1260. const flow = sp_lc.find(x => { return x.code === this_code; });
  1261. const groupId = parseInt($(this).val());
  1262. const _self = $(this);
  1263. const prop = {
  1264. type: 'change-group',
  1265. groupId,
  1266. }
  1267. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  1268. flow.groupList.forEach(function (item) {
  1269. item.is_select = 0;
  1270. });
  1271. const group = flow.groupList.find(x => { return x.id === groupId; });
  1272. group.is_select = 1;
  1273. flow.auditGroupList = group.auditGroupList;
  1274. const addhtml = auditUtils.getgdsplHtml(flow, this_code);
  1275. _self.parents('.lc-show').children('ul').html(addhtml);
  1276. _self.parents('.lc-show').find('.edit-spzsave').attr('data-group', groupId);
  1277. });
  1278. });
  1279. $('#show-delete-group-btn').click(function () {
  1280. const code = $('#save-code').val();
  1281. const groupId = $('#save-group-id').val();
  1282. const flow = sp_lc.find(x => { return x.code === code; });
  1283. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1284. if (!group) {
  1285. toastr.error('该审批组不存在');
  1286. return false;
  1287. }
  1288. $('#delete-group-name').text(group.name);
  1289. $('#delete-group-id').val(group.id);
  1290. $('#delete-code').val(code);
  1291. $('#spzsave').modal('hide');
  1292. $('#spzdelete').modal('show');
  1293. });
  1294. $('#delete-group-btn').click(function () {
  1295. const code = $('#delete-code').val();
  1296. const groupId = $('#delete-group-id').val();
  1297. const flow = sp_lc.find(x => { return x.code === code; });
  1298. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1299. if (!group) {
  1300. toastr.error('该审批组不存在');
  1301. return false;
  1302. }
  1303. const prop = {
  1304. type: 'delete-group',
  1305. groupId: group.id,
  1306. }
  1307. console.log(prop);
  1308. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  1309. // const flow = findSplc(code);
  1310. const index = flow.groupList.findIndex(x => { return x.id === group.id; });
  1311. flow.groupList.splice(index, 1);
  1312. flow.auditGroupList = flow.groupList.length > 0 ? flow.groupList[0].auditGroupList : [];
  1313. if (flow.groupList.length > 0) flow.groupList[0].is_select = 1;
  1314. // 配置页面
  1315. let addhtml = auditUtils.getGroupHtml(flow, code);
  1316. addhtml += '<ul class="list-unstyled">\n';
  1317. addhtml += auditUtils.getgdsplHtml(flow, code);
  1318. addhtml += '</ul>\n';
  1319. $('.' + code + '_div').children('.lc-show').html(addhtml);
  1320. $('#spzdelete').modal('hide');
  1321. });
  1322. });
  1323. });
  1324. // 审批流程-审批人html 生成
  1325. function makeAudit(audit, i = '终') {
  1326. return '<li class="d-flex justify-content-start mb-3">\n' +
  1327. ' <span class="col-auto">'+ i +'审</span>\n' +
  1328. ' <span class="col-7 spr-span">\n' +
  1329. ' <span class="d-inline-block"></span>\n' +
  1330. ' <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  1331. ' <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' +
  1332. ' <div class="dropdown-menu">\n' +
  1333. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  1334. ' <div class="dropdown-divider"></div>\n' +
  1335. ' <div class="px-2 py-1 text-center">\n' +
  1336. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  1337. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  1338. ' </div>\n' +
  1339. ' </div>\n' +
  1340. ' </span> ' +
  1341. // '<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' +
  1342. ' </span></span></span>\n' +
  1343. ' </li>';
  1344. }
  1345. // 审批流程-选择审批人html 生成
  1346. function makeSelectAudit(code, i = '终') {
  1347. let divhtml = '';
  1348. accountGroup.forEach((group, idx) => {
  1349. let didivhtml = '';
  1350. if(group) {
  1351. group.groupList.forEach(item => {
  1352. 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' +
  1353. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  1354. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  1355. ' <span class="text-muted">' + item.role + '</span>\n' +
  1356. ' </dd>\n' : '';
  1357. });
  1358. 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' +
  1359. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  1360. ' </div>\n';
  1361. }
  1362. });
  1363. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  1364. ' <span class="col-auto">' + i + '审</span>\n' +
  1365. ' <span class="col-7 spr-span">\n' +
  1366. ' <span class="d-inline-block">\n' +
  1367. ' <div class="dropdown text-right">\n' +
  1368. ' <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' +
  1369. ' 选择审批人\n' +
  1370. ' </button>\n' +
  1371. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  1372. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  1373. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  1374. ' <dl class="list-unstyled book-list">\n' + divhtml +
  1375. ' </dl>\n' +
  1376. ' </div>\n' +
  1377. ' </div>\n' +
  1378. ' </span>\n' +
  1379. ' </span>\n' +
  1380. ' </li>';
  1381. return html;
  1382. }