list.js 9.4 KB

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