tender_list_info.js 17 KB

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