list.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/10/11
  7. * @version
  8. */
  9. const EmptyTenderHtml = [
  10. '',
  11. ];
  12. const tenderTree = [];
  13. let parentId = 0;
  14. // 查询方法
  15. function findNode (key, value, arr) {
  16. for (const a of arr) {
  17. if (a[key] && a[key] === value) {
  18. return a;
  19. }
  20. }
  21. }
  22. function getPId(level) {
  23. if (level !== 1) {
  24. const p = findNode('level', level - 1, levelNodes);
  25. if (p) {
  26. return p.lid
  27. } else {
  28. return 1;
  29. }
  30. } else {
  31. return 2;
  32. }
  33. }
  34. // 分类数据排序
  35. function sortCategory() {
  36. category.sort(function (a, b) {
  37. return a.level ? (b.level ? a.level - b.level : -1) : a.id - b.id;
  38. });
  39. }
  40. function calculateParent(node) {
  41. if (node.children && node.cid) {
  42. node.end_qc_tp = 0;
  43. node.pre_gather_tp = 0;
  44. node.gather_tp = 0;
  45. node.sum_tp = 0;
  46. node.lastStage = 0;
  47. for (const c of node.children) {
  48. calculateParent(c);
  49. node.end_qc_tp = ZhCalc.add(node.end_qc_tp, c.end_qc_tp);
  50. node.pre_gather_tp = ZhCalc.add(node.pre_gather_tp, c.pre_gather_tp);
  51. node.gather_tp = ZhCalc.add(node.gather_tp, c.gather_tp);
  52. node.sum_tp = ZhCalc.add(node.sum_tp, c.sum_tp);
  53. node.lastStage = c.cid
  54. ? Math.max(node.lastStage, c.lastStage)
  55. : (c.lastStage ? Math.max(node.lastStage, c.lastStage.order) : node.lastStage);
  56. }
  57. }
  58. }
  59. // 初始化TenderTree数据
  60. function initTenderTree () {
  61. const levelCategory = category.filter(function (c) {
  62. return c.level && c.level > 0;
  63. });
  64. function findCategoryNode(cid, value, array) {
  65. for (const a of array) {
  66. if (a.cid === cid && a.vid === value) {
  67. return a;
  68. }
  69. }
  70. }
  71. function getCategoryNode(category, value, parent, i = null) {
  72. const array = parent ? parent.children : tenderTree;
  73. let cate = findCategoryNode(category.id, value, array);
  74. if (!cate) {
  75. const cateValue = findNode('id', value, category.value);
  76. if (!cateValue) return null;
  77. cate = {
  78. cid: category.id,
  79. vid: value,
  80. name: cateValue.value,
  81. children: [],
  82. level: i ? i : category.level,
  83. sort_id: ++parentId,
  84. sort: cateValue.sort,
  85. };
  86. array.push(cate);
  87. }
  88. return cate;
  89. }
  90. function loadTenderCategory (tender) {
  91. let tenderCategory = null;
  92. for (const [index, lc] of levelCategory.entries()) {
  93. const tenderCate = findNode('cid', lc.id, tender.category);
  94. if (tenderCate) {
  95. tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
  96. } else {
  97. if (index === 0 && tender.category) {
  98. for (const [i,c] of tender.category.entries()) {
  99. const cate = findNode('id', c.cid, category);
  100. tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
  101. }
  102. }
  103. return tenderCategory;
  104. }
  105. }
  106. return tenderCategory;
  107. }
  108. function calculateTender(tender) {
  109. if (tender.lastStage) {
  110. tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp);
  111. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  112. tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp);
  113. tender.sum_tp = ZhCalc.add(tender.total_price, tender.end_qc_tp);
  114. } else {
  115. tender.sum_tp = tender.total_price;
  116. }
  117. }
  118. tenderTree.splice(0, tenderTree.length);
  119. for (const t of tenders) {
  120. calculateTender(t);
  121. t.valid = true;
  122. delete t.level;
  123. if (t.category && levelCategory.length > 0) {
  124. const parent = loadTenderCategory(t);
  125. if (parent) {
  126. t.level = parent.level + 1;
  127. parent.children.push(t);
  128. } else {
  129. tenderTree.push(t);
  130. }
  131. } else {
  132. tenderTree.push(t);
  133. }
  134. }
  135. sortTenderTree();
  136. for (const t of tenderTree) {
  137. calculateParent(t);
  138. }
  139. }
  140. function getProgressHtml(total, pre, cur) {
  141. if (total !== 0) {
  142. let preP = ZhCalc.mul(ZhCalc.div(pre, total, 2), 100, 0);
  143. let curP = ZhCalc.mul(ZhCalc.div(cur, total, 2), 100, 0);
  144. let other = Math.max(ZhCalc.sub(ZhCalc.sub(total, pre), cur), 0);
  145. let otherP = Math.max(100 - preP - curP, 0);
  146. const html = '<div class="progress">' +
  147. '<div class="progress-bar bg-success" style="width: ' + preP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="截止上期完成:¥' + pre + '">' + preP + '%</div>' +
  148. '<div class="progress-bar bg-info" style="width: ' + curP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="本期完成:¥' + cur + '">' + curP + '%</div>' +
  149. '<div class="progress-bar bg-gray" style="width: ' + otherP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="未完成:¥' + other + '">' + otherP + '%</div>' +
  150. '</div>';
  151. return html;
  152. } else {
  153. return '';
  154. }
  155. }
  156. function recursiveGetTenderNodeHtml (node, arr, pid) {
  157. const html = [];
  158. html.push('<tr pid="' + pid + '">');
  159. // 名称
  160. if (node.cid) {
  161. html.push('<td class="in-' + node.level + '">');
  162. 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);
  163. html.push('</td><td></td><td></td>');
  164. } else {
  165. html.push('<td colspan="3" class="in-' + node.level + '">');
  166. html.push('<div class="row">');
  167. html.push('<span class="col-8">');
  168. html.push('<span class="text-muted mr-2">');
  169. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  170. html.push('</span>');
  171. html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a></span>');
  172. html.push('<span class="col-auto ml-auto"></span>');
  173. html.push('</div>');
  174. html.push('<div class="d-flex justify-content-between"><span>');
  175. // 计量期数
  176. if (!node.cid) {
  177. html.push(node.lastStage ? '第' + node.lastStage.order + '期' : '台账');
  178. }
  179. html.push('</span><span>');
  180. // 累计合同计量
  181. const sum = node.lastStage ? ZhCalc.add(node.total_price, node.lastStage.end_qc_tp) : node.total_price;
  182. html.push(node.sum_tp ? node.sum_tp : '');
  183. html.push('</span></div>');
  184. // 截止本期累计完成/本期完成/未完成
  185. if (node.lastStage) {
  186. html.push(getProgressHtml(node.sum_tp, node.pre_gather_tp, node.gather_tp));
  187. } else {
  188. html.push('');
  189. }
  190. html.push('</td>');
  191. }
  192. html.push('</tr>');
  193. if (node.children) {
  194. for (const c of node.children) {
  195. html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));
  196. }
  197. }
  198. return html.join('');
  199. }
  200. // 根据TenderTree数据获取Html代码
  201. function getTenderTreeHtml () {
  202. const html = [];
  203. html.push('<table class="table">');
  204. html.push('<thead>', '<tr>');
  205. html.push('<th>名称</th>');
  206. html.push('<th width="120">计量期数</th>');
  207. html.push('<th>总价</th>');
  208. html.push('</tr>', '</thead>');
  209. if (tenderTree.length > 0) {
  210. parentId = 0;
  211. for (const t of tenderTree) {
  212. html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
  213. }
  214. } else {
  215. html.push(EmptyTenderHtml.join(''));
  216. }
  217. html.push('</table>');
  218. return html.join('');
  219. }
  220. function bindTenderUrl() {
  221. $('.c-body').on('click', 'a', function () {
  222. const tenderId = parseInt($(this).attr('id'));
  223. const tender = _.find(tenders, function (t) {
  224. return t.id === tenderId;
  225. });
  226. if (tender.measure_type) {
  227. window.location.href = '/wap/tender/' + tenderId;
  228. } else {
  229. // for (const a of $('a', '#jlms')) {
  230. // a.href = '/wap/tender/' + tenderId + '/type?type=' + $(a).attr('mst');
  231. // }
  232. // $('#jlms').modal('show');
  233. }
  234. });
  235. }
  236. $(document).ready(() => {
  237. // 初始化标段树结构
  238. sortCategory();
  239. initTenderTree();
  240. $('.c-body').html(getTenderTreeHtml());
  241. bindTenderUrl();
  242. localHideList(true);
  243. });