shenpi.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/10/09
  7. * @version
  8. */
  9. const tenderTree = [];
  10. let parentId = 0;
  11. let selects;
  12. // 查询方法
  13. function findNode (key, value, arr) {
  14. for (const a of arr) {
  15. if (a[key] && a[key] === value) {
  16. return a;
  17. }
  18. }
  19. }
  20. // 初始化TenderTree数据
  21. function initTenderTree () {
  22. const levelCategory = category.filter(function (c) {
  23. return c.level && c.level > 0;
  24. });
  25. function findCategoryNode(cid, value, array) {
  26. for (const a of array) {
  27. if (a.cid === cid && a.vid === value) {
  28. return a;
  29. }
  30. }
  31. }
  32. function getCategoryNode(category, value, parent, i = null) {
  33. const array = parent ? parent.children : tenderTree;
  34. let cate = findCategoryNode(category.id, value, array);
  35. if (!cate) {
  36. const cateValue = findNode('id', value, category.value);
  37. if (!cateValue) return null;
  38. cate = {
  39. cid: category.id,
  40. vid: value,
  41. name: cateValue.value,
  42. children: [],
  43. level: i ? i : category.level,
  44. sort_id: ++parentId,
  45. sort: cateValue.sort,
  46. };
  47. array.push(cate);
  48. }
  49. return cate;
  50. }
  51. function loadTenderCategory (tender) {
  52. let tenderCategory = null;
  53. for (const [index,lc] of levelCategory.entries()) {
  54. const tenderCate = findNode('cid', lc.id, tender.category);
  55. if (tenderCate) {
  56. tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
  57. } else {
  58. if (index === 0 && tender.category) {
  59. for (const [i,c] of tender.category.entries()) {
  60. const cate = findNode('id', c.cid, category);
  61. if (cate) tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
  62. }
  63. }
  64. return tenderCategory;
  65. }
  66. }
  67. return tenderCategory;
  68. }
  69. function calculateTender(tender) {
  70. if (tender.lastStage) {
  71. tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp);
  72. tender.end_contract_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp);
  73. tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp);
  74. tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp);
  75. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  76. tender.yf_tp = ZhCalc.add(tender.lastStage.yf_tp);
  77. tender.end_yf_tp = ZhCalc.add(tender.lastStage.pre_yf_tp, tender.yf_tp);
  78. }
  79. }
  80. tenderTree.splice(0, tenderTree.length);
  81. for (const t of tenders) {
  82. calculateTender(t);
  83. t.valid = true;
  84. delete t.level;
  85. if (t.category && levelCategory.length > 0) {
  86. const parent = loadTenderCategory(t);
  87. if (parent) {
  88. t.level = parent.level + 1;
  89. parent.children.push(t);
  90. } else {
  91. tenderTree.push(t);
  92. }
  93. } else {
  94. tenderTree.push(t);
  95. }
  96. }
  97. sortTenderTree();
  98. }
  99. function recursiveGetTenderNodeHtml (node, arr, pid, this_code, this_status, aidList = []) {
  100. const html = [];
  101. html.push('<tr pid="' + pid + '">');
  102. // 名称
  103. html.push('<td class="in-' + node.level + '">');
  104. if (node.cid) {
  105. html.push('<i class="fa fa-folder-o"></i> ', node.name);
  106. } else {
  107. html.push('<span class="text-muted mr-2">');
  108. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  109. html.push('</span>');
  110. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  111. html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');
  112. }
  113. html.push('</td>');
  114. // 创建人
  115. // html.push('<td>', sp_status_list[node.shenpiInfo[shenpi_type]].name, '</td>');
  116. html.push('<td>');
  117. if (!node.cid) {
  118. if(cur_tenderid === node.id) {
  119. html.push(sp_status_list[this_status].name);
  120. } else {
  121. html.push(sp_status_list[node.shenpiInfo[this_code]].name);
  122. }
  123. }
  124. html.push('</td>');
  125. html.push('<td>');
  126. if (!node.cid) {
  127. let auditList = [];
  128. let tender_status = 1;
  129. if(cur_tenderid === node.id) {
  130. auditList = aidList;
  131. tender_status = this_status;
  132. } else {
  133. auditList = node.shenpiauditList[this_code];
  134. tender_status = node.shenpiInfo[this_code];
  135. }
  136. if(tender_status === sp_status.gdspl || tender_status === sp_status.gdzs) {
  137. const nameList = [];
  138. if(auditList) {
  139. for (const uid of auditList) {
  140. const user = _.find(accountList, { id: uid });
  141. nameList.push(user.name);
  142. }
  143. }
  144. // html.push('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
  145. // 'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
  146. html.push(nameList.length > 0 ? nameList.join('-') : '');
  147. }
  148. }
  149. html.push('</td>');
  150. html.push('<td>');
  151. if (!node.cid) {
  152. html.push('<input data-tid="'+ node.id +'" type="checkbox"'+ (cur_tenderid === node.id ? ' checked disabled' : '') +'>');
  153. }
  154. html.push('</td>');
  155. html.push('</tr>');
  156. if (node.children) {
  157. for (const c of node.children) {
  158. html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id, this_code, this_status, aidList));
  159. }
  160. }
  161. return html.join('');
  162. }
  163. // 根据TenderTree数据获取Html代码
  164. function getTenderTreeHtml (this_code, this_status, aidList = []) {
  165. if (tenderTree.length > 0) {
  166. const html = [];
  167. html.push('<table class="table table-hover table-bordered">');
  168. html.push('<thead>', '<tr>');
  169. html.push('<th>名称</th>');
  170. html.push('<th width="80">流程模式</th>');
  171. html.push('<th>详细流程</th>');
  172. html.push('<th width="40">选择</th>');
  173. html.push('</tr>', '</thead>');
  174. parentId = 0;
  175. for (const t of tenderTree) {
  176. html.push(recursiveGetTenderNodeHtml(t, tenderTree, '', this_code, this_status, aidList));
  177. }
  178. html.push('</table>');
  179. return html.join('');
  180. } else {
  181. return EmptyTenderHtml.join('');
  182. }
  183. }
  184. function getShenpiHtml (this_code) {
  185. const html = [];
  186. html.push('<table class="table table-hover table-bordered">');
  187. html.push('<thead>', '<tr>');
  188. html.push('<th>名称</th>');
  189. html.push('<th width="100">审批流程</th>');
  190. html.push('<th width="40">选择</th>');
  191. html.push('</tr>', '</thead>');
  192. for (const sp of sp_lc) {
  193. html.push('<tr>');
  194. html.push('<td>', sp.name, '</td>');
  195. html.push('<td>');
  196. const this_status = parseInt($('.' + sp.code + '_div').children('.lc-show').siblings('.form-group').find('input:checked').val());
  197. html.push(sp_status_list[this_status].name);
  198. if(this_status !== sp_status.sqspr) {
  199. const nameList = [];
  200. const aid_num = $('.' + sp.code + '_div').children('.lc-show').children('ul').find('.remove-audit').length;
  201. const aidList = [];
  202. for (let i = 0; i < aid_num; i++) {
  203. const aid = parseInt($('.' + sp.code + '_div').children('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
  204. aidList.push(aid);
  205. }
  206. if(aidList.length > 0) {
  207. for (const uid of aidList) {
  208. const user = _.find(accountList, { id: uid });
  209. nameList.push(user.name);
  210. }
  211. }
  212. html.push('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
  213. 'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
  214. }
  215. html.push('</td>');
  216. html.push('<td>', this_code !== sp.code ? '<input type="checkbox" data-code="'+ sp.code +'">' : '', '</td>');
  217. html.push('</tr>');
  218. }
  219. html.push('</table>');
  220. return html.join('');
  221. }
  222. $(document).ready(function () {
  223. const auditUtils = {
  224. getAuditHtml: function(audit) {
  225. return '<span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  226. ' <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' +
  227. ' <div class="dropdown-menu">\n' +
  228. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  229. ' <div class="dropdown-divider"></div>\n' +
  230. ' <div class="px-2 py-1 text-center">\n' +
  231. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  232. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  233. ' </div>\n' +
  234. ' </div>\n' +
  235. ' </span> ' +
  236. ' </span></span>\n'
  237. },
  238. getAuditTypeHtml: function(code, type) {
  239. const html = [];
  240. const hide = code !== 'stage' ? 'style="display: none;"' : '';
  241. html.push(`<span class="d-inline-block"><select class="form-control form-control-sm" ${hide} data-type="${type}">`);
  242. for (const t of auditType.types) {
  243. html.push(`<option value="${t.value}" ${t.value === type ? 'selected' : ''}>${t.name}</option>`);
  244. }
  245. html.push('</select></span>');
  246. return html.join('');
  247. },
  248. getSelectAuditHtml: function (code) {
  249. let divhtml = '';
  250. accountGroup.forEach((group, idx) => {
  251. let didivhtml = '';
  252. if(group) {
  253. group.groupList.forEach(item => {
  254. 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' +
  255. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  256. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  257. ' <span class="text-muted">' + item.role + '</span>\n' +
  258. ' </dd>\n' : '';
  259. });
  260. 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' +
  261. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  262. ' </div>\n';
  263. }
  264. });
  265. const html =
  266. ' <span class="d-inline-block">\n' +
  267. ' <div class="dropdown text-right">\n' +
  268. ' <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' +
  269. ' 选择审批人\n' +
  270. ' </button>\n' +
  271. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  272. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  273. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  274. ' <dl class="list-unstyled book-list">\n' + divhtml +
  275. ' </dl>\n' +
  276. ' </div>\n' +
  277. ' </div>\n' +
  278. ' </span>\n';
  279. return html;
  280. },
  281. // 以下i从1开始
  282. getAuditGroupInnerHtml: function(code, auditGroup, i) {
  283. const html = [];
  284. const type = auditGroup.length > 0 ? auditGroup[0].audit_type : auditType.key.common;
  285. html.push(`<span class="col-auto">${transFormToChinese(i)}审</span><span class="col-7 spr-span">`);
  286. html.push(this.getAuditTypeHtml(code, type));
  287. for (const audit of auditGroup) {
  288. html.push(this.getAuditHtml(audit));
  289. }
  290. if (type !== auditType.key.common || auditGroup.length === 0) {
  291. html.push(this.getSelectAuditHtml(code));
  292. }
  293. html.push('</span>');
  294. return html.join('');
  295. },
  296. getAuditGroupHtml: function (code, auditGroup, i) {
  297. return `<li class="d-flex justify-content-start align-items-center mb-3">${this.getAuditGroupInnerHtml(code, auditGroup, i)}</li>`;
  298. },
  299. getFinalAuditHtml: function (audit) {
  300. const html = [];
  301. html.push('<li class="d-flex justify-content-start mb-3"><span class="col-auto">终审</span><span class="col-7 spr-span">');
  302. html.push(this.getAuditHtml(audit));
  303. html.push('</span></span></li>');
  304. return html.join('');
  305. },
  306. // 以下i从0开始
  307. addAudit: function (code, user, i) {
  308. const flow = sp_lc.find(x => { return x.code === code });
  309. if (!flow.auditGroupList) flow.auditGroupList = [];
  310. if (!flow.auditGroupList[i]) flow.auditGroupList[i] = [];
  311. flow.auditGroupList[i].push(user);
  312. return flow.auditGroupList[i];
  313. },
  314. removeAudit: function (code, audit_id, i) {
  315. const flow = sp_lc.find(x => { return x.code === code });
  316. if (flow.auditGroupList[i].length === 1) {
  317. flow.auditGroupList.splice(i, 1);
  318. return null;
  319. }
  320. flow.auditGroupList[i].splice(flow.auditGroupList[i].findIndex(x => { return x.audit_id === audit_id; }), 1);
  321. return flow.auditGroupList[i];
  322. },
  323. setAuditType: function (code, audit_type, i) {
  324. const flow = sp_lc.find(x => { return x.code === code });
  325. if (!flow || !flow.auditGroupList || !flow.auditGroupList[i]) return;
  326. flow.auditGroupList[i].forEach(x => { x.audit_type = audit_type});
  327. return flow.auditGroupList[i];
  328. }
  329. };
  330. let timer = null;
  331. let oldSearchVal = null;
  332. const needYB = ['advance', 'ledger', 'revise', 'change', 'audit-ass'];
  333. $('body').on('input propertychange', '.gr-search', function(e) {
  334. oldSearchVal = e.target.value;
  335. timer && clearTimeout(timer);
  336. timer = setTimeout(() => {
  337. const newVal = $(this).val();
  338. const code = $(this).attr('data-code');
  339. let html = '';
  340. if (newVal && newVal === oldSearchVal) {
  341. 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 => {
  342. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  343. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  344. class="ml-auto">${item.mobile || ''}</span></p>
  345. <span class="text-muted">${item.role || ''}</span>
  346. </dd>`
  347. });
  348. $('#' + code + '_dropdownMenu .book-list').empty();
  349. $('#' + code + '_dropdownMenu .book-list').append(html);
  350. } else {
  351. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  352. accountGroup.forEach((group, idx) => {
  353. if (!group) return;
  354. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  355. </a> ${group.groupName}</dt>
  356. <div class="dd-content" data-toggleid="${idx}">`;
  357. group.groupList.forEach(item => {
  358. if ((item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1))) {
  359. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  360. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  361. class="ml-auto">${item.mobile || ''}</span></p>
  362. <span class="text-muted">${item.role || ''}</span>
  363. </dd>`;
  364. }
  365. });
  366. html += '</div>';
  367. });
  368. $('#' + code + '_dropdownMenu .book-list').empty();
  369. $('#' + code + '_dropdownMenu .book-list').append(html);
  370. }
  371. }
  372. }, 400);
  373. });
  374. // 添加审批流程按钮逻辑
  375. $('body').on('click', '.book-list dt', function () {
  376. const idx = $(this).find('.acc-btn').attr('data-groupid');
  377. const type = $(this).find('.acc-btn').attr('data-type');
  378. if (type === 'hide') {
  379. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  380. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  381. $(this).find('.acc-btn').attr('data-type', 'show');
  382. })
  383. } else {
  384. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  385. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  386. $(this).find('.acc-btn').attr('data-type', 'hide');
  387. })
  388. }
  389. return false;
  390. });
  391. // 更改审批流程状态
  392. $('.form-check input').on('change', function () {
  393. // 获取所有审批的checked值并更新
  394. const this_status = parseInt($(this).val());
  395. const this_code = $(this).data('code');
  396. const spt = sp_status_list[this_status];
  397. $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
  398. // 拼接post json
  399. const prop = {
  400. code: this_code,
  401. status: this_status
  402. };
  403. const _self = $(this);
  404. postData('/tender/' + cur_tenderid + '/shenpi/save', prop, function (data) {
  405. if (this_status === sp_status.sqspr) {
  406. _self.parents('.form-group').siblings('.lc-show').html('');
  407. } else if (this_status === sp_status.gdspl) {
  408. let addhtml = '<ul class="list-unstyled">\n';
  409. const flow = sp_lc.find(x => { return x.code === this_code; });
  410. flow.auditGroupList = data;
  411. if (data.length !== 0) {
  412. for(const [i, auditGroup] of data.entries()) {
  413. addhtml += auditUtils.getAuditGroupHtml(this_code, auditGroup, i + 1);
  414. }
  415. addhtml += '<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>';
  416. } else {
  417. addhtml += auditUtils.getAuditGroupHtml(this_code, [], 1);
  418. }
  419. addhtml += '</ul>\n';
  420. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  421. } else if (this_status === sp_status.gdzs) {
  422. let addhtml = '<ul class="list-unstyled">\n' +
  423. ' <li class="d-flex justify-content-start mb-3">\n' +
  424. ' <span class="col-auto">授权审批人</span>\n' +
  425. ' <span class="col-7">\n' +
  426. ' <span class="d-inline-block"></span>\n' +
  427. ' </span>\n' +
  428. ' </li>\n';
  429. addhtml += data ? makeAudit(data) : makeSelectAudit(this_code);
  430. addhtml += '</ul>\n';
  431. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  432. }
  433. if(this_code === 'stage') {
  434. if(this_status === sp_status.gdspl) {
  435. $('#stage_cooperation').show();
  436. } else {
  437. $('#stage_cooperation').hide();
  438. }
  439. }
  440. });
  441. });
  442. // 选中审批人
  443. $('body').on('click', 'dl dd', function () {
  444. const id = parseInt($(this).data('id'));
  445. if (!id) return;
  446. let this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  447. if (!this_code) this_code = $(this).parents('.dropdown').data('code');
  448. const user = _.find(accountList, function (item) {
  449. return item.id === id;
  450. });
  451. if (this_code === 'audit-ass') {
  452. auditAss.setAuditAssist(user);
  453. } else {
  454. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  455. if (this_status === sp_status.gdspl) {
  456. // 判断是否已存在审批人
  457. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  458. for (let i = 0; i < aid_num; i++) {
  459. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  460. if (aid === id) {
  461. toastr.warning('该审核人已存在,请勿重复添加');
  462. return;
  463. }
  464. }
  465. }
  466. const prop = {
  467. status: this_status,
  468. code: sp_type[this_code],
  469. audit_id: id,
  470. type: 'add',
  471. };
  472. if (this_status === sp_status.gdspl) {
  473. prop.audit_type = parseInt($(this).parents('li').find('select')[0].value);
  474. prop.audit_order = $(this).parents('li').index() + 1;
  475. }
  476. const _self = $(this);
  477. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  478. if (this_status === sp_status.gdspl) {
  479. 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);
  480. if (_self.parents('ul').find('.add-audit').length === 0) {
  481. _self.parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
  482. }
  483. _self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, prop.audit_order));
  484. } else {
  485. _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  486. '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <span class="dropdown">\n' +
  487. ' <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' +
  488. ' <div class="dropdown-menu">\n' +
  489. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  490. ' <div class="dropdown-divider"></div>\n' +
  491. ' <div class="px-2 py-1 text-center">\n' +
  492. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + user.id + '">移除</button>\n' +
  493. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  494. ' </div>\n' +
  495. ' </div>\n' +
  496. ' </span> ' +
  497. ' </span></span></span>\n');
  498. }
  499. });
  500. }
  501. });
  502. // 移除审批人
  503. $('body').on('click', '.remove-audit', function () {
  504. const id = parseInt($(this).data('id'));
  505. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  506. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  507. const prop = {
  508. status: this_status,
  509. code: sp_type[this_code],
  510. audit_id: id,
  511. type: 'del',
  512. };
  513. const _self = $(this);
  514. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  515. if (this_status === sp_status.gdspl) {
  516. const index = _self.parents('li').index();
  517. const auditGroup = auditUtils.removeAudit(this_code, id, index);
  518. if (auditGroup) {
  519. _self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, index + 1));
  520. } else {
  521. const _selflc = _self.parents('.lc-show');
  522. _self.parents('li').remove();
  523. const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
  524. if (aid_num === 0) {
  525. _selflc.html(auditUtils.getAuditGroupHtml(this_code, [], 1));
  526. } else {
  527. for (let i = 0; i < aid_num; i++) {
  528. _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  529. }
  530. }
  531. }
  532. } else if (this_status === sp_status.gdzs) {
  533. let addhtml = '<ul class="list-unstyled">\n' +
  534. ' <li class="d-flex justify-content-start mb-3">\n' +
  535. ' <span class="col-auto">授权审批人</span>\n' +
  536. ' <span class="col-7">\n' +
  537. ' <span class="d-inline-block"></span>\n' +
  538. ' </span>\n' +
  539. ' </li>\n';
  540. addhtml += makeSelectAudit(this_code);
  541. addhtml += '</ul>\n';
  542. _self.parents('.lc-show').html(addhtml);
  543. }
  544. })
  545. });
  546. // 固定审批流-添加流程
  547. $('body').on('click', '.add-audit', function () {
  548. const num = $(this).parents('ul').children('li').length;
  549. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  550. //const addhtml = makeSelectAudit(this_code, transFormToChinese(num));
  551. const addhtml = auditUtils.getAuditGroupHtml(this_code, [], num);
  552. $(this).parents('ul').append(addhtml);
  553. $(this).parents('li').remove();
  554. });
  555. // 审批流程-审批人html 生成
  556. function makeAudit(audit, i = '终') {
  557. return '<li class="d-flex justify-content-start mb-3">\n' +
  558. ' <span class="col-auto">'+ i +'审</span>\n' +
  559. ' <span class="col-7 spr-span">\n' +
  560. ' <span class="d-inline-block"></span>\n' +
  561. ' <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  562. ' <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' +
  563. ' <div class="dropdown-menu">\n' +
  564. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  565. ' <div class="dropdown-divider"></div>\n' +
  566. ' <div class="px-2 py-1 text-center">\n' +
  567. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  568. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  569. ' </div>\n' +
  570. ' </div>\n' +
  571. ' </span> ' +
  572. // '<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' +
  573. ' </span></span></span>\n' +
  574. ' </li>';
  575. }
  576. // 审批流程-选择审批人html 生成
  577. function makeSelectAudit(code, i = '终') {
  578. let divhtml = '';
  579. accountGroup.forEach((group, idx) => {
  580. let didivhtml = '';
  581. if(group) {
  582. group.groupList.forEach(item => {
  583. 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' +
  584. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  585. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  586. ' <span class="text-muted">' + item.role + '</span>\n' +
  587. ' </dd>\n' : '';
  588. });
  589. 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' +
  590. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  591. ' </div>\n';
  592. }
  593. });
  594. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  595. ' <span class="col-auto">' + i + '审</span>\n' +
  596. ' <span class="col-7 spr-span">\n' +
  597. ' <span class="d-inline-block">\n' +
  598. ' <div class="dropdown text-right">\n' +
  599. ' <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' +
  600. ' 选择审批人\n' +
  601. ' </button>\n' +
  602. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  603. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  604. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  605. ' <dl class="list-unstyled book-list">\n' + divhtml +
  606. ' </dl>\n' +
  607. ' </div>\n' +
  608. ' </div>\n' +
  609. ' </span>\n' +
  610. ' </span>\n' +
  611. ' </li>';
  612. return html;
  613. }
  614. initTenderTree();
  615. $('.set-otherTender').on('click', function () {
  616. const this_code = $(this).data('code');
  617. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  618. const lis = $(this).siblings('.lc-show').find('li');
  619. const auditList = [], aidList = [];
  620. lis.each((i, li) => {
  621. const removes = $(li).find('.remove-audit');
  622. if (removes.length === 0) return;
  623. const select = $(li).find('select');
  624. const audit_type = select.length > 0 ? parseInt(select.val()) : 1;
  625. for (const remove of removes) {
  626. auditList.push({ audit_id: parseInt(remove.getAttribute('data-id')), audit_type, audit_order: i + 1 });
  627. aidList.push(parseInt(remove.getAttribute('data-id')));
  628. }
  629. });
  630. const html = getTenderTreeHtml(this_code, this_status, aidList);
  631. $('#shenpi-name').text($(this).data('name'));
  632. $('#shenpi_code').val(this_code);
  633. $('#shenpi_status').val(this_status);
  634. $('#shenpi_auditors').val(JSON.stringify(auditList));
  635. $('#tender-list').html(html);
  636. $('#search-audit').val('');
  637. $('#search-result').text('0/0');
  638. $('#up-search').attr('disabled', true);
  639. $('#down-search').attr('disabled', true);
  640. setTimeout(function () { $("#tender-list [data-toggle='tooltip']").tooltip(); },800);
  641. });
  642. $('#save-other-tender').click(function () {
  643. $(this).attr('disabled', true);
  644. const num = $('#tender-list input:checked').length;
  645. if (num < 2) {
  646. toastr.warning('请选择需要设置审批同步的标段');
  647. return;
  648. }
  649. const data = {
  650. type: 'copy2ot',
  651. status: parseInt($('#shenpi_status').val()),
  652. code: $('#shenpi_code').val(),
  653. };
  654. if(data.status !== shenpi_status.gdspl) {
  655. data.auditList = JSON.parse($('#shenpi_auditors').val());
  656. }
  657. // 获取已选中的标段
  658. const tenderList = [];
  659. for (let i = 0; i < num; i++) {
  660. const tid = parseInt($('#tender-list input:checked').eq(i).data('tid'));
  661. if (tid !== cur_tenderid) {
  662. tenderList.push(tid);
  663. }
  664. }
  665. data.tidList = tenderList.join(',');
  666. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
  667. toastr.success('设置成功');
  668. setTimeout(function () {
  669. window.location.reload();
  670. }, 1000)
  671. })
  672. });
  673. $('.set-otherShenpi').on('click', function () {
  674. let canSetOther = true;
  675. const this_code = $(this).data('code');
  676. if (this_code === 'stage') {
  677. const select = $(this).siblings('.lc-show').find('select');
  678. select.each((i, s) => {
  679. if (s.value !== '1') canSetOther = false;
  680. });
  681. }
  682. if (!canSetOther) {
  683. toastr.warning('该流程含有会签或签,不可同步至其他流程');
  684. $('#batch2').modal('hide');
  685. return;
  686. }
  687. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  688. const aid_num = $(this).siblings('.lc-show').children('ul').find('.remove-audit').length;
  689. const aidList = [];
  690. for (let i = 0; i < aid_num; i++) {
  691. const aid = parseInt($(this).siblings('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
  692. aidList.push(aid);
  693. }
  694. const html = getShenpiHtml(this_code);
  695. $('#shenpi-name2').text($(this).data('name'));
  696. $('#shenpi_code2').val(this_code);
  697. $('#shenpi_status2').val(this_status);
  698. $('#shenpi_auditors2').val(aidList.join(','));
  699. $('#shenpi-list').html(html);
  700. setTimeout(function () { $("#shenpi-list [data-toggle='tooltip']").tooltip(); },800);
  701. $('#batch2').modal('show');
  702. });
  703. $('#save-other-shenpi').click(function () {
  704. $(this).attr('disabled', true);
  705. const num = $('#shenpi-list input:checked').length;
  706. if (num < 1) {
  707. toastr.warning('请选择需要设置审批同步的流程');
  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.aidList = $('#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', 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('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) 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.assList = data.auditAssList;
  871. self.tree.loadDatas(data.ledgerList);
  872. SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
  873. self.uid = uid;
  874. self.refreshOperate();
  875. }, null, true);
  876. }
  877. loadPostData(data) {
  878. if (data.add) {
  879. this.assList.push(data.add);
  880. }
  881. if (data.del) {
  882. this.assList.splice(this.assList.findIndex(x => { return x.id === data.del.id }), 1);
  883. }
  884. if (data.update) {
  885. for (const d of data.update) {
  886. const od = this.assList.find(x => { return x.id === d.id });
  887. if (!od) continue;
  888. od.ass_ledger_id = d.ass_ledger_id;
  889. }
  890. }
  891. this._refreshAss();
  892. }
  893. setAuditAssist(assist){
  894. const node = SpreadJsObj.getSelectObject(this.sheet);
  895. if (assist && node.ass_audit_id === assist.id) return;
  896. if (assist && assist.id === this.uid) {
  897. toastr.warning('请勿添加本人');
  898. return;
  899. }
  900. const self = this;
  901. const data = { type: 'audit-ass'};
  902. if (assist) {
  903. const newAss = this.showAssList.find(x => { return x.ass_user_id === assist.id; });
  904. if (!newAss) {
  905. 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 + '' };
  906. } else {
  907. data.update = [{ id: newAss.id, ass_ledger_id: newAss.ass_ledger_id + ',' + node.ledger_id}];
  908. }
  909. }
  910. if (node.ass_audit_id) {
  911. const orgAss = this.showAssList.find(x => { return x.ass_user_id === node.ass_audit_id; });
  912. const rela_lid = orgAss.ass_ledger_id ? orgAss.ass_ledger_id.split(',') : [];
  913. rela_lid.splice(rela_lid.indexOf(node.ledger_id + ''), 1);
  914. if (rela_lid.length === 0) {
  915. data.del = { id: orgAss.id };
  916. } else {
  917. if (!data.update) data.update = [];
  918. data.update.push({ id: orgAss.id, ass_ledger_id: rela_lid.join(',')});
  919. }
  920. }
  921. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function (result) {
  922. self.loadPostData(result);
  923. self.refreshOperate();
  924. });
  925. }
  926. removeAuditAss(assistId) {
  927. const self = this;
  928. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', { type: 'audit-ass', del: { id: assistId } }, function (result) {
  929. self.loadPostData(result);
  930. self.refreshOperate();
  931. });
  932. }
  933. refreshOperate() {
  934. const node = SpreadJsObj.getSelectObject(this.sheet);
  935. if (node && node.ass_audit_id) {
  936. $('#del-audit-ass').show();
  937. $('#audit-ass_dropdownMenuButton')[0].innerHTML = '替换协同人';
  938. } else {
  939. $('#del-audit-ass').hide();
  940. $('#audit-ass_dropdownMenuButton')[0].innerHTML = '添加协同人';
  941. }
  942. }
  943. }
  944. const auditAss = new AuditAss();
  945. $.subMenu({
  946. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  947. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  948. key: 'menu.1.0.0',
  949. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  950. callback: function (info) {
  951. if (info.mini) {
  952. $('.panel-title').addClass('fluid');
  953. $('#sub-menu').removeClass('panel-sidebar');
  954. } else {
  955. $('.panel-title').removeClass('fluid');
  956. $('#sub-menu').addClass('panel-sidebar');
  957. }
  958. autoFlashHeight();
  959. }
  960. });
  961. let timer2 = null;
  962. let oldSearchVal2 = null;
  963. $('body').on('input propertychange', '#batch input[name="audit-name"]', function(e) {
  964. oldSearchVal2 = e.target.value;
  965. timer2 && clearTimeout(timer2);
  966. timer2 = setTimeout(() => {
  967. const newVal = $(this).val();
  968. const resultLength = $('#tender-list').find('.result').length;
  969. if (resultLength > 0) {
  970. let content = $('#tender-list').html();
  971. const replaceStr = $('#tender-list').find('.result').eq(0).html();
  972. const regExp2 = new RegExp('<span class="result" style="background: yellow;">' + replaceStr + '</span>', 'g');
  973. content = content.replace(regExp2, replaceStr);
  974. const regExp3 = new RegExp('<span class="result" style="background: orange;">' + replaceStr + '</span>', 'g');
  975. content = content.replace(regExp3, replaceStr);
  976. $('#tender-list').html(content);
  977. }
  978. $('#search-result').text('0/0');
  979. $('#up-search').attr('disabled', true);
  980. $('#down-search').attr('disabled', true);
  981. if (newVal && newVal === oldSearchVal2) {
  982. const regExp = new RegExp(newVal, 'g');
  983. for (let i = 0; i < $('#tender-list tr').length; i++) {
  984. if (_.includes($('#tender-list tr').eq(i).children('td').eq(2).html(), newVal)) {
  985. $('#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>'))
  986. }
  987. }
  988. const resultLength2 = $('#tender-list').find('.result').length;
  989. if (resultLength2 > 0) {
  990. $('#tender-list').find('.result').eq(0).css('background', 'orange');
  991. $('#search-result').text('1/' + resultLength2);
  992. $('#up-search').attr('disabled', false);
  993. $('#down-search').attr('disabled', false);
  994. }
  995. }
  996. if($('#tender-list').find('.result').length > 0) {
  997. const X = $('#tender-list').find('.result').eq(0).offset().top;
  998. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  999. }
  1000. }, 400);
  1001. });
  1002. $('#up-search').on('click', function () {
  1003. const cur = parseInt($('#search-result').text().split('/')[0]);
  1004. const total = parseInt($('#search-result').text().split('/')[1]);
  1005. const now = cur - 1 !== 0 ? cur - 1: total;
  1006. $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  1007. $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  1008. // $('#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;">'))
  1009. // $('#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;">'))
  1010. $('#search-result').text(now + '/' + total);
  1011. const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  1012. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  1013. });
  1014. $('#down-search').on('click', function () {
  1015. const cur = parseInt($('#search-result').text().split('/')[0]);
  1016. const total = parseInt($('#search-result').text().split('/')[1]);
  1017. const now = cur + 1 > total ? 1: cur + 1;
  1018. $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  1019. $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  1020. // $('#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;">'))
  1021. // $('#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;">'))
  1022. $('#search-result').text(now + '/' + total);
  1023. const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  1024. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() -30);
  1025. });
  1026. });