shenpi.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. // 查询方法
  12. function findNode (key, value, arr) {
  13. for (const a of arr) {
  14. if (a[key] && a[key] === value) {
  15. return a;
  16. }
  17. }
  18. }
  19. // 初始化TenderTree数据
  20. function initTenderTree () {
  21. const levelCategory = category.filter(function (c) {
  22. return c.level && c.level > 0;
  23. });
  24. function findCategoryNode(cid, value, array) {
  25. for (const a of array) {
  26. if (a.cid === cid && a.vid === value) {
  27. return a;
  28. }
  29. }
  30. }
  31. function getCategoryNode(category, value, parent, i = null) {
  32. const array = parent ? parent.children : tenderTree;
  33. let cate = findCategoryNode(category.id, value, array);
  34. if (!cate) {
  35. const cateValue = findNode('id', value, category.value);
  36. if (!cateValue) return null;
  37. cate = {
  38. cid: category.id,
  39. vid: value,
  40. name: cateValue.value,
  41. children: [],
  42. level: i ? i : category.level,
  43. sort_id: ++parentId,
  44. };
  45. array.push(cate);
  46. }
  47. return cate;
  48. }
  49. function loadTenderCategory (tender) {
  50. let tenderCategory = null;
  51. for (const [index,lc] of levelCategory.entries()) {
  52. const tenderCate = findNode('cid', lc.id, tender.category);
  53. if (tenderCate) {
  54. tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
  55. } else {
  56. if (index === 0 && tender.category) {
  57. for (const [i,c] of tender.category.entries()) {
  58. const cate = findNode('id', c.cid, category);
  59. tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
  60. }
  61. }
  62. return tenderCategory;
  63. }
  64. }
  65. return tenderCategory;
  66. }
  67. function calculateTender(tender) {
  68. if (tender.lastStage) {
  69. tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp);
  70. tender.end_contract_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp);
  71. tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp);
  72. tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp);
  73. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  74. tender.yf_tp = ZhCalc.add(tender.lastStage.yf_tp);
  75. tender.end_yf_tp = ZhCalc.add(tender.lastStage.pre_yf_tp, tender.yf_tp);
  76. }
  77. }
  78. tenderTree.splice(0, tenderTree.length);
  79. for (const t of tenders) {
  80. calculateTender(t);
  81. t.valid = true;
  82. delete t.level;
  83. if (t.category && levelCategory.length > 0) {
  84. const parent = loadTenderCategory(t);
  85. if (parent) {
  86. t.level = parent.level + 1;
  87. parent.children.push(t);
  88. } else {
  89. tenderTree.push(t);
  90. }
  91. } else {
  92. tenderTree.push(t);
  93. }
  94. }
  95. }
  96. function recursiveGetTenderNodeHtml (node, arr, pid, this_code, this_status, aidList = []) {
  97. const html = [];
  98. html.push('<tr pid="' + pid + '">');
  99. // 名称
  100. html.push('<td class="in-' + node.level + '">');
  101. if (node.cid) {
  102. html.push('<i class="fa fa-folder-o"></i> ', node.name);
  103. } else {
  104. html.push('<span class="text-muted mr-2">');
  105. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  106. html.push('</span>');
  107. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  108. html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');
  109. }
  110. html.push('</td>');
  111. // 创建人
  112. // html.push('<td>', sp_status_list[node.shenpiInfo[shenpi_type]].name, '</td>');
  113. html.push('<td>');
  114. if (!node.cid) {
  115. let auditList = [];
  116. let tender_status = 1;
  117. if(cur_tenderid === node.id) {
  118. html.push(sp_status_list[this_status].name);
  119. auditList = aidList;
  120. tender_status = this_status;
  121. } else {
  122. html.push(sp_status_list[node.shenpiInfo[this_code]].name);
  123. auditList = node.shenpiauditList[this_code];
  124. tender_status = node.shenpiInfo[this_code];
  125. }
  126. if(tender_status === sp_status.gdspl || tender_status === sp_status.gdzs) {
  127. const nameList = [];
  128. if(auditList) {
  129. for (const uid of auditList) {
  130. const user = _.find(accountList, { id: uid });
  131. nameList.push(user.name);
  132. }
  133. }
  134. html.push('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
  135. 'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
  136. }
  137. }
  138. html.push('</td>');
  139. html.push('<td>');
  140. if (!node.cid) {
  141. html.push('<input data-tid="'+ node.id +'" type="checkbox"'+ (cur_tenderid === node.id ? ' checked disabled' : '') +'>');
  142. }
  143. html.push('</td>');
  144. html.push('</tr>');
  145. if (node.children) {
  146. for (const c of node.children) {
  147. html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id, this_code, this_status, aidList));
  148. }
  149. }
  150. return html.join('');
  151. }
  152. // 根据TenderTree数据获取Html代码
  153. function getTenderTreeHtml (this_code, this_status, aidList = []) {
  154. if (tenderTree.length > 0) {
  155. const html = [];
  156. html.push('<table class="table table-hover table-bordered">');
  157. html.push('<thead>', '<tr>');
  158. html.push('<th>名称</th>');
  159. html.push('<th width="100">审批流程</th>');
  160. html.push('<th width="40">选择</th>');
  161. html.push('</tr>', '</thead>');
  162. parentId = 0;
  163. for (const t of tenderTree) {
  164. html.push(recursiveGetTenderNodeHtml(t, tenderTree, '', this_code, this_status, aidList));
  165. }
  166. html.push('</table>');
  167. return html.join('');
  168. } else {
  169. return EmptyTenderHtml.join('');
  170. }
  171. }
  172. $(document).ready(function () {
  173. let timer = null;
  174. let oldSearchVal = null;
  175. const needYB = ['ledger', 'revise', 'change'];
  176. $('body').on('input propertychange', '.gr-search', function(e) {
  177. oldSearchVal = e.target.value;
  178. timer && clearTimeout(timer);
  179. timer = setTimeout(() => {
  180. const newVal = $(this).val();
  181. const code = $(this).attr('data-code');
  182. let html = '';
  183. if (newVal && newVal === oldSearchVal) {
  184. 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 => {
  185. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  186. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  187. class="ml-auto">${item.mobile || ''}</span></p>
  188. <span class="text-muted">${item.role || ''}</span>
  189. </dd>`
  190. });
  191. $('#' + code + '_dropdownMenu .book-list').empty();
  192. $('#' + code + '_dropdownMenu .book-list').append(html);
  193. } else {
  194. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  195. accountGroup.forEach((group, idx) => {
  196. if (!group) return;
  197. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  198. </a> ${group.groupName}</dt>
  199. <div class="dd-content" data-toggleid="${idx}">`;
  200. group.groupList.forEach(item => {
  201. if ((item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1))) {
  202. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  203. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  204. class="ml-auto">${item.mobile || ''}</span></p>
  205. <span class="text-muted">${item.role || ''}</span>
  206. </dd>`;
  207. }
  208. });
  209. html += '</div>';
  210. });
  211. $('#' + code + '_dropdownMenu .book-list').empty();
  212. $('#' + code + '_dropdownMenu .book-list').append(html);
  213. }
  214. }
  215. }, 400);
  216. });
  217. // 添加审批流程按钮逻辑
  218. $('body').on('click', '.book-list dt', function () {
  219. const idx = $(this).find('.acc-btn').attr('data-groupid');
  220. const type = $(this).find('.acc-btn').attr('data-type');
  221. if (type === 'hide') {
  222. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  223. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  224. $(this).find('.acc-btn').attr('data-type', 'show');
  225. })
  226. } else {
  227. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  228. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  229. $(this).find('.acc-btn').attr('data-type', 'hide');
  230. })
  231. }
  232. return false;
  233. });
  234. // 更改审批流程状态
  235. $('.form-check input').on('change', function () {
  236. // 获取所有审批的checked值并更新
  237. const this_status = parseInt($(this).val());
  238. const this_code = $(this).data('code');
  239. const spt = sp_status_list[this_status];
  240. $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
  241. // 拼接post json
  242. const prop = {
  243. code: this_code,
  244. status: this_status
  245. };
  246. const _self = $(this);
  247. postData('/tender/' + cur_tenderid + '/shenpi/save', prop, function (data) {
  248. if (this_status === sp_status.sqspr) {
  249. _self.parents('.form-group').siblings('.lc-show').html('');
  250. } else if (this_status === sp_status.gdspl) {
  251. let addhtml = '<ul class="list-unstyled">\n';
  252. if (data.length !== 0) {
  253. for(const [i, audit] of data.entries()) {
  254. addhtml += makeAudit(audit, transFormToChinese(i+1));
  255. }
  256. addhtml += '<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>';
  257. } else {
  258. addhtml += makeSelectAudit(this_code, '一');
  259. }
  260. addhtml += '</ul>\n';
  261. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  262. } else if (this_status === sp_status.gdzs) {
  263. let addhtml = '<ul class="list-unstyled">\n' +
  264. ' <li class="d-flex justify-content-start mb-3">\n' +
  265. ' <span class="col-auto">授权审批人</span>\n' +
  266. ' <span class="col-7">\n' +
  267. ' <span class="d-inline-block"></span>\n' +
  268. ' </span>\n' +
  269. ' </li>\n';
  270. addhtml += data ? makeAudit(data) : makeSelectAudit(this_code);
  271. addhtml += '</ul>\n';
  272. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  273. }
  274. });
  275. });
  276. // 选中审批人
  277. $('body').on('click', 'dl dd', function () {
  278. const id = parseInt($(this).data('id'));
  279. if (id) {
  280. const user = _.find(accountList, function (item) {
  281. return item.id === id;
  282. });
  283. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  284. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  285. if (this_status === sp_status.gdspl) {
  286. // 判断是否已存在审批人
  287. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  288. for (let i = 0; i < aid_num; i++) {
  289. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  290. if (aid === id) {
  291. toastr.warning('该审核人已存在,请勿重复添加');
  292. return;
  293. }
  294. }
  295. }
  296. const prop = {
  297. status: this_status,
  298. code: sp_type[this_code],
  299. audit_id: id,
  300. type: 'add',
  301. };
  302. const _self = $(this);
  303. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  304. if (this_status === sp_status.gdspl) {
  305. _self.parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
  306. }
  307. _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  308. '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="'+ user.id +'"><i class="fa fa-remove"></i></a></span> </span>');
  309. });
  310. }
  311. });
  312. // 移除审批人
  313. $('body').on('click', '.remove-audit', function () {
  314. const id = parseInt($(this).data('id'));
  315. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  316. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  317. const prop = {
  318. status: this_status,
  319. code: sp_type[this_code],
  320. audit_id: id,
  321. type: 'del',
  322. };
  323. const _self = $(this);
  324. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  325. if (this_status === sp_status.gdspl) {
  326. const _selflc = _self.parents('.lc-show');
  327. _self.parents('li').remove();
  328. const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
  329. if (aid_num === 0) {
  330. let addhtml = '<ul class="list-unstyled">\n';
  331. addhtml += makeSelectAudit(this_code, '一');
  332. addhtml += '</ul>\n';
  333. _selflc.html(addhtml);
  334. } else {
  335. for (let i = 0; i < aid_num; i++) {
  336. _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  337. }
  338. }
  339. } else if (this_status === sp_status.gdzs) {
  340. let addhtml = '<ul class="list-unstyled">\n' +
  341. ' <li class="d-flex justify-content-start mb-3">\n' +
  342. ' <span class="col-auto">授权审批人</span>\n' +
  343. ' <span class="col-7">\n' +
  344. ' <span class="d-inline-block"></span>\n' +
  345. ' </span>\n' +
  346. ' </li>\n';
  347. addhtml += makeSelectAudit(this_code);
  348. addhtml += '</ul>\n';
  349. _self.parents('.lc-show').html(addhtml);
  350. }
  351. })
  352. });
  353. // 固定审批流-添加流程
  354. $('body').on('click', '.add-audit', function () {
  355. const num = $(this).parents('ul').children('li').length;
  356. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  357. const addhtml = makeSelectAudit(this_code, transFormToChinese(num));
  358. $(this).parents('ul').append(addhtml);
  359. $(this).parents('li').remove();
  360. });
  361. // 审批流程-审批人html 生成
  362. function makeAudit(audit, i = '终') {
  363. return '<li class="d-flex justify-content-start mb-3">\n' +
  364. ' <span class="col-auto">'+ i +'审</span>\n' +
  365. ' <span class="col-7 spr-span">\n' +
  366. ' <span class="d-inline-block"></span>\n' +
  367. ' <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <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' +
  368. ' </span>\n' +
  369. ' </li>';
  370. }
  371. // 审批流程-选择审批人html 生成
  372. function makeSelectAudit(code, i = '终') {
  373. let divhtml = '';
  374. accountGroup.forEach((group, idx) => {
  375. let didivhtml = '';
  376. if(group) {
  377. group.groupList.forEach(item => {
  378. 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' +
  379. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  380. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  381. ' <span class="text-muted">' + item.role + '</span>\n' +
  382. ' </dd>\n' : '';
  383. });
  384. 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' +
  385. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  386. ' </div>\n';
  387. }
  388. });
  389. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  390. ' <span class="col-auto">' + i + '审</span>\n' +
  391. ' <span class="col-7 spr-span">\n' +
  392. ' <span class="d-inline-block">\n' +
  393. ' <div class="dropdown text-right">\n' +
  394. ' <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' +
  395. ' 选择审批人\n' +
  396. ' </button>\n' +
  397. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  398. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  399. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  400. ' <dl class="list-unstyled book-list">\n' + divhtml +
  401. ' </dl>\n' +
  402. ' </div>\n' +
  403. ' </div>\n' +
  404. ' </span>\n' +
  405. ' </span>\n' +
  406. ' </li>';
  407. return html;
  408. }
  409. initTenderTree();
  410. $('.set-otherTender').on('click', function () {
  411. const this_code = $(this).data('code');
  412. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  413. const aid_num = $(this).siblings('.lc-show').children('ul').find('.remove-audit').length;
  414. const aidList = [];
  415. for (let i = 0; i < aid_num; i++) {
  416. const aid = parseInt($(this).siblings('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
  417. aidList.push(aid);
  418. }
  419. const html = getTenderTreeHtml(this_code, this_status, aidList);
  420. $('#shenpi-name').text($(this).data('name'));
  421. $('#shenpi_code').val(this_code);
  422. $('#shenpi_status').val(this_status);
  423. $('#shenpi_auditors').val(aidList.join(','));
  424. $('#tender-list').html(html);
  425. setTimeout(function () { $("#tender-list [data-toggle='tooltip']").tooltip(); },800);
  426. });
  427. $('#save-other-shenpi').click(function () {
  428. $(this).attr('disabled', true);
  429. const num = $('#tender-list input:checked').length;
  430. if (num < 2) {
  431. toastr.warning('请选择需要设置审批同步的标段');
  432. return;
  433. }
  434. const data = {
  435. type: 'copy2ot',
  436. status: $('#shenpi_status').val(),
  437. code: $('#shenpi_code').val(),
  438. };
  439. if(data.code !== shenpi_status.gdspl) {
  440. data.aidList = $('#shenpi_auditors').val();
  441. }
  442. // 获取已选中的标段
  443. const tenderList = [];
  444. for (let i = 0; i < num; i++) {
  445. const tid = parseInt($('#tender-list input:checked').eq(i).data('tid'));
  446. if (tid !== cur_tenderid) {
  447. tenderList.push(tid);
  448. }
  449. }
  450. data.tidList = tenderList.join(',');
  451. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
  452. toastr.success('设置成功');
  453. setTimeout(function () {
  454. window.location.reload();
  455. }, 1000)
  456. })
  457. })
  458. });