shenpi.js 73 KB

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