list.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. };
  85. array.push(cate);
  86. }
  87. return cate;
  88. }
  89. function loadTenderCategory (tender) {
  90. let tenderCategory = null;
  91. for (const [index, lc] of levelCategory.entries()) {
  92. const tenderCate = findNode('cid', lc.id, tender.category);
  93. if (tenderCate) {
  94. tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
  95. } else {
  96. if (index === 0 && tender.category) {
  97. for (const [i,c] of tender.category.entries()) {
  98. const cate = findNode('id', c.cid, category);
  99. tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
  100. }
  101. }
  102. return tenderCategory;
  103. }
  104. }
  105. return tenderCategory;
  106. }
  107. function calculateTender(tender) {
  108. if (tender.lastStage) {
  109. tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp);
  110. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  111. tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp);
  112. tender.sum_tp = ZhCalc.add(tender.total_price, tender.end_qc_tp);
  113. } else {
  114. tender.sum_tp = tender.total_price;
  115. }
  116. }
  117. tenderTree.splice(0, tenderTree.length);
  118. for (const t of tenders) {
  119. calculateTender(t);
  120. t.valid = true;
  121. delete t.level;
  122. if (t.category && levelCategory.length > 0) {
  123. const parent = loadTenderCategory(t);
  124. if (parent) {
  125. t.level = parent.level + 1;
  126. parent.children.push(t);
  127. } else {
  128. tenderTree.push(t);
  129. }
  130. } else {
  131. tenderTree.push(t);
  132. }
  133. }
  134. for (const t of tenderTree) {
  135. calculateParent(t);
  136. }
  137. }
  138. function getProgressHtml(total, pre, cur) {
  139. if (total !== 0) {
  140. let preP = ZhCalc.mul(ZhCalc.div(pre, total, 2), 100, 0);
  141. let curP = ZhCalc.mul(ZhCalc.div(cur, total, 2), 100, 0);
  142. let other = Math.max(ZhCalc.sub(ZhCalc.sub(total, pre), cur), 0);
  143. let otherP = Math.max(100 - preP - curP, 0);
  144. const html = '<div class="progress">' +
  145. '<div class="progress-bar bg-success" style="width: ' + preP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="截止上期完成:¥' + pre + '">' + preP + '%</div>' +
  146. '<div class="progress-bar bg-info" style="width: ' + curP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="本期完成:¥' + cur + '">' + curP + '%</div>' +
  147. '<div class="progress-bar bg-gray" style="width: ' + otherP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="未完成:¥' + other + '">' + otherP + '%</div>' +
  148. '</div>';
  149. return html;
  150. } else {
  151. return '';
  152. }
  153. }
  154. function recursiveGetTenderNodeHtml (node, arr, pid) {
  155. const html = [];
  156. html.push('<tr pid="' + pid + '">');
  157. // 名称
  158. if (node.cid) {
  159. html.push('<td class="in-' + node.level + '">');
  160. 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);
  161. html.push('</td><td></td><td></td>');
  162. } else {
  163. html.push('<td colspan="3" class="in-' + node.level + '">');
  164. html.push('<div class="row">');
  165. html.push('<span class="col-8">');
  166. html.push('<span class="text-muted mr-2">');
  167. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  168. html.push('</span>');
  169. html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a></span>');
  170. html.push('<span class="col-auto ml-auto"></span>');
  171. html.push('</div>');
  172. html.push('<div class="d-flex justify-content-between"><span>');
  173. // 计量期数
  174. if (!node.cid) {
  175. html.push(node.lastStage ? '第' + node.lastStage.order + '期' : '台账');
  176. }
  177. html.push('</span><span>');
  178. // 累计合同计量
  179. const sum = node.lastStage ? ZhCalc.add(node.total_price, node.lastStage.end_qc_tp) : node.total_price;
  180. html.push(node.sum_tp ? node.sum_tp : '');
  181. html.push('</span></div>');
  182. // 截止本期累计完成/本期完成/未完成
  183. if (node.lastStage) {
  184. html.push(getProgressHtml(node.sum_tp, node.pre_gather_tp, node.gather_tp));
  185. } else {
  186. html.push('');
  187. }
  188. html.push('</td>');
  189. }
  190. html.push('</tr>');
  191. if (node.children) {
  192. for (const c of node.children) {
  193. html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));
  194. }
  195. }
  196. return html.join('');
  197. }
  198. // 根据TenderTree数据获取Html代码
  199. function getTenderTreeHtml () {
  200. const html = [];
  201. html.push('<table class="table">');
  202. html.push('<thead>', '<tr>');
  203. html.push('<th>名称</th>');
  204. html.push('<th width="120">计量期数</th>');
  205. html.push('<th>总价</th>');
  206. html.push('</tr>', '</thead>');
  207. if (tenderTree.length > 0) {
  208. parentId = 0;
  209. for (const t of tenderTree) {
  210. html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
  211. }
  212. } else {
  213. html.push(EmptyTenderHtml.join(''));
  214. }
  215. html.push('</table>');
  216. return html.join('');
  217. }
  218. function bindTenderUrl() {
  219. $('.c-body').on('click', 'a', function () {
  220. const tenderId = parseInt($(this).attr('id'));
  221. const tender = _.find(tenders, function (t) {
  222. return t.id === tenderId;
  223. });
  224. if (tender.measure_type) {
  225. window.location.href = '/wap/tender/' + tenderId;
  226. } else {
  227. // for (const a of $('a', '#jlms')) {
  228. // a.href = '/wap/tender/' + tenderId + '/type?type=' + $(a).attr('mst');
  229. // }
  230. // $('#jlms').modal('show');
  231. }
  232. });
  233. }
  234. $(document).ready(() => {
  235. // 初始化标段树结构
  236. sortCategory();
  237. initTenderTree();
  238. $('.c-body').html(getTenderTreeHtml());
  239. bindTenderUrl();
  240. localHideList(true);
  241. });