tender_list_info.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/10/11
  7. * @version
  8. */
  9. const EmptyTenderHtml = [
  10. '<div class="jumbotron">',
  11. '<h3 class="display-6">还没有标段数据</h3>',
  12. '</div>'
  13. ];
  14. // levelTree - setting
  15. const levelTreeSetting = {
  16. view: {
  17. selectedMulti: false
  18. },
  19. data: {
  20. simpleData: {
  21. idKey: 'lid',
  22. pIdKey: 'lpId',
  23. rootPId: 0,
  24. enable: true,
  25. }
  26. },
  27. edit: {
  28. enable: true,
  29. showRemoveBtn: false,
  30. showRenameBtn: false,
  31. drag: {
  32. autoExpandTrigger: true,
  33. isCopy: false,
  34. isMove: true,
  35. prev: false,
  36. next: false,
  37. inner: true,
  38. }
  39. },
  40. callback: {
  41. beforeDrop: beforeDropNode,
  42. onDrop: onDropNode,
  43. }
  44. };
  45. const levelNodes =[];
  46. const tenderTree = [];
  47. let parentId = 0;
  48. function createTree() {
  49. const zTree = $.fn.zTree.getZTreeObj('treeLevel');
  50. if (zTree) {
  51. zTree.destroy();
  52. }
  53. $.fn.zTree.init($("#treeLevel"), levelTreeSetting, levelNodes);
  54. }
  55. function beforeDropNode(treeId, treeNodes, targetNode, moveType, isCopy) {
  56. if (targetNode !== null && targetNode.lid !== 1) {
  57. const parent = targetNode.getParentNode();
  58. if (parent && parent.lid === 1) {
  59. return false;
  60. }
  61. }
  62. for (var i=0,l=treeNodes.length; i<l; i++) {
  63. if (treeNodes[i].drag === false) {
  64. return false;
  65. }
  66. if (!targetNode && treeNodes[i].dropRoot === false) {
  67. return false;
  68. }
  69. if(treeNodes[i].isParent === true && targetNode.lid !== 1){
  70. return false;
  71. }
  72. }
  73. }
  74. function onDropNode(event, treeId, treeNodes, targetNode, moveType) {
  75. const zTree = $.fn.zTree.getZTreeObj(treeId);
  76. function resetFixNode(id) {
  77. const node = zTree.getNodeByParam('lid', id);
  78. node.isParent = true;
  79. zTree.updateNode(node, false);
  80. zTree.expandNode(node, true);
  81. }
  82. function moveChildren(children, node) {
  83. if (!children || children.length === 0) { return }
  84. for (const c of children) {
  85. moveChildren(c.children, node);
  86. zTree.moveNode(node, c, 'inner');
  87. }
  88. }
  89. resetFixNode(1);
  90. resetFixNode(2);
  91. if (targetNode !== null && targetNode.lid === 1 && treeNodes[0].children && treeNodes[0].children.length !== 0) {
  92. moveChildren(treeNodes[0].children, zTree.getNodeByParam('lid', 1));
  93. } else if (targetNode !== null && targetNode.lid !== 1) {
  94. if (targetNode.children.length >= 2) {
  95. for (const c of targetNode.children) {
  96. if (c.lid !== treeNodes[0].lid) {
  97. zTree.moveNode(treeNodes[0], c, 'inner');
  98. }
  99. }
  100. }
  101. }
  102. }
  103. // 查询方法
  104. function findNode (key, value, arr) {
  105. for (const a of arr) {
  106. if (a[key] && a[key] === value) {
  107. return a;
  108. }
  109. }
  110. }
  111. function getPId(level) {
  112. if (level !== 1) {
  113. const p = findNode('level', level - 1, levelNodes);
  114. if (p) {
  115. return p.lid
  116. } else {
  117. return 1;
  118. }
  119. } else {
  120. return 2;
  121. }
  122. }
  123. // 分类数据排序
  124. function sortCategory() {
  125. category.sort(function (a, b) {
  126. return a.level ? (b.level ? a.level - b.level : -1) : a.id - b.id;
  127. });
  128. }
  129. // 初始化分类树结构数据
  130. function initCategoryLevelNode() {
  131. levelNodes.splice(0, levelNodes.length);
  132. levelNodes.push(
  133. { lid:1, lpId:0, name:"可用类别", open:true, isParent: true, drag: false},
  134. { lid:2, lpId:0, name:"已用类别", open:true, isParent: true, drag: false}
  135. );
  136. for (const c of category) {
  137. const cate = JSON.parse(JSON.stringify(c));
  138. cate.lid = levelNodes.length + 1;
  139. cate.open = true;
  140. cate.dropRoot = false;
  141. if (!cate.level) {
  142. cate.lpId = 1;
  143. levelNodes.push(cate);
  144. } else {
  145. cate.lpId = getPId(cate.level);
  146. levelNodes.push(cate);
  147. }
  148. }
  149. }
  150. // 新建标段 -- 分类属性选择
  151. function getCategoryHtml() {
  152. function getSelectCategoryHtml (cate) {
  153. const html = [];
  154. html.push('<div class="form-group" cate-id="' + cate.id + '">');
  155. html.push('<lable>', cate.name, '</lable>');
  156. html.push('<select class="form-control form-control-sm">');
  157. for (const v of cate.value) {
  158. html.push('<option value="' + v.id + '">', v.value, '</option>');
  159. }
  160. html.push('<option value="0">不选</option>');
  161. html.push('</select>');
  162. html.push('</div>');
  163. return html.join('');
  164. }
  165. function getRadioCategoryHtml (cate) {
  166. const html = [];
  167. html.push('<div class="form-group" cate-id="' + cate.id + '">');
  168. html.push('<lable>', cate.name, '</lable>');
  169. html.push('<div>');
  170. for (const iV in cate.value) {
  171. const v = cate.value[iV];
  172. html.push('<div class="form-check-inline">');
  173. html.push('<input class="form-check-input" type="radio"', 'name="' + cate.name + '" ', 'value="' , v.id, (iV == 0 ? '" checked="' : ''), '">');
  174. html.push('<label class="form-check-label">', v.value, '</label>');
  175. html.push('</div>');
  176. }
  177. html.push('</div>');
  178. html.push('</div>');
  179. return html.join('');
  180. }
  181. const html = [];
  182. for (const c of category) {
  183. // if (c.type === categoryType.key.dropDown) {
  184. html.push(getSelectCategoryHtml(c));
  185. // } else if (c.type === categoryType.key.radio) {
  186. // html.push(getRadioCategoryHtml(c));
  187. // }
  188. }
  189. return html.join('');
  190. }
  191. // 初始化TenderTree数据
  192. function calculateParent(node) {
  193. if (node.children && node.cid) {
  194. node.total_price = 0;
  195. node.gather_tp = 0;
  196. node.end_contract_tp = 0;
  197. node.end_qc_tp = 0;
  198. node.end_gather_tp = 0;
  199. node.pre_gather_tp = 0;
  200. node.yf_tp = 0;
  201. node.end_yf_tp = 0;
  202. node.advance_tp = 0;
  203. node.contract_price = 0;
  204. for (const c of node.children) {
  205. calculateParent(c);
  206. node.total_price = ZhCalc.add(node.total_price, c.total_price);
  207. node.gather_tp = ZhCalc.add(node.gather_tp, c.gather_tp);
  208. node.end_contract_tp = ZhCalc.add(node.end_contract_tp, c.end_contract_tp);
  209. node.end_qc_tp = ZhCalc.add(node.end_qc_tp, c.end_qc_tp);
  210. node.end_gather_tp = ZhCalc.add(node.end_gather_tp, c.end_gather_tp);
  211. node.pre_gather_tp = ZhCalc.add(node.pre_gather_tp, c.pre_gather_tp);
  212. node.yf_tp = ZhCalc.add(node.yf_tp, c.yf_tp);
  213. node.end_yf_tp = ZhCalc.add(node.end_yf_tp, c.end_yf_tp);
  214. node.advance_tp = ZhCalc.add(node.advance_tp, c.advance_tp);
  215. node.contract_price = ZhCalc.add(node.contract_price, c.contract_price);
  216. }
  217. }
  218. }
  219. function initTenderTree () {
  220. const levelCategory = category.filter(function (c) {
  221. return c.level && c.level > 0;
  222. });
  223. function findCategoryNode(cid, value, array) {
  224. for (const a of array) {
  225. if (a.cid === cid && a.vid === value) {
  226. return a;
  227. }
  228. }
  229. }
  230. function getCategoryNode(category, value, parent, i = null) {
  231. const array = parent ? parent.children : tenderTree;
  232. let cate = findCategoryNode(category.id, value, array);
  233. if (!cate) {
  234. const cateValue = findNode('id', value, category.value);
  235. if (!cateValue) return null;
  236. cate = {
  237. cid: category.id,
  238. vid: value,
  239. name: cateValue.value,
  240. children: [],
  241. level: i ? i : category.level,
  242. sort_id: ++parentId,
  243. sort: cateValue.sort,
  244. };
  245. array.push(cate);
  246. }
  247. return cate;
  248. }
  249. function loadTenderCategory (tender) {
  250. let tenderCategory = null;
  251. for (const [index, lc] of levelCategory.entries()) {
  252. const tenderCate = findNode('cid', lc.id, tender.category);
  253. if (tenderCate) {
  254. tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
  255. } else {
  256. if (index === 0 && tender.category) {
  257. for (const [i,c] of tender.category.entries()) {
  258. const cate = findNode('id', c.cid, category);
  259. if (cate) {
  260. tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
  261. } else {
  262. console.log(tender.name, c.cid, c.value);
  263. }
  264. }
  265. }
  266. return tenderCategory;
  267. }
  268. }
  269. return tenderCategory;
  270. }
  271. function calculateTender(tender) {
  272. if (tender.lastStage) {
  273. tender.gather_tp = ZhCalc.sum([tender.lastStage.contract_tp, tender.lastStage.qc_tp, tender.lastStage.pc_tp]);
  274. tender.end_contract_tp = ZhCalc.sum([tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp, tender.lastStage.contract_pc_tp]);
  275. tender.end_qc_tp = ZhCalc.sum([tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp, tender.lastStage.qc_pc_tp]);
  276. tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp);
  277. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  278. tender.yf_tp = ZhCalc.add(tender.lastStage.yf_tp);
  279. tender.end_yf_tp = ZhCalc.add(tender.lastStage.pre_yf_tp, tender.yf_tp);
  280. }
  281. }
  282. tenderTree.splice(0, tenderTree.length);
  283. for (const t of tenders) {
  284. calculateTender(t);
  285. t.valid = true;
  286. delete t.level;
  287. if (t.category && levelCategory.length > 0) {
  288. const parent = loadTenderCategory(t);
  289. if (parent) {
  290. t.level = parent.level + 1;
  291. parent.children.push(t);
  292. } else {
  293. tenderTree.push(t);
  294. }
  295. } else {
  296. tenderTree.push(t);
  297. }
  298. }
  299. sortTenderTree();
  300. for (const t of tenderTree) {
  301. calculateParent(t);
  302. }
  303. }
  304. function recursiveGetTenderNodeHtml (node, arr, pid) {
  305. const html = [];
  306. html.push('<tr pid="' + pid + '">');
  307. // 名称
  308. html.push('<td style="min-width: 300px;" class="in-' + node.level + '">');
  309. if (node.cid) {
  310. html.push('<span onselectstart="return false" style="{-moz-user-select:none}" class="fold-switch mr-1" title="收起" cid="'+ node.sort_id +'"><i class="fa fa-minus-square-o"></i></span> <i class="fa fa-folder-o"></i> ', node.name);
  311. } else {
  312. html.push('<span class="text-muted mr-2">');
  313. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  314. html.push('</span>');
  315. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  316. html.push('<a href="javascript: void(0)" style="min-width: 300px;word-break:break-all;" id="' + node.id + '">', node.name, '</a>');
  317. }
  318. html.push('</td>');
  319. // 计量模式
  320. html.push('<td style="width: 75px" class="text-center">');
  321. if (node.measure_type) {
  322. html.push(node.measure_type === measureType.tz.value ? '0号台账' : '工程量清单');
  323. }
  324. html.push('</td>');
  325. // 计量进度
  326. html.push('<td style="width: 105px">');
  327. if (!node.cid && node.cur_flow) {
  328. html.push(node.cur_flow.title + ' (' + '<span class="' + node.cur_flow.status_class +'">' + node.cur_flow.status + '</span>' + ')');
  329. }
  330. html.push('</td>');
  331. // 当前流程
  332. html.push('<td style="width: 230px">');
  333. if (!node.cid && node.cur_flow) {
  334. html.push((node.lastStage && node.lastStage.status === auditConst.stage.status.uncheck) || (!node.lastStage && node.ledger_status === auditConst.ledger.status.uncheck ) ? '' :
  335. '<a href="#sp-list" data-toggle="modal" data-target="#sp-list" data-type="'+ (node.lastStage ? 'stage' : 'ledger') +'"' +
  336. ' data-tender="'+ node.id +'" data-order="'+ (node.lastStage ? node.lastStage.order : '') +'">');
  337. html.push(node.cur_flow.name+ (node.cur_flow.role ? '-'+node.cur_flow.role : ''));
  338. html.push((node.lastStage && node.lastStage.status === auditConst.stage.status.uncheck) || (!node.lastStage && node.ledger_status === auditConst.ledger.status.uncheck ) ? ' ':
  339. '</a> ');
  340. html.push('<span class="' + node.cur_flow.status_class +'">' + node.cur_flow.status + '</span>');
  341. }
  342. html.push('</td>');
  343. // 上一流程审批时间
  344. // html.push('<td style="width: 7%">');
  345. // if (!node.cid && node.pre_flow) {
  346. // html.push(node.pre_flow.name + ' ' + moment(node.pre_flow.time).format('YYYY-MM-DD'));
  347. // }
  348. // html.push('</td>');
  349. // 签约合同价
  350. html.push('<td style="width: 100px" class="text-right">');
  351. html.push(node.contract_price || '');
  352. html.push('</td>');
  353. // 0号台账合同
  354. html.push('<td style="width: 100px" class="text-right">');
  355. html.push(node.total_price || '');
  356. html.push('</td>');
  357. // 本期完成
  358. html.push('<td style="width: 100px" class="text-right">');
  359. html.push(node.gather_tp || '');
  360. html.push('</td>');
  361. // 截止本期合同
  362. html.push('<td style="width: 100px" class="text-right">');
  363. html.push(node.end_contract_tp || '');
  364. html.push('</td>');
  365. // 截止本期变更
  366. html.push('<td style="width: 100px" class="text-right">');
  367. html.push(node.end_qc_tp || '');
  368. html.push('</td>');
  369. // 截止本期完成
  370. html.push('<td style="width: 100px" class="text-right">');
  371. html.push(node.end_gather_tp || '');
  372. html.push('</td>');
  373. // 截止上期完成
  374. html.push('<td style="width: 100px" class="text-right">');
  375. html.push(node.pre_gather_tp || '');
  376. html.push('</td>');
  377. // 预付款
  378. html.push('<td style="width: 100px" class="text-right">');
  379. html.push(node.advance_tp || '');
  380. html.push('</td>');
  381. // 本期应付
  382. html.push('<td style="width: 100px" class="text-right">');
  383. html.push(node.yf_tp || '');
  384. html.push('</td>');
  385. // 截止本期应付
  386. html.push('<td style="width: 100px" class="text-right">');
  387. html.push(node.end_yf_tp || '');
  388. html.push('</td>');
  389. html.push('</tr>');
  390. if (node.children) {
  391. for (const c of node.children) {
  392. html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));
  393. }
  394. }
  395. return html.join('');
  396. }
  397. // 根据TenderTree数据获取Html代码
  398. function getTenderTreeHtml () {
  399. if (tenderTree.length > 0) {
  400. const html = [];
  401. html.push('<table class="table table-hover table-bordered">');
  402. html.push('<thead style="position: fixed;left:56px;top: 34px;">', '<tr>');
  403. html.push('<th class="text-center" style="min-width: 300px;">', '标段名称', '</th>');
  404. html.push('<th class="text-center" style="width: 75px">', '计量模式', '</th>');
  405. html.push('<th class="text-center" style="width: 105px">', '计量进度', '</th>');
  406. html.push('<th class="text-center" style="width: 230px">', '当前流程', '</th>');
  407. // html.push('<th class="text-center" style="width: 7%">', '上一流程审批时间', '</th>');
  408. html.push('<th class="text-center" style="width: 100px">', '签约合同价', '</th>');
  409. html.push('<th class="text-center" style="width: 100px">', '0号台账', '</th>');
  410. html.push('<th class="text-center" style="width: 100px">', '本期完成', '</th>');
  411. html.push('<th class="text-center" style="width: 100px">', '截止本期合同', '</th>');
  412. html.push('<th class="text-center" style="width: 100px">', '截止本期变更', '</th>');
  413. html.push('<th class="text-center" style="width: 100px">', '截止本期完成', '</th>');
  414. html.push('<th class="text-center" style="width: 100px">', '截止上期完成', '</th>');
  415. html.push('<th class="text-center" style="width: 100px">', '预付款', '<i class="fa fa-question-circle text-primary" data-placement="bottom" data-toggle="tooltip" data-original-title="预付款流程中截止本期金额"></i>', '</th>');
  416. html.push('<th class="text-center" style="width: 100px">', '本期应付', '</th>');
  417. html.push('<th class="text-center" style="width: 100px">', '截止本期应付', '</th>');
  418. html.push('</tr>', '</thead>');
  419. parentId = 0;
  420. for (const t of tenderTree) {
  421. html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
  422. }
  423. html.push('</table>');
  424. return html.join('');
  425. } else {
  426. return EmptyTenderHtml.join('');
  427. }
  428. }
  429. function bindTenderUrl() {
  430. $('.c-body').on('click', 'a', function () {
  431. const tenderId = parseInt($(this).attr('id'));
  432. const tender = _.find(tenders, function (t) {
  433. return t.id === tenderId;
  434. });
  435. if (!tender) return;
  436. if (!tender.measure_type && tender.user_id !== userID) return;
  437. if (tender.measure_type) {
  438. // window.location.href = '/tender/' + tenderId;
  439. window.open('/tender/' + tenderId, '_blank');
  440. } else {
  441. for (const a of $('a', '#jlms')) {
  442. a.href = '/tender/' + tenderId + '/type?type=' + $(a).attr('mst');
  443. }
  444. $('#jlms').modal('show');
  445. }
  446. });
  447. }
  448. $(document).ready(() => {
  449. autoFlashHeight();
  450. sortCategory();
  451. // 初始化分类数据
  452. initCategoryLevelNode();
  453. $('.modal-body', '#add-bd').append(getCategoryHtml());
  454. // 初始化标段树结构
  455. initTenderTree();
  456. $('.c-body').html(getTenderTreeHtml());
  457. bindTenderUrl();
  458. localHideList();
  459. tenderTreeShowLevel.initShowLevel();
  460. // 分类
  461. $('#cate-set').on('show.bs.modal', function () {
  462. createTree();
  463. });
  464. $('#set-cate-ok').click(function () {
  465. const data = [];
  466. const zTree = $.fn.zTree.getZTreeObj('treeLevel');
  467. for (const c of category) {
  468. const node = zTree.getNodeByParam('id', c.id);
  469. const parent = node.getParentNode();
  470. if (parent.lid === 1) {
  471. data.push({id: c.id, level: 0});
  472. } else {
  473. data.push({id: c.id, level: node.getPath().length - 1});
  474. }
  475. }
  476. postData('/setting/category/level', data, function (rst) {
  477. for (const d of data) {
  478. const c = findNode('id', d.id, category);
  479. c.level = d.level;
  480. }
  481. sortCategory();
  482. initCategoryLevelNode();
  483. initTenderTree();
  484. $('.c-body').html(getTenderTreeHtml());
  485. localHideList();
  486. $('#cate-set').modal('hide');
  487. tenderTreeShowLevel.refreshMenuVisible();
  488. });
  489. });
  490. // 新增标段
  491. $('#add-bd-ok').click(function () {
  492. const data = {
  493. name: cleanSymbols($('[name=name]', '#add-bd').val()),
  494. valuation: $('[name=valuation]:checked').val(),
  495. category: [],
  496. };
  497. if (!data.name || data.name === '') {
  498. // TODO 提示用户
  499. return;
  500. }
  501. for (const c of category) {
  502. if (parseInt($('select', '[cate-id=' + c.id + ']').val()) !== 0) {
  503. const cate = {cid: c.id};
  504. // if (c.type === categoryType.key.dropDown) {
  505. cate.value = parseInt($('select', '[cate-id=' + c.id + ']').val());
  506. // } else if (c.type === categoryType.key.radio) {
  507. // cate.value = parseInt($('input:checked', '[cate-id=' + c.id + ']').val());
  508. // }
  509. data.category.push(cate);
  510. }
  511. }
  512. $('#hide-all').show();
  513. postData('/list/add', data, function (result) {
  514. tenders.push(result);
  515. initTenderTree();
  516. $('.c-body').html(getTenderTreeHtml());
  517. bindTenderUrl();
  518. localHideList();
  519. $('#add-bd').modal('hide');
  520. $('[name=name]', '#add-bd').val('');
  521. $('#hide-all').hide();
  522. });
  523. });
  524. });