tender_list_info.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. for (const c of node.children) {
  204. calculateParent(c);
  205. node.total_price = ZhCalc.add(node.total_price, c.total_price);
  206. node.gather_tp = ZhCalc.add(node.gather_tp, c.gather_tp);
  207. node.end_contract_tp = ZhCalc.add(node.end_contract_tp, c.end_contract_tp);
  208. node.end_qc_tp = ZhCalc.add(node.end_qc_tp, c.end_qc_tp);
  209. node.end_gather_tp = ZhCalc.add(node.end_gather_tp, c.end_gather_tp);
  210. node.pre_gather_tp = ZhCalc.add(node.pre_gather_tp, c.pre_gather_tp);
  211. node.yf_tp = ZhCalc.add(node.yf_tp, c.yf_tp);
  212. node.end_yf_tp = ZhCalc.add(node.end_yf_tp, c.end_yf_tp);
  213. node.advance_tp = ZhCalc.add(node.advance_tp, c.advance_tp);
  214. }
  215. }
  216. }
  217. function initTenderTree () {
  218. const levelCategory = category.filter(function (c) {
  219. return c.level && c.level > 0;
  220. });
  221. function findCategoryNode(cid, value, array) {
  222. for (const a of array) {
  223. if (a.cid === cid && a.vid === value) {
  224. return a;
  225. }
  226. }
  227. }
  228. function getCategoryNode(category, value, parent, i = null) {
  229. const array = parent ? parent.children : tenderTree;
  230. let cate = findCategoryNode(category.id, value, array);
  231. if (!cate) {
  232. const cateValue = findNode('id', value, category.value);
  233. if (!cateValue) return null;
  234. cate = {
  235. cid: category.id,
  236. vid: value,
  237. name: cateValue.value,
  238. children: [],
  239. level: i ? i : category.level,
  240. sort_id: ++parentId,
  241. sort: cateValue.sort,
  242. };
  243. array.push(cate);
  244. }
  245. return cate;
  246. }
  247. function loadTenderCategory (tender) {
  248. let tenderCategory = null;
  249. for (const [index, lc] of levelCategory.entries()) {
  250. const tenderCate = findNode('cid', lc.id, tender.category);
  251. if (tenderCate) {
  252. tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
  253. } else {
  254. if (index === 0 && tender.category) {
  255. for (const [i,c] of tender.category.entries()) {
  256. const cate = findNode('id', c.cid, category);
  257. tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
  258. }
  259. }
  260. return tenderCategory;
  261. }
  262. }
  263. return tenderCategory;
  264. }
  265. function calculateTender(tender) {
  266. if (tender.lastStage) {
  267. tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp);
  268. tender.end_contract_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp);
  269. tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp);
  270. tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp);
  271. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  272. tender.yf_tp = ZhCalc.add(tender.lastStage.yf_tp);
  273. tender.end_yf_tp = ZhCalc.add(tender.lastStage.pre_yf_tp, tender.yf_tp);
  274. }
  275. }
  276. tenderTree.splice(0, tenderTree.length);
  277. for (const t of tenders) {
  278. calculateTender(t);
  279. t.valid = true;
  280. delete t.level;
  281. if (t.category && levelCategory.length > 0) {
  282. const parent = loadTenderCategory(t);
  283. if (parent) {
  284. t.level = parent.level + 1;
  285. parent.children.push(t);
  286. } else {
  287. tenderTree.push(t);
  288. }
  289. } else {
  290. tenderTree.push(t);
  291. }
  292. }
  293. sortTenderTree();
  294. for (const t of tenderTree) {
  295. calculateParent(t);
  296. }
  297. }
  298. function recursiveGetTenderNodeHtml (node, arr, pid) {
  299. const html = [];
  300. html.push('<tr pid="' + pid + '">');
  301. // 名称
  302. html.push('<td style="width: 20%" class="in-' + node.level + '">');
  303. if (node.cid) {
  304. 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);
  305. } else {
  306. html.push('<span class="text-muted mr-2">');
  307. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  308. html.push('</span>');
  309. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  310. html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');
  311. }
  312. html.push('</td>');
  313. // 计量模式
  314. html.push('<td style="width: 6%" class="text-center">');
  315. if (node.measure_type) {
  316. html.push(node.measure_type === measureType.tz.value ? '0号台账' : '工程量清单');
  317. }
  318. html.push('</td>');
  319. // 计量进度
  320. html.push('<td style="width: 6%">');
  321. if (!node.cid && node.cur_flow) {
  322. html.push(node.cur_flow.title + ' (' + '<span class="' + node.cur_flow.status_class +'">' + node.cur_flow.status + '</span>' + ')');
  323. }
  324. html.push('</td>');
  325. // 当前流程
  326. html.push('<td style="width: 6%">');
  327. if (!node.cid && node.cur_flow) {
  328. html.push(node.cur_flow.name + ' ' + '<span class="' + node.cur_flow.status_class +'">' + node.cur_flow.status + '</span>');
  329. }
  330. html.push('</td>');
  331. // 上一流程审批时间
  332. html.push('<td style="width: 8%">');
  333. if (!node.cid && node.pre_flow) {
  334. html.push(node.pre_flow.name + ' ' + moment(node.pre_flow.time).format('YYYY-MM-DD'));
  335. }
  336. html.push('</td>');
  337. // 0号台账合同
  338. html.push('<td style="width: 6%" class="text-right">');
  339. html.push(node.total_price || '');
  340. html.push('</td>');
  341. // 本期完成
  342. html.push('<td style="width: 6%" class="text-right">');
  343. html.push(node.gather_tp || '');
  344. html.push('</td>');
  345. // 截止本期合同
  346. html.push('<td style="width: 6%" class="text-right">');
  347. html.push(node.end_contract_tp || '');
  348. html.push('</td>');
  349. // 截止本期变更
  350. html.push('<td style="width: 6%" class="text-right">');
  351. html.push(node.end_qc_tp || '');
  352. html.push('</td>');
  353. // 截止本期完成
  354. html.push('<td style="width: 6%" class="text-right">');
  355. html.push(node.end_gather_tp || '');
  356. html.push('</td>');
  357. // 截止上期完成
  358. html.push('<td style="width: 6%" class="text-right">');
  359. html.push(node.pre_gather_tp || '');
  360. html.push('</td>');
  361. // 预付款
  362. html.push('<td style="width: 6%" class="text-right">');
  363. html.push(node.advance_tp || '');
  364. html.push('</td>');
  365. // 本期应付
  366. html.push('<td style="width: 6%" class="text-right">');
  367. html.push(node.yf_tp || '');
  368. html.push('</td>');
  369. // 截止本期应付
  370. html.push('<td style="width: 6%" class="text-right">');
  371. html.push(node.end_yf_tp || '');
  372. html.push('</td>');
  373. html.push('</tr>');
  374. if (node.children) {
  375. for (const c of node.children) {
  376. html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));
  377. }
  378. }
  379. return html.join('');
  380. }
  381. // 根据TenderTree数据获取Html代码
  382. function getTenderTreeHtml () {
  383. if (tenderTree.length > 0) {
  384. const html = [];
  385. html.push('<table class="table table-hover table-bordered">');
  386. html.push('<thead style="position: fixed;left:56px;top: 34px;">', '<tr>');
  387. html.push('<th class="text-center" style="width: 20%">', '标段名称', '</th>');
  388. html.push('<th class="text-center" style="width: 6%">', '计量模式', '</th>');
  389. html.push('<th class="text-center" style="width: 6%">', '计量进度', '</th>');
  390. html.push('<th class="text-center" style="width: 6%">', '当前流程', '</th>');
  391. html.push('<th class="text-center" style="width: 8%">', '上一流程审批时间', '</th>');
  392. html.push('<th class="text-center" style="width: 6%">', '0号台账', '</th>');
  393. html.push('<th class="text-center" style="width: 6%">', '本期完成', '</th>');
  394. html.push('<th class="text-center" style="width: 6%">', '截止本期合同', '</th>');
  395. html.push('<th class="text-center" style="width: 6%">', '截止本期变更', '</th>');
  396. html.push('<th class="text-center" style="width: 6%">', '截止本期完成', '</th>');
  397. html.push('<th class="text-center" style="width: 6%">', '截止上期完成', '</th>');
  398. html.push('<th class="text-center" style="width: 6%">', '预付款', '<i class="fa fa-question-circle text-primary" data-placement="bottom" data-toggle="tooltip" data-original-title="预付款流程中截止本期金额"></i>', '</th>');
  399. html.push('<th class="text-center" style="width: 6%">', '本期应付', '</th>');
  400. html.push('<th class="text-center" style="width: 6%">', '截止本期应付', '</th>');
  401. html.push('</tr>', '</thead>');
  402. parentId = 0;
  403. for (const t of tenderTree) {
  404. html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
  405. }
  406. html.push('</table>');
  407. return html.join('');
  408. } else {
  409. return EmptyTenderHtml.join('');
  410. }
  411. }
  412. function bindTenderUrl() {
  413. $('.c-body').on('click', 'a', function () {
  414. const tenderId = parseInt($(this).attr('id'));
  415. const tender = _.find(tenders, function (t) {
  416. return t.id === tenderId;
  417. });
  418. if (!tender) return;
  419. if (!tender.measure_type && tender.user_id !== userID) return;
  420. if (tender.measure_type) {
  421. // window.location.href = '/tender/' + tenderId;
  422. window.open('/tender/' + tenderId, '_blank');
  423. } else {
  424. for (const a of $('a', '#jlms')) {
  425. a.href = '/tender/' + tenderId + '/type?type=' + $(a).attr('mst');
  426. }
  427. $('#jlms').modal('show');
  428. }
  429. });
  430. }
  431. $(document).ready(() => {
  432. autoFlashHeight();
  433. sortCategory();
  434. // 初始化分类数据
  435. initCategoryLevelNode();
  436. $('.modal-body', '#add-bd').append(getCategoryHtml());
  437. // 初始化标段树结构
  438. initTenderTree();
  439. $('.c-body').html(getTenderTreeHtml());
  440. bindTenderUrl();
  441. localHideList();
  442. // 分类
  443. $('#cate-set').on('show.bs.modal', function () {
  444. createTree();
  445. });
  446. $('#set-cate-ok').click(function () {
  447. const data = [];
  448. const zTree = $.fn.zTree.getZTreeObj('treeLevel');
  449. for (const c of category) {
  450. const node = zTree.getNodeByParam('id', c.id);
  451. const parent = node.getParentNode();
  452. if (parent.lid === 1) {
  453. data.push({id: c.id, level: 0});
  454. } else {
  455. data.push({id: c.id, level: node.getPath().length - 1});
  456. }
  457. }
  458. postData('/setting/category/level', data, function (rst) {
  459. for (const d of data) {
  460. const c = findNode('id', d.id, category);
  461. c.level = d.level;
  462. }
  463. sortCategory();
  464. initCategoryLevelNode();
  465. initTenderTree();
  466. $('.c-body').html(getTenderTreeHtml());
  467. localHideList();
  468. $('#cate-set').modal('hide');
  469. });
  470. });
  471. // 新增标段
  472. $('#add-bd-ok').click(function () {
  473. const data = {
  474. name: cleanSymbols($('[name=name]', '#add-bd').val()),
  475. valuation: $('[name=valuation]:checked').val(),
  476. category: [],
  477. };
  478. if (!data.name || data.name === '') {
  479. // TODO 提示用户
  480. return;
  481. }
  482. for (const c of category) {
  483. if (parseInt($('select', '[cate-id=' + c.id + ']').val()) !== 0) {
  484. const cate = {cid: c.id};
  485. // if (c.type === categoryType.key.dropDown) {
  486. cate.value = parseInt($('select', '[cate-id=' + c.id + ']').val());
  487. // } else if (c.type === categoryType.key.radio) {
  488. // cate.value = parseInt($('input:checked', '[cate-id=' + c.id + ']').val());
  489. // }
  490. data.category.push(cate);
  491. }
  492. }
  493. $('#hide-all').show();
  494. postData('/list/add', data, function (result) {
  495. tenders.push(result);
  496. initTenderTree();
  497. $('.c-body').html(getTenderTreeHtml());
  498. bindTenderUrl();
  499. localHideList();
  500. $('#add-bd').modal('hide');
  501. $('[name=name]', '#add-bd').val('');
  502. $('#hide-all').hide();
  503. });
  504. });
  505. });