budget_info.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. $(document).ready(() => {
  10. autoFlashHeight();
  11. const compareObj = {
  12. curFinalId() {
  13. return this.finalInfo ? this.finalInfo.id : undefined;
  14. },
  15. expand(tree, tag) {
  16. switch (tag) {
  17. case "1":
  18. case "2":
  19. case "3":
  20. case "4":
  21. case "5":
  22. tree.expandByLevel(parseInt(tag));
  23. break;
  24. case "last":
  25. tree.expandByCustom(() => { return true; });
  26. break;
  27. }
  28. },
  29. calcStackedBar(tree) {
  30. const calcField = this.stackedBarField;
  31. const calcFieldColor = { 'gu_tp': '#657798', 'gai_tp': '#EE6666', 'yu_tp': '#74CBED', 'total_price': '#FAC858', 'final_tp': '#62DAAB' };
  32. const calcFieldCaption = { 'gu_tp': '估算', 'gai_tp': '概算', 'yu_tp': '预算', 'total_price': '台账', 'final_tp': '决算' };
  33. const calc = function(node, base){
  34. // const parent = tree.getParent(node);
  35. // if (!parent) {
  36. // base = 0;
  37. // for (const cf of calcField) {
  38. // base = Math.max(node[cf], base);
  39. // }
  40. // }
  41. node.stackedBar = [];
  42. node.stackedBarTips = [];
  43. for (const cf of calcField) {
  44. node.stackedBar.push({color: calcFieldColor[cf], percent: ZhCalc.div(node[cf], base), field: cf});
  45. node.stackedBarTips.push(`${calcFieldCaption[cf]}: ${node[cf] || 0}`);
  46. }
  47. if (node.children) {
  48. for (const child of node.children) {
  49. calc(child, base);
  50. }
  51. }
  52. };
  53. let commonBase = 0;
  54. tree.children.forEach(x => {
  55. for (const cf of calcField) {
  56. commonBase = Math.max(x[cf] || 0, commonBase);
  57. }
  58. });
  59. for (const child of tree.children) {
  60. calc(child, commonBase);
  61. }
  62. },
  63. loadBudgetData(result) {
  64. const compareTree = createNewPathTree('final', {
  65. id: 'id',
  66. pid: 'pid',
  67. order: 'order',
  68. level: 'level',
  69. rootId: -1,
  70. });
  71. const setting = { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] };
  72. const guTree = createNewPathTree('ledger', setting);
  73. guTree.loadDatas(result.gu);
  74. treeCalc.calculateAll(guTree);
  75. compareTree.loadTree(guTree, function (cur, source) {
  76. cur.base = true;
  77. cur.gu_dgn_qty1 = ZhCalc.add(cur.gu_dgn_qty1, source.dgn_qty1);
  78. cur.gu_dgn_qty2 = ZhCalc.add(cur.gu_dgn_qty2, source.dgn_qty2);
  79. cur.gu_tp = ZhCalc.add(cur.gu_tp, source.total_price);
  80. });
  81. const gaiTree = createNewPathTree('ledger', setting);
  82. gaiTree.loadDatas(result.gai);
  83. treeCalc.calculateAll(gaiTree);
  84. compareTree.loadTree(gaiTree, function (cur, source) {
  85. cur.base = true;
  86. cur.gai_dgn_qty1 = ZhCalc.add(cur.gai_dgn_qty1, source.dgn_qty1);
  87. cur.gai_dgn_qty2 = ZhCalc.add(cur.gai_dgn_qty2, source.dgn_qty2);
  88. cur.gai_tp = ZhCalc.add(cur.gai_tp, source.total_price);
  89. });
  90. const yuTree = createNewPathTree('ledger', setting);
  91. yuTree.loadDatas(result.yu);
  92. treeCalc.calculateAll(yuTree);
  93. compareTree.loadTree(yuTree, function (cur, source) {
  94. cur.base = true;
  95. cur.yu_dgn_qty1 = ZhCalc.add(cur.yu_dgn_qty1, source.dgn_qty1);
  96. cur.yu_dgn_qty2 = ZhCalc.add(cur.yu_dgn_qty2, source.dgn_qty2);
  97. cur.yu_tp = ZhCalc.add(cur.yu_tp, source.total_price);
  98. });
  99. compareTree.afterLoad(node => {
  100. node.gu_dgn_price = ZhCalc.div(node.gu_tp, node.gu_dgn_qty1, 2);
  101. node.gu_dgn_qty = node.gu_dgn_qty1
  102. ? (node.gu_dgn_qty2 ? node.gu_dgn_qty1 + '/' + node.gu_dgn_qty2 : node.gu_dgn_qty1)
  103. : (node.gu_dgn_qty2 ? '/' + node.gu_dgn_qty2 : '');
  104. node.gai_dgn_price = ZhCalc.div(node.gai_tp, node.gai_dgn_qty1, 2);
  105. node.gai_dgn_qty = node.gai_dgn_qty1
  106. ? (node.gai_dgn_qty2 ? node.gai_dgn_qty1 + '/' + node.gai_dgn_qty2 : node.gai_dgn_qty1)
  107. : (node.gai_dgn_qty2 ? '/' + node.gai_dgn_qty2 : '');
  108. node.yu_dgn_price = ZhCalc.div(node.yu_tp, node.yu_dgn_qty1, 2);
  109. node.yu_dgn_qty = node.yu_dgn_qty1
  110. ? (node.yu_dgn_qty2 ? node.yu_dgn_qty1 + '/' + node.yu_dgn_qty2 : node.yu_dgn_qty1)
  111. : (node.yu_dgn_qty2 ? '/' + node.yu_dgn_qty2 : '');
  112. });
  113. compareTree.resortChildrenByCustom(function (x, y) {
  114. const iCode = compareCode(x.code, y.code);
  115. if (iCode) return iCode;
  116. if (!x.name) return -1;
  117. if (!y.name) return 1;
  118. return x.name.localeCompare(y.name);
  119. });
  120. const expandTag = getLocalCache('revise-compare-level');
  121. if (expandTag) compareObj.expand(compareTree, expandTag);
  122. this.calcStackedBar(compareTree);
  123. // console.log(compareTree);
  124. setPageData(compareTree);
  125. },
  126. loadFinalData(result, msg) {
  127. if (msg) toastr.warning(msg);
  128. this.finalInfo = result.finalInfo;
  129. const finalTree = createNewPathTree('ledger', {
  130. id: 'tree_id',
  131. pid: 'tree_pid',
  132. order: 'order',
  133. level: 'level',
  134. rootId: -1,
  135. });
  136. finalTree.loadDatas(result.final);
  137. const expandTag = getLocalCache('revise-compare-level');
  138. if (expandTag) compareObj.expand(finalTree, expandTag);
  139. this.calcStackedBar(finalTree);
  140. // console.log(finalTree);
  141. setPageData(finalTree);
  142. },
  143. loadCacheData(){
  144. const stackedBarCache = 'gai_tp,total_price,final_tp';
  145. this.setStackedBarField(stackedBarCache.split(','));
  146. },
  147. setStackedBarField(field){
  148. this.stackedBarField = field;
  149. },
  150. };
  151. compareObj.loadCacheData();
  152. function compareCode(str1, str2, symbol = '-') {
  153. if (!str1) {
  154. return 1;
  155. } else if (!str2) {
  156. return -1;
  157. }
  158. function compareSubCode(code1, code2) {
  159. if (numReg.test(code1)) {
  160. if (numReg.test(code2)) {
  161. return parseInt(code1) - parseInt(code2);
  162. } else {
  163. return -1
  164. }
  165. } else {
  166. if (numReg.test(code2)) {
  167. return 1;
  168. } else {
  169. return code1 === code2 ? 0 : (code1 < code2 ? -1 : 1); //code1.localeCompare(code2);
  170. }
  171. }
  172. }
  173. const numReg = /^[0-9]+$/;
  174. const aCodes = str1.split(symbol), bCodes = str2.split(symbol);
  175. for (let i = 0, iLength = Math.min(aCodes.length, bCodes.length); i < iLength; ++i) {
  176. const iCompare = compareSubCode(aCodes[i], bCodes[i]);
  177. if (iCompare !== 0) {
  178. return iCompare;
  179. }
  180. }
  181. return aCodes.length - bCodes.length;
  182. }
  183. postData(window.location.pathname + '/compare/load', {}, function (result, msg) {
  184. if (result.final) {
  185. compareObj.loadFinalData(result, msg);
  186. } else {
  187. compareObj.loadBudgetData(result);
  188. }
  189. });
  190. //金额对比
  191. var chartDom = document.getElementById('jlchart2');
  192. var myChart = echarts.init(chartDom);
  193. var option = {
  194. tooltip: {
  195. trigger: 'axis',
  196. },
  197. grid: {
  198. left: '3%',
  199. right: '3%',
  200. bottom: '4%',
  201. containLabel: true
  202. },
  203. xAxis: {
  204. type: 'category',
  205. data: ['投资估算', '设计概算', '施工图预算', '台账', '变更后台账', '预估决算']
  206. },
  207. yAxis: {
  208. type: 'value'
  209. },
  210. series: [
  211. {
  212. data: [0, 0, 0, 0, 0, 0],
  213. type: 'bar',
  214. showBackground: true,
  215. backgroundStyle: {
  216. color: 'rgba(180, 180, 180, 0.2)'
  217. },
  218. itemStyle:{
  219. borderRadius: [30, 30, 0, 0]
  220. },
  221. barWidth : 30
  222. }
  223. ],
  224. color:{
  225. type: 'linear',
  226. x: 0,
  227. y: 0,
  228. x2: 0,
  229. y2: 1,
  230. colorStops: [{
  231. offset: 0, color: '#3A6FB5' // 0% 处的颜色
  232. }, {
  233. offset: 1, color: '#44BEE3' // 100% 处的颜色
  234. }],
  235. global: false // 缺省为 false
  236. }
  237. };
  238. //全过程造价趋势
  239. var chartDom2 = document.getElementById('jlchart3');
  240. var myChart2 = echarts.init(chartDom2);
  241. var option2 = {
  242. title: {
  243. text: ''
  244. },
  245. tooltip: {
  246. trigger: 'axis'
  247. },
  248. legend: {
  249. },
  250. grid: {
  251. left: '3%',
  252. right: '5%',
  253. bottom: '3%',
  254. containLabel: true
  255. },
  256. xAxis: {
  257. type: 'category',
  258. boundaryGap: false,
  259. data: ['投资估算', '设计概算', '施工图预算', '台账金额', '预估决算']
  260. },
  261. yAxis: {
  262. type: 'value'
  263. },
  264. series: []
  265. };
  266. function setPageData(tree) {
  267. console.log(tree);
  268. if (tree.children.length > 0) {
  269. const level2List = tree.children[0].children;
  270. if (level2List.length > 0) {
  271. let jianAnHtml = '';
  272. for (const level2 of level2List) {
  273. jianAnHtml += `<tr>
  274. <td class="text-left pl-3">${level2.name}</td>
  275. <td>${level2.gai_tp ? ZhCalc.div(level2.gai_tp, 10000) : 0}</td>
  276. <td>${level2.final_tp ? ZhCalc.div(level2.final_tp, 10000) : 0}</td>
  277. <td class="${level2.gai_tp !== 0 ? (ZhCalc.sub(level2.final_tp, level2.gai_tp) > 0 ? 'text-danger' : ZhCalc.sub(level2.final_tp, level2.gai_tp) === 0 ? '' : 'text-success') : ''}">${level2.gai_tp ? ZhCalc.round(ZhCalc.mul(ZhCalc.div(ZhCalc.sub(level2.final_tp, level2.gai_tp), level2.gai_tp), 100), 2) : 0}</td>
  278. </tr>`;
  279. }
  280. $('#jianan-table').html(jianAnHtml);
  281. }
  282. // 分析第一层结构,获取各个部分金额非全0的及除了回收金额层
  283. const level1List = _.filter(tree.children, function (item) {
  284. return item.name.indexOf('回收金额') === -1 &&
  285. (item.gu_tp || item.gai_tp || (item.final_tp !== undefined && item.final_tp) || item.yu_tp || (item.total_price !== undefined && item.total_price))
  286. });
  287. // 回收金额
  288. const huishouInfo = _.find(tree.children, function (item) {
  289. return item.name.indexOf('回收金额') !== -1 && (item.gu_tp || item.gai_tp || (item.final_tp !== undefined && item.final_tp) || item.yu_tp || (item.total_price !== undefined && item.total_price))
  290. });
  291. let total_rate = 0, total_gai_tp = 0, total_gu_tp = 0, total_yu_tp = 0, total_price = 0, total_final_tp = 0;
  292. if (level1List.length > 0) {
  293. if (huishouInfo) {
  294. total_gai_tp = ZhCalc.sub(ZhCalc.sum(_.map(level1List, 'gai_tp')), huishouInfo.gai_tp);
  295. total_final_tp = ZhCalc.sub(ZhCalc.sum(_.map(level1List, 'final_tp')), huishouInfo.final_tp);
  296. total_gu_tp = ZhCalc.sub(ZhCalc.sum(_.map(level1List, 'gu_tp')), huishouInfo.gu_tp);
  297. total_yu_tp = ZhCalc.sub(ZhCalc.sum(_.map(level1List, 'yu_tp')), huishouInfo.yu_tp);
  298. total_price = ZhCalc.sub(ZhCalc.sum(_.map(level1List, 'total_price')), huishouInfo.total_price);
  299. total_rate = ZhCalc.div(ZhCalc.sub(total_final_tp, total_gai_tp), total_gai_tp);
  300. $('#total_gai_tp').text(total_gai_tp ? ZhCalc.div(total_gai_tp, 10000) : 0);
  301. $('#total_final_tp').text(total_final_tp ? ZhCalc.div(total_final_tp, 10000) : 0);
  302. // level1List.push(huishouInfo);
  303. } else {
  304. total_gai_tp = ZhCalc.sum(_.map(level1List, 'gai_tp'));
  305. total_final_tp = ZhCalc.sum(_.map(level1List, 'final_tp'));
  306. total_gu_tp = ZhCalc.sum(_.map(level1List, 'gu_tp'));
  307. total_yu_tp = ZhCalc.sum(_.map(level1List, 'yu_tp'));
  308. total_price = ZhCalc.sum(_.map(level1List, 'total_price'));
  309. total_rate = ZhCalc.div(ZhCalc.sub(total_final_tp, total_gai_tp), total_gai_tp);
  310. $('#total_gai_tp').text(total_gai_tp ? ZhCalc.div(total_gai_tp, 10000) : 0);
  311. $('#total_final_tp').text(total_final_tp ? ZhCalc.div(total_final_tp, 10000) : 0);
  312. }
  313. }
  314. $('#total_rate').text((total_rate ? ZhCalc.round(ZhCalc.mul(total_rate,100), 2) : 0) + '%');
  315. if (total_rate > 0) {
  316. $('#total_rate').parents('.canyu-band').removeClass('text-success').addClass('text-danger');
  317. } else if (total_rate < 0) {
  318. $('#total_rate').parents('.canyu-band').removeClass('text-danger').addClass('text-success');
  319. } else if (total_rate === 0) {
  320. $('#total_rate').parents('.canyu-band').removeClass('text-success').removeClass('text-danger');
  321. }
  322. console.log(level1List);
  323. option.series[0].data = [
  324. ZhCalc.div(total_gu_tp, 10000),
  325. ZhCalc.div(total_gai_tp, 10000),
  326. ZhCalc.div(total_yu_tp, 10000),
  327. ZhCalc.div(total_price, 10000),
  328. ZhCalc.div(ZhCalc.add(total_change_tp, total_price), 10000),
  329. ZhCalc.div(total_final_tp, 10000),
  330. ];
  331. if (huishouInfo) level1List.push(huishouInfo);
  332. option2.legend.data = _.map(level1List, 'name');
  333. for (const level1 of level1List) {
  334. option2.series.push({
  335. name: level1.name,
  336. type: 'line',
  337. stack: 'Total',
  338. data: [ZhCalc.div(level1.gu_tp, 10000), ZhCalc.div(level1.gai_tp, 10000),
  339. ZhCalc.div(level1.yu_tp, 10000), ZhCalc.div(level1.total_price, 10000),
  340. ZhCalc.div(level1.final_tp, 10000)
  341. ]
  342. });
  343. }
  344. }
  345. myChart.setOption(option);
  346. myChart2.setOption(option2);
  347. }
  348. let resizeTimer = null;
  349. $(window).bind('resize', function () {
  350. if (resizeTimer) clearTimeout(resizeTimer);
  351. resizeTimer = setTimeout(function () {
  352. echartsReset();
  353. }, 500);
  354. });
  355. function echartsReset() {
  356. myChart.resize();
  357. myChart2.resize();
  358. }
  359. function setDashboardHeight() {
  360. function getObjHeight(select) {
  361. return select.length > 0 ? select.outerHeight(true) : 0;
  362. }
  363. $('.dashboard-height').height($(window).height() - 34 - 16);
  364. $('.agency-partheight').height($('.dashboard-height').height()/2);
  365. $('.contant-height-one').height($('.agency-partheight').height() - 52 - 20);
  366. $('.contant-height-two').height($('.agency-partheight').height() - 52 - getObjHeight($(".echart-height")) - 20);
  367. // $('.echart-height').width(parseInt($(".echart-height").width()));
  368. }
  369. setDashboardHeight();
  370. $(window).resize(setDashboardHeight);
  371. $.subMenu({
  372. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  373. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  374. key: 'menu.1.0.0',
  375. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  376. callback: function (info) {
  377. if (info.mini) {
  378. $('.panel-title').addClass('fluid');
  379. $('#sub-menu').removeClass('panel-sidebar');
  380. } else {
  381. $('.panel-title').removeClass('fluid');
  382. $('#sub-menu').addClass('panel-sidebar');
  383. }
  384. autoFlashHeight();
  385. }
  386. });
  387. });