tender_list_info.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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.lid !== 1) {
  57. const parent = targetNode.getParentNode();
  58. if (parent && parent.lid === 1) {
  59. return false;
  60. }
  61. }
  62. }
  63. function onDropNode(event, treeId, treeNodes, targetNode, moveType) {
  64. const zTree = $.fn.zTree.getZTreeObj(treeId);
  65. function resetFixNode(id) {
  66. const node = zTree.getNodeByParam('lid', id);
  67. node.isParent = true;
  68. zTree.updateNode(node, false);
  69. zTree.expandNode(node, true);
  70. }
  71. function moveChildren(children, node) {
  72. if (!children || children.length === 0) { return }
  73. for (const c of children) {
  74. moveChildren(c.children, node);
  75. zTree.moveNode(node, c, 'inner');
  76. }
  77. }
  78. resetFixNode(1);
  79. resetFixNode(2);
  80. if (targetNode.lid === 1 && treeNodes[0].children && treeNodes[0].children.length !== 0) {
  81. moveChildren(treeNodes[0].children, zTree.getNodeByParam('lid', 1));
  82. } else if (targetNode.lid !== 1) {
  83. if (targetNode.children.length >= 2) {
  84. for (const c of targetNode.children) {
  85. if (c.lid !== treeNodes[0].lid) {
  86. zTree.moveNode(treeNodes[0], c, 'inner');
  87. }
  88. }
  89. }
  90. }
  91. }
  92. // 查询方法
  93. function findNode (key, value, arr) {
  94. for (const a of arr) {
  95. if (a[key] && a[key] === value) {
  96. return a;
  97. }
  98. }
  99. }
  100. function getPId(level) {
  101. if (level !== 1) {
  102. const p = findNode('level', level - 1, levelNodes);
  103. if (p) {
  104. return p.lid
  105. } else {
  106. return 1;
  107. }
  108. } else {
  109. return 2;
  110. }
  111. }
  112. // 分类数据排序
  113. function sortCategory() {
  114. category.sort(function (a, b) {
  115. return a.level ? (b.level ? a.level - b.level : -1) : a.id - b.id;
  116. });
  117. }
  118. // 初始化分类树结构数据
  119. function initCategoryLevelNode() {
  120. levelNodes.splice(0, levelNodes.length);
  121. levelNodes.push(
  122. { lid:1, lpId:0, name:"可用类别", open:true, isParent: true},
  123. { lid:2, lpId:0, name:"已用类别", open:true, isParent: true}
  124. );
  125. for (const c of category) {
  126. const cate = JSON.parse(JSON.stringify(c));
  127. cate.lid = levelNodes.length + 1;
  128. cate.open = true;
  129. if (!cate.level) {
  130. cate.lpId = 1;
  131. levelNodes.push(cate);
  132. } else {
  133. cate.lpId = getPId(cate.level);
  134. levelNodes.push(cate);
  135. }
  136. }
  137. }
  138. // 新建标段 -- 分类属性选择
  139. function getCategoryHtml() {
  140. function getSelectCategoryHtml (cate) {
  141. const html = [];
  142. html.push('<div class="form-group" cate-id="' + cate.id + '">');
  143. html.push('<lable>', cate.name, '</lable>');
  144. html.push('<select class="form-control">');
  145. for (const v of cate.value) {
  146. html.push('<option value="' + v.id + '">', v.value, '</option>');
  147. }
  148. html.push('</select>');
  149. html.push('</div>');
  150. return html.join('');
  151. }
  152. function getRadioCategoryHtml (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('<div>');
  157. for (const iV in cate.value) {
  158. const v = cate.value[iV];
  159. html.push('<div class="form-check-inline">');
  160. html.push('<input class="form-check-input" type="radio"', 'name="' + cate.name + '" ', 'value="' , v.id, (iV == 0 ? '" checked="' : ''), '">');
  161. html.push('<label class="form-check-label">', v.value, '</label>');
  162. html.push('</div>');
  163. }
  164. html.push('</div>');
  165. html.push('</div>');
  166. return html.join('');
  167. }
  168. const html = [];
  169. for (const c of category) {
  170. // if (c.type === categoryType.key.dropDown) {
  171. html.push(getSelectCategoryHtml(c));
  172. // } else if (c.type === categoryType.key.radio) {
  173. // html.push(getRadioCategoryHtml(c));
  174. // }
  175. }
  176. return html.join('');
  177. }
  178. // 初始化TenderTree数据
  179. function initTenderTree () {
  180. const levelCategory = category.filter(function (c) {
  181. return c.level && c.level > 0;
  182. });
  183. function findCategoryNode(cid, value, array) {
  184. for (const a of array) {
  185. if (a.cid === cid && a.vid === value) {
  186. return a;
  187. }
  188. }
  189. }
  190. function getCategoryNode(category, value, parent, i = null) {
  191. const array = parent ? parent.children : tenderTree;
  192. let cate = findCategoryNode(category.id, value, array);
  193. if (!cate) {
  194. const cateValue = findNode('id', value, category.value);
  195. if (!cateValue) return null;
  196. cate = {
  197. cid: category.id,
  198. vid: value,
  199. name: cateValue.value,
  200. children: [],
  201. level: i ? i : category.level,
  202. sort_id: ++parentId,
  203. };
  204. array.push(cate);
  205. }
  206. return cate;
  207. }
  208. function loadTenderCategory (tender) {
  209. let tenderCategory = null;
  210. for (const [index, lc] of levelCategory.entries()) {
  211. const tenderCate = findNode('cid', lc.id, tender.category);
  212. if (tenderCate) {
  213. tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
  214. } else {
  215. if (index === 0 && tender.category) {
  216. for (const [i,c] of tender.category.entries()) {
  217. const cate = findNode('id', c.cid, category);
  218. tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
  219. }
  220. }
  221. return tenderCategory;
  222. }
  223. }
  224. return tenderCategory;
  225. }
  226. function calculateTender(tender) {
  227. if (tender.lastStage) {
  228. tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp);
  229. tender.end_contract_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp);
  230. tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp);
  231. tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp);
  232. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  233. tender.yf_tp = ZhCalc.add(tender.lastStage.yf_tp);
  234. tender.end_yf_tp = ZhCalc.add(tender.lastStage.pre_yf_tp, tender.yf_tp);
  235. }
  236. }
  237. tenderTree.splice(0, tenderTree.length);
  238. for (const t of tenders) {
  239. calculateTender(t);
  240. t.valid = true;
  241. delete t.level;
  242. if (t.category && levelCategory.length > 0) {
  243. const parent = loadTenderCategory(t);
  244. if (parent) {
  245. t.level = parent.level + 1;
  246. parent.children.push(t);
  247. } else {
  248. tenderTree.push(t);
  249. }
  250. } else {
  251. tenderTree.push(t);
  252. }
  253. }
  254. }
  255. function recursiveGetTenderNodeHtml (node, arr, pid) {
  256. const html = [];
  257. html.push('<tr pid="' + pid + '">');
  258. // 名称
  259. html.push('<td class="in-' + node.level + '">');
  260. if (node.cid) {
  261. html.push('<span 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);
  262. } else {
  263. html.push('<span class="text-muted mr-2">');
  264. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  265. html.push('</span>');
  266. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  267. html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');
  268. }
  269. html.push('</td>');
  270. // 计量模式
  271. html.push('<td>');
  272. if (node.measure_type) {
  273. html.push(node.measure_type === measureType.tz.value ? '0号台账' : '工程量清单');
  274. }
  275. html.push('</td>');
  276. // 计量期数
  277. html.push('<td>');
  278. if (!node.cid) {
  279. html.push(node.lastStage ? '第' + node.lastStage.order + '期' : '台账');
  280. }
  281. html.push('</td>');
  282. // 审批状态
  283. html.push('<td>');
  284. html.push(node.lastStage ? auditConst.stage.statusString[node.lastStage.status] : auditConst.ledger.statusString[node.ledger_status]);
  285. html.push('</td>');
  286. // 0号台账合同
  287. html.push('<td class="text-right">');
  288. html.push(node.total_price);
  289. console.log(node);
  290. html.push('</td>');
  291. // 本期完成
  292. html.push('<td class="text-right">');
  293. html.push(node.gather_tp);
  294. html.push('</td>');
  295. // 截止本期合同
  296. html.push('<td class="text-right">');
  297. html.push(node.end_contract_tp);
  298. html.push('</td>');
  299. // 截止本期变更
  300. html.push('<td class="text-right">');
  301. html.push(node.end_qc_tp);
  302. html.push('</td>');
  303. // 截止本期完成
  304. html.push('<td class="text-right">');
  305. html.push(node.end_gather_tp);
  306. html.push('</td>');
  307. // 截止上期完成
  308. html.push('<td class="text-right">');
  309. html.push(node.pre_gather_tp);
  310. html.push('</td>');
  311. // 本期应付
  312. html.push('<td class="text-right">');
  313. html.push(node.yf_tp);
  314. html.push('</td>');
  315. // 截止本期应付
  316. html.push('<td class="text-right">');
  317. html.push(node.end_yf_tp);
  318. html.push('</td>');
  319. html.push('</tr>');
  320. if (node.children) {
  321. for (const c of node.children) {
  322. html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));
  323. }
  324. }
  325. return html.join('');
  326. }
  327. // 根据TenderTree数据获取Html代码
  328. function getTenderTreeHtml () {
  329. if (tenderTree.length > 0) {
  330. const html = [];
  331. html.push('<table class="table table-hover table-bordered">');
  332. html.push('<thead>', '<tr>');
  333. html.push('<th>', '名称', '</th>');
  334. html.push('<th>', '计量模式', '</th>');
  335. html.push('<th>', '计量期数', '</th>');
  336. html.push('<th>', '审批状态', '</th>');
  337. html.push('<th>', '0号台帐', '</th>');
  338. html.push('<th>', '本期完成', '</th>');
  339. html.push('<th>', '截止本期合同', '</th>');
  340. html.push('<th>', '截止本期变更', '</th>');
  341. html.push('<th>', '截止本期完成', '</th>');
  342. html.push('<th>', '截止上期完成', '</th>');
  343. html.push('<th>', '本期应付', '</th>');
  344. html.push('<th>', '截止本期应付', '</th>');
  345. html.push('</tr>', '</thead>');
  346. for (const t of tenderTree) {
  347. html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
  348. }
  349. html.push('</table>');
  350. return html.join('');
  351. } else {
  352. return EmptyTenderHtml.join('');
  353. }
  354. }
  355. function bindTenderUrl() {
  356. $('a', '.c-body').bind('click', function () {
  357. const tenderId = parseInt($(this).attr('id'));
  358. const tender = _.find(tenders, function (t) {
  359. return t.id === tenderId;
  360. });
  361. if (tender.measure_type) {
  362. window.location.href = '/tender/' + tenderId;
  363. } else {
  364. for (const a of $('a', '#jlms')) {
  365. a.href = '/tender/' + tenderId + '/type?type=' + $(a).attr('mst');
  366. }
  367. $('#jlms').modal('show');
  368. }
  369. });
  370. }
  371. $(document).ready(() => {
  372. autoFlashHeight();
  373. sortCategory();
  374. // 初始化分类数据
  375. initCategoryLevelNode();
  376. $('.modal-body', '#add-bd').append(getCategoryHtml());
  377. // 初始化标段树结构
  378. initTenderTree();
  379. $('.c-body').html(getTenderTreeHtml());
  380. bindTenderUrl();
  381. // 分类
  382. $('#cate-set').on('show.bs.modal', function () {
  383. createTree();
  384. });
  385. $('#set-cate-ok').click(function () {
  386. const data = [];
  387. const zTree = $.fn.zTree.getZTreeObj('treeLevel');
  388. for (const c of category) {
  389. const node = zTree.getNodeByParam('id', c.id);
  390. const parent = node.getParentNode();
  391. if (parent.lid === 1) {
  392. data.push({id: c.id, level: 0});
  393. } else {
  394. data.push({id: c.id, level: node.getPath().length - 1});
  395. }
  396. }
  397. postData('/setting/category/level', data, function (rst) {
  398. for (const d of data) {
  399. const c = findNode('id', d.id, category);
  400. c.level = d.level;
  401. }
  402. sortCategory();
  403. initCategoryLevelNode();
  404. initTenderTree();
  405. $('.c-body').html(getTenderTreeHtml());
  406. $('#cate-set').modal('hide');
  407. });
  408. });
  409. // 新增标段
  410. $('#add-bd-ok').click(function () {
  411. const data = {
  412. name: $('[name=name]', '#add-bd').val(),
  413. valuation: $('[name=valuation]:checked').val(),
  414. category: [],
  415. };
  416. if (!data.name || data.name === '') {
  417. // TODO 提示用户
  418. return;
  419. }
  420. for (const c of category) {
  421. if (parseInt($('select', '[cate-id=' + c.id + ']').val()) !== 0) {
  422. const cate = {cid: c.id};
  423. // if (c.type === categoryType.key.dropDown) {
  424. cate.value = parseInt($('select', '[cate-id=' + c.id + ']').val());
  425. // } else if (c.type === categoryType.key.radio) {
  426. // cate.value = parseInt($('input:checked', '[cate-id=' + c.id + ']').val());
  427. // }
  428. data.category.push(cate);
  429. }
  430. }
  431. $('#hide-all').show();
  432. postData('/list/add', data, function (result) {
  433. tenders.push(result);
  434. initTenderTree();
  435. $('.c-body').html(getTenderTreeHtml());
  436. bindTenderUrl();
  437. $('#add-bd').modal('hide');
  438. $('[name=name]', '#add-bd').val('');
  439. $('#hide-all').hide();
  440. });
  441. });
  442. // 展开和收起
  443. $('body').on('click', '.fold-switch', function () {
  444. if ($(this).children('i').hasClass('fa-minus-square-o')) {
  445. $(this).children('i').removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
  446. $(this).attr('title', '展开');
  447. const cid = $(this).attr('cid');
  448. const node = findTenderTreeNode(parseInt(cid), tenderTree);
  449. doTrStatus(returnItem, 'hide');
  450. } else {
  451. $(this).children('i').removeClass('fa-plus-square-o').addClass('fa-minus-square-o');
  452. $(this).attr('title', '收起');
  453. const cid = $(this).attr('cid');
  454. const node = findTenderTreeNode(parseInt(cid), tenderTree);
  455. doTrStatus(returnItem, 'show');
  456. }
  457. })
  458. });
  459. function doTrStatus(node, status) {
  460. if (status === 'show') {
  461. $('.c-body').find('tr[pid="'+ node.sort_id +'"]').show();
  462. $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').attr('title', '收起');
  463. $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch i').removeClass('fa-plus-square-o').removeClass('fa-minus-square-o').addClass('fa-minus-square-o');
  464. } else {
  465. $('.c-body').find('tr[pid="'+ node.sort_id +'"]').hide();
  466. $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').attr('title', '展开');
  467. $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch i').removeClass('fa-minus-square-o').removeClass('fa-plus-square-o').addClass('fa-plus-square-o');
  468. }
  469. // 判断是否还有一层
  470. if (node.children) {
  471. for (const c of node.children) {
  472. doTrStatus(c, status);
  473. }
  474. }
  475. }
  476. let returnItem;
  477. const findTenderTreeNode = function(sortId, tree) {
  478. tree.forEach((item) => {
  479. if (item.sort_id !== undefined && item.sort_id === sortId) {
  480. returnItem = item;
  481. return item;
  482. } else if (item.children && item.children.length > 0) {
  483. findTenderTreeNode(sortId, item.children);
  484. }
  485. });
  486. }