tender_list_info.js 18 KB

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