tender_list_progress.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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. return true;
  74. }
  75. function onDropNode(event, treeId, treeNodes, targetNode, moveType) {
  76. const zTree = $.fn.zTree.getZTreeObj(treeId);
  77. function resetFixNode(id) {
  78. const node = zTree.getNodeByParam('lid', id);
  79. node.isParent = true;
  80. zTree.updateNode(node, false);
  81. zTree.expandNode(node, true);
  82. }
  83. function moveChildren(children, node) {
  84. if (!children || children.length === 0) { return }
  85. for (const c of children) {
  86. moveChildren(c.children, node);
  87. zTree.moveNode(node, c, 'inner');
  88. }
  89. }
  90. resetFixNode(1);
  91. resetFixNode(2);
  92. if (targetNode !== null && targetNode.lid === 1 && treeNodes[0].children && treeNodes[0].children.length !== 0) {
  93. moveChildren(treeNodes[0].children, zTree.getNodeByParam('lid', 1));
  94. } else if (targetNode !== null && targetNode.lid !== 1) {
  95. if (targetNode.children.length >= 2) {
  96. for (const c of targetNode.children) {
  97. if (c.lid !== treeNodes[0].lid) {
  98. zTree.moveNode(treeNodes[0], c, 'inner');
  99. }
  100. }
  101. }
  102. }
  103. }
  104. // 查询方法
  105. function findNode (key, value, arr) {
  106. for (const a of arr) {
  107. if (a[key] && a[key] === value) {
  108. return a;
  109. }
  110. }
  111. }
  112. function getPId(level) {
  113. if (level !== 1) {
  114. const p = findNode('level', level - 1, levelNodes);
  115. if (p) {
  116. return p.lid
  117. } else {
  118. return 1;
  119. }
  120. } else {
  121. return 2;
  122. }
  123. }
  124. // 分类数据排序
  125. function sortCategory() {
  126. category.sort(function (a, b) {
  127. return a.level ? (b.level ? a.level - b.level : -1) : a.id - b.id;
  128. });
  129. }
  130. // 初始化分类树结构数据
  131. function initCategoryLevelNode() {
  132. levelNodes.splice(0, levelNodes.length);
  133. levelNodes.push(
  134. { lid:1, lpId:0, name:"可用类别", open:true, isParent: true, drag: false},
  135. { lid:2, lpId:0, name:"已用类别", open:true, isParent: true, drag: false}
  136. );
  137. for (const c of category) {
  138. const cate = JSON.parse(JSON.stringify(c));
  139. cate.lid = levelNodes.length + 1;
  140. cate.open = true;
  141. cate.dropRoot = false;
  142. if (!cate.level) {
  143. cate.lpId = 1;
  144. levelNodes.push(cate);
  145. } else {
  146. cate.lpId = getPId(cate.level);
  147. levelNodes.push(cate);
  148. }
  149. }
  150. }
  151. // 新建标段 -- 分类属性选择
  152. function getCategoryHtml() {
  153. function getSelectCategoryHtml (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('<select class="form-control form-control-sm">');
  158. for (const v of cate.value) {
  159. html.push('<option value="' + v.id + '">', v.value, '</option>');
  160. }
  161. html.push('<option value="0">不选</option>');
  162. html.push('</select>');
  163. html.push('</div>');
  164. return html.join('');
  165. }
  166. function getRadioCategoryHtml (cate) {
  167. const html = [];
  168. html.push('<div class="form-group" cate-id="' + cate.id + '">');
  169. html.push('<lable>', cate.name, '</lable>');
  170. html.push('<div>');
  171. for (const iV in cate.value) {
  172. const v = cate.value[iV];
  173. html.push('<div class="form-check-inline">');
  174. html.push('<input class="form-check-input" type="radio"', 'name="' + cate.name + '" ', 'value="' , v.id, (iV == 0 ? '" checked="' : ''), '">');
  175. html.push('<label class="form-check-label">', v.value, '</label>');
  176. html.push('</div>');
  177. }
  178. html.push('</div>');
  179. html.push('</div>');
  180. return html.join('');
  181. }
  182. const html = [];
  183. for (const c of category) {
  184. // if (c.type === categoryType.key.dropDown) {
  185. html.push(getSelectCategoryHtml(c));
  186. // } else if (c.type === categoryType.key.radio) {
  187. // html.push(getRadioCategoryHtml(c));
  188. // }
  189. }
  190. return html.join('');
  191. }
  192. function calculateParent(node) {
  193. if (node.children && node.cid) {
  194. node.end_qc_tp = 0;
  195. node.pre_gather_tp = 0;
  196. node.gather_tp = 0;
  197. node.sum_tp = 0;
  198. node.lastStage = 0;
  199. node.contract_price = 0;
  200. for (const c of node.children) {
  201. calculateParent(c);
  202. node.end_qc_tp = ZhCalc.add(node.end_qc_tp, c.end_qc_tp);
  203. node.pre_gather_tp = ZhCalc.add(node.pre_gather_tp, c.pre_gather_tp);
  204. node.gather_tp = ZhCalc.add(node.gather_tp, c.gather_tp);
  205. node.sum_tp = ZhCalc.add(node.sum_tp, c.sum_tp);
  206. node.lastStage = c.cid
  207. ? Math.max(node.lastStage, c.lastStage)
  208. : (c.lastStage ? Math.max(node.lastStage, c.lastStage.order) : node.lastStage);
  209. node.contract_price = ZhCalc.add(node.contract_price, c.contract_price);
  210. }
  211. }
  212. }
  213. // 初始化TenderTree数据
  214. function initTenderTree () {
  215. const levelCategory = category.filter(function (c) {
  216. return c.level && c.level > 0;
  217. });
  218. function findCategoryNode(cid, value, array) {
  219. for (const a of array) {
  220. if (a.cid === cid && a.vid === value) {
  221. return a;
  222. }
  223. }
  224. }
  225. function getCategoryNode(category, value, parent, i = null) {
  226. const array = parent ? parent.children : tenderTree;
  227. let cate = findCategoryNode(category.id, value, array);
  228. if (!cate) {
  229. const cateValue = findNode('id', value, category.value);
  230. if (!cateValue) return null;
  231. cate = {
  232. cid: category.id,
  233. vid: value,
  234. name: cateValue.value,
  235. children: [],
  236. level: i ? i : category.level,
  237. sort_id: ++parentId,
  238. sort: cateValue.sort,
  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.end_qc_tp = ZhCalc.sum([tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp, tender.lastStage.qc_pc_tp]);
  265. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  266. tender.gather_tp = ZhCalc.sum([tender.lastStage.contract_tp, tender.lastStage.qc_tp, tender.lastStage.pc_tp]);
  267. tender.sum_tp = ZhCalc.add(tender.total_price, tender.end_qc_tp);
  268. } else {
  269. tender.sum_tp = tender.total_price;
  270. }
  271. }
  272. tenderTree.splice(0, tenderTree.length);
  273. for (const t of tenders) {
  274. calculateTender(t);
  275. t.valid = true;
  276. delete t.level;
  277. if (t.category && levelCategory.length > 0) {
  278. const parent = loadTenderCategory(t);
  279. if (parent) {
  280. t.level = parent.level + 1;
  281. parent.children.push(t);
  282. } else {
  283. tenderTree.push(t);
  284. }
  285. } else {
  286. tenderTree.push(t);
  287. }
  288. }
  289. sortTenderTree();
  290. for (const t of tenderTree) {
  291. calculateParent(t);
  292. }
  293. }
  294. function getProgressHtml(total, pre, cur) {
  295. if (total !== 0) {
  296. let preP = ZhCalc.mul(ZhCalc.div(pre, total, 2), 100, 0);
  297. let curP = ZhCalc.mul(ZhCalc.div(cur, total, 2), 100, 0);
  298. let other = Math.max(ZhCalc.sub(ZhCalc.sub(total, pre), cur), 0);
  299. let otherP = Math.max(100 - preP - curP, 0);
  300. const html = '<div class="progress">' +
  301. '<div class="progress-bar bg-success" style="width: ' + preP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="截止上期完成:¥' + (pre || 0) + '">' + preP + '%</div>' +
  302. '<div class="progress-bar bg-info" style="width: ' + curP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="本期完成:¥' + (cur || 0) + '">' + curP + '%</div>' +
  303. '<div class="progress-bar bg-gray" style="width: ' + otherP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="未完成:¥' + (other || 0) + '">' + otherP + '%</div>' +
  304. '</div>';
  305. return html;
  306. } else {
  307. return '';
  308. }
  309. }
  310. function recursiveGetTenderNodeHtml (node, arr, pid) {
  311. const html = [];
  312. html.push('<tr pid="' + pid + '">');
  313. // 名称
  314. html.push('<td width="25%" class="in-' + node.level + '">');
  315. if (node.cid) {
  316. 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);
  317. } else {
  318. html.push('<span class="text-muted mr-2">');
  319. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  320. html.push('</span>');
  321. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  322. html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');
  323. }
  324. html.push('</td>');
  325. // 计量进度
  326. html.push('<td style="width: 8%">');
  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: 8%">');
  333. if (!node.cid && node.cur_flow) {
  334. html.push(node.cur_flow.name + ' ' + '<span class="' + node.cur_flow.status_class +'">' + node.cur_flow.status + '</span>');
  335. }
  336. html.push('</td>');
  337. // 上一流程审批时间
  338. html.push('<td style="width: 8%">');
  339. if (!node.cid && node.pre_flow) {
  340. html.push(node.pre_flow.name + ' ' + moment(node.pre_flow.time).format('YYYY-MM-DD'));
  341. }
  342. html.push('</td>');
  343. // 签约合同价
  344. html.push('<td width="8%" class="text-right">');
  345. html.push(node.contract_price ? node.contract_price : '');
  346. html.push('</td>');
  347. // 总价
  348. html.push('<td width="8%" class="text-right">');
  349. html.push(node.sum_tp ? node.sum_tp : '');
  350. html.push('</td>');
  351. // 截止本期累计完成/本期完成/未完成
  352. html.push('<td>');
  353. if (node.lastStage) {
  354. html.push(getProgressHtml(node.sum_tp, node.pre_gather_tp, node.gather_tp));
  355. } else {
  356. html.push('');
  357. }
  358. html.push('</td>');
  359. html.push('</tr>');
  360. if (node.children) {
  361. for (const c of node.children) {
  362. html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));
  363. }
  364. }
  365. return html.join('');
  366. }
  367. // 根据TenderTree数据获取Html代码
  368. function getTenderTreeHtml () {
  369. if (tenderTree.length > 0) {
  370. const html = [];
  371. html.push('<table class="table table-hover table-bordered">');
  372. html.push('<thead style="position: fixed;left:56px;top: 34px;">', '<tr>');
  373. html.push('<th style="width: 25%" class="text-center">', '标段名称', '</th>');
  374. html.push('<th class="text-center" style="width: 8%">', '计量进度', '</th>');
  375. html.push('<th class="text-center" style="width: 8%">', '当前流程', '</th>');
  376. html.push('<th class="text-center" style="width: 8%">', '上一流程审批时间', '</th>');
  377. html.push('<th class="text-center" style="width: 8%">', '签约合同价', '</th>');
  378. html.push('<th style="width: 8%" class="text-center">', '总价 <i class="fa fa-question-circle text-primary" data-placement="bottom" data-toggle="tooltip" data-original-title="0号台账+截止本期数量变更"></i>', '</th>');
  379. html.push('<th style="width: 35%" class="text-center">', '截止上期完成/本期完成/未完成', '</th>');
  380. html.push('</tr>', '</thead>');
  381. parentId = 0;
  382. for (const t of tenderTree) {
  383. html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
  384. }
  385. html.push('</table>');
  386. return html.join('');
  387. } else {
  388. return EmptyTenderHtml.join('');
  389. }
  390. }
  391. function bindTenderUrl() {
  392. $('.c-body').on('click', 'a', function () {
  393. const tenderId = parseInt($(this).attr('id'));
  394. const tender = _.find(tenders, function (t) {
  395. return t.id === tenderId;
  396. });
  397. if (!tender) return;
  398. if (!tender.measure_type && tender.user_id !== userID) return;
  399. if (tender.measure_type) {
  400. // window.location.href = '/tender/' + tenderId;
  401. window.open('/tender/' + tenderId, '_blank');
  402. } else {
  403. for (const a of $('a', '#jlms')) {
  404. a.href = '/tender/' + tenderId + '/type?type=' + $(a).attr('mst');
  405. }
  406. $('#jlms').modal('show');
  407. }
  408. });
  409. }
  410. $(document).ready(() => {
  411. autoFlashHeight();
  412. sortCategory();
  413. // 初始化分类数据
  414. initCategoryLevelNode();
  415. $('.modal-body', '#add-bd').append(getCategoryHtml());
  416. // 初始化标段树结构
  417. initTenderTree();
  418. $('.c-body').html(getTenderTreeHtml());
  419. bindTenderUrl();
  420. localHideList();
  421. tenderTreeShowLevel.initShowLevel();
  422. // 分类
  423. $('#cate-set').on('show.bs.modal', function () {
  424. createTree();
  425. });
  426. $('#set-cate-ok').click(function () {
  427. const data = [];
  428. const zTree = $.fn.zTree.getZTreeObj('treeLevel');
  429. for (const c of category) {
  430. const node = zTree.getNodeByParam('id', c.id);
  431. const parent = node.getParentNode();
  432. if (parent.lid === 1) {
  433. data.push({id: c.id, level: 0});
  434. } else {
  435. data.push({id: c.id, level: node.getPath().length - 1});
  436. }
  437. }
  438. postData('/setting/category/level', data, function (rst) {
  439. for (const d of data) {
  440. const c = findNode('id', d.id, category);
  441. c.level = d.level;
  442. }
  443. sortCategory();
  444. initCategoryLevelNode();
  445. initTenderTree();
  446. $('.c-body').html(getTenderTreeHtml());
  447. localHideList();
  448. $('#cate-set').modal('hide');
  449. tenderTreeShowLevel.refreshMenuVisible();
  450. });
  451. });
  452. // 新增标段
  453. $('#add-bd-ok').click(function () {
  454. const data = {
  455. name: cleanSymbols($('[name=name]', '#add-bd').val()),
  456. valuation: $('[name=valuation]:checked').val(),
  457. category: [],
  458. };
  459. if (!data.name || data.name === '') {
  460. // TODO 提示用户
  461. return;
  462. }
  463. for (const c of category) {
  464. if (parseInt($('select', '[cate-id=' + c.id + ']').val()) !== 0) {
  465. const cate = {cid: c.id};
  466. // if (c.type === categoryType.key.dropDown) {
  467. cate.value = parseInt($('select', '[cate-id=' + c.id + ']').val());
  468. // } else if (c.type === categoryType.key.radio) {
  469. // cate.value = parseInt($('input:checked', '[cate-id=' + c.id + ']').val());
  470. // }
  471. data.category.push(cate);
  472. }
  473. }
  474. postData('/list/add', data, function (result) {
  475. tenders.push(result);
  476. initTenderTree();
  477. $('.c-body').html(getTenderTreeHtml());
  478. bindTenderUrl();
  479. localHideList();
  480. $('#add-bd').modal('hide');
  481. $('[name=name]', '#add-bd').val('');
  482. });
  483. });
  484. });