'use strict'; /** * * * @author Mai * @date * @version */ $(document).ready(() => { autoFlashHeight(); const compareObj = { curFinalId() { return this.finalInfo ? this.finalInfo.id : undefined; }, expand(tree, tag) { switch (tag) { case "1": case "2": case "3": case "4": case "5": tree.expandByLevel(parseInt(tag)); break; case "last": tree.expandByCustom(() => { return true; }); break; } }, calcStackedBar(tree) { const calcField = this.stackedBarField; const calcFieldColor = { 'gu_tp': '#657798', 'gai_tp': '#EE6666', 'yu_tp': '#74CBED', 'total_price': '#FAC858', 'final_tp': '#62DAAB' }; const calcFieldCaption = { 'gu_tp': '估算', 'gai_tp': '概算', 'yu_tp': '预算', 'total_price': '台账', 'final_tp': '决算' }; const calc = function(node, base){ // const parent = tree.getParent(node); // if (!parent) { // base = 0; // for (const cf of calcField) { // base = Math.max(node[cf], base); // } // } node.stackedBar = []; node.stackedBarTips = []; for (const cf of calcField) { node.stackedBar.push({color: calcFieldColor[cf], percent: ZhCalc.div(node[cf], base), field: cf}); node.stackedBarTips.push(`${calcFieldCaption[cf]}: ${node[cf] || 0}`); } if (node.children) { for (const child of node.children) { calc(child, base); } } }; let commonBase = 0; tree.children.forEach(x => { for (const cf of calcField) { commonBase = Math.max(x[cf] || 0, commonBase); } }); for (const child of tree.children) { calc(child, commonBase); } }, loadBudgetData(result) { const compareTree = createNewPathTree('final', { id: 'id', pid: 'pid', order: 'order', level: 'level', rootId: -1, }); const setting = { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] }; const guTree = createNewPathTree('ledger', setting); guTree.loadDatas(result.gu); treeCalc.calculateAll(guTree); compareTree.loadTree(guTree, function (cur, source) { cur.base = true; cur.gu_dgn_qty1 = ZhCalc.add(cur.gu_dgn_qty1, source.dgn_qty1); cur.gu_dgn_qty2 = ZhCalc.add(cur.gu_dgn_qty2, source.dgn_qty2); cur.gu_tp = ZhCalc.add(cur.gu_tp, source.total_price); }); const gaiTree = createNewPathTree('ledger', setting); gaiTree.loadDatas(result.gai); treeCalc.calculateAll(gaiTree); compareTree.loadTree(gaiTree, function (cur, source) { cur.base = true; cur.gai_dgn_qty1 = ZhCalc.add(cur.gai_dgn_qty1, source.dgn_qty1); cur.gai_dgn_qty2 = ZhCalc.add(cur.gai_dgn_qty2, source.dgn_qty2); cur.gai_tp = ZhCalc.add(cur.gai_tp, source.total_price); }); const yuTree = createNewPathTree('ledger', setting); yuTree.loadDatas(result.yu); treeCalc.calculateAll(yuTree); compareTree.loadTree(yuTree, function (cur, source) { cur.base = true; cur.yu_dgn_qty1 = ZhCalc.add(cur.yu_dgn_qty1, source.dgn_qty1); cur.yu_dgn_qty2 = ZhCalc.add(cur.yu_dgn_qty2, source.dgn_qty2); cur.yu_tp = ZhCalc.add(cur.yu_tp, source.total_price); }); compareTree.afterLoad(node => { node.gu_dgn_price = ZhCalc.div(node.gu_tp, node.gu_dgn_qty1, 2); node.gu_dgn_qty = node.gu_dgn_qty1 ? (node.gu_dgn_qty2 ? node.gu_dgn_qty1 + '/' + node.gu_dgn_qty2 : node.gu_dgn_qty1) : (node.gu_dgn_qty2 ? '/' + node.gu_dgn_qty2 : ''); node.gai_dgn_price = ZhCalc.div(node.gai_tp, node.gai_dgn_qty1, 2); node.gai_dgn_qty = node.gai_dgn_qty1 ? (node.gai_dgn_qty2 ? node.gai_dgn_qty1 + '/' + node.gai_dgn_qty2 : node.gai_dgn_qty1) : (node.gai_dgn_qty2 ? '/' + node.gai_dgn_qty2 : ''); node.yu_dgn_price = ZhCalc.div(node.yu_tp, node.yu_dgn_qty1, 2); node.yu_dgn_qty = node.yu_dgn_qty1 ? (node.yu_dgn_qty2 ? node.yu_dgn_qty1 + '/' + node.yu_dgn_qty2 : node.yu_dgn_qty1) : (node.yu_dgn_qty2 ? '/' + node.yu_dgn_qty2 : ''); }); compareTree.resortChildrenByCustom(function (x, y) { const iCode = compareCode(x.code, y.code); if (iCode) return iCode; if (!x.name) return -1; if (!y.name) return 1; return x.name.localeCompare(y.name); }); const expandTag = getLocalCache('revise-compare-level'); if (expandTag) compareObj.expand(compareTree, expandTag); this.calcStackedBar(compareTree); // console.log(compareTree); setPageData(compareTree); }, loadFinalData(result, msg) { if (msg) toastr.warning(msg); this.finalInfo = result.finalInfo; const finalTree = createNewPathTree('ledger', { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, }); finalTree.loadDatas(result.final); const expandTag = getLocalCache('revise-compare-level'); if (expandTag) compareObj.expand(finalTree, expandTag); this.calcStackedBar(finalTree); // console.log(finalTree); setPageData(finalTree); }, loadCacheData(){ const stackedBarCache = 'gai_tp,total_price,final_tp'; this.setStackedBarField(stackedBarCache.split(',')); }, setStackedBarField(field){ this.stackedBarField = field; }, }; compareObj.loadCacheData(); function compareCode(str1, str2, symbol = '-') { if (!str1) { return 1; } else if (!str2) { return -1; } function compareSubCode(code1, code2) { if (numReg.test(code1)) { if (numReg.test(code2)) { return parseInt(code1) - parseInt(code2); } else { return -1 } } else { if (numReg.test(code2)) { return 1; } else { return code1 === code2 ? 0 : (code1 < code2 ? -1 : 1); //code1.localeCompare(code2); } } } const numReg = /^[0-9]+$/; const aCodes = str1.split(symbol), bCodes = str2.split(symbol); for (let i = 0, iLength = Math.min(aCodes.length, bCodes.length); i < iLength; ++i) { const iCompare = compareSubCode(aCodes[i], bCodes[i]); if (iCompare !== 0) { return iCompare; } } return aCodes.length - bCodes.length; } postData(window.location.pathname + '/compare/load', {}, function (result, msg) { if (result.final) { compareObj.loadFinalData(result, msg); } else { compareObj.loadBudgetData(result); } }); //金额对比 var chartDom = document.getElementById('jlchart2'); var myChart = echarts.init(chartDom); var option = { tooltip: { trigger: 'axis', }, grid: { left: '3%', right: '3%', bottom: '4%', containLabel: true }, xAxis: { type: 'category', data: ['投资估算', '设计概算', '施工图预算', '台账', '变更后台账', '决算'] }, yAxis: { type: 'value' }, series: [ { data: [0, 0, 0, 0, 0, 0], type: 'bar', showBackground: true, backgroundStyle: { color: 'rgba(180, 180, 180, 0.2)' }, itemStyle:{ borderRadius: [30, 30, 0, 0] }, barWidth : 30 } ], color:{ type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [{ offset: 0, color: '#3A6FB5' // 0% 处的颜色 }, { offset: 1, color: '#44BEE3' // 100% 处的颜色 }], global: false // 缺省为 false } }; //全过程造价趋势 var chartDom2 = document.getElementById('jlchart3'); var myChart2 = echarts.init(chartDom2); var option2 = { title: { text: '' }, tooltip: { trigger: 'axis' }, legend: { }, grid: { left: '3%', right: '5%', bottom: '3%', containLabel: true }, xAxis: { type: 'category', boundaryGap: false, data: ['投资估算', '设计概算', '施工图预算', '台账金额', '决算金额'] }, yAxis: { type: 'value' }, series: [] }; function setPageData(tree) { console.log(tree); if (tree.children.length > 0) { const level2List = tree.children[0].children; if (level2List.length > 0) { let jianAnHtml = ''; for (const level2 of level2List) { jianAnHtml += ` ${level2.name} ${level2.gai_tp ? ZhCalc.div(level2.gai_tp, 10000) : 0} ${level2.final_tp ? ZhCalc.div(level2.final_tp, 10000) : 0} ${level2.gai_tp ? ZhCalc.round(ZhCalc.div(ZhCalc.sub(level2.final_tp, level2.gai_tp), level2.gai_tp), 2) : 0} `; } $('#jianan-table').html(jianAnHtml); } // 分析第一层结构,获取各个部分金额非全0的及除了回收金额层 const level1List = _.filter(tree.children, function (item) { 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)) }); // 回收金额 const huishouInfo = _.find(tree.children, function (item) { 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)) }); let total_rate = 0, total_gai_tp = 0, total_gu_tp = 0, total_yu_tp = 0, total_price = 0, total_final_tp = 0; if (level1List.length > 0) { if (huishouInfo) { total_gai_tp = ZhCalc.sub(ZhCalc.sum(_.map(level1List, 'gai_tp')), huishouInfo.gai_tp); total_final_tp = ZhCalc.sub(ZhCalc.sum(_.map(level1List, 'final_tp')), huishouInfo.final_tp); total_gu_tp = ZhCalc.sub(ZhCalc.sum(_.map(level1List, 'gu_tp')), huishouInfo.gu_tp); total_yu_tp = ZhCalc.sub(ZhCalc.sum(_.map(level1List, 'yu_tp')), huishouInfo.yu_tp); total_price = ZhCalc.sub(ZhCalc.sum(_.map(level1List, 'total_price')), huishouInfo.total_price); total_rate = ZhCalc.div(ZhCalc.sub(total_final_tp, total_gai_tp), total_gai_tp); $('#total_gai_tp').text(total_gai_tp ? ZhCalc.div(total_gai_tp, 10000) : 0); $('#total_final_tp').text(total_final_tp ? ZhCalc.div(total_final_tp, 10000) : 0); // level1List.push(huishouInfo); } else { total_gai_tp = ZhCalc.sum(_.map(level1List, 'gai_tp')); total_final_tp = ZhCalc.sum(_.map(level1List, 'final_tp')); total_gu_tp = ZhCalc.sum(_.map(level1List, 'gu_tp')); total_yu_tp = ZhCalc.sum(_.map(level1List, 'yu_tp')); total_price = ZhCalc.sum(_.map(level1List, 'total_price')); total_rate = ZhCalc.div(ZhCalc.sub(total_final_tp, total_gai_tp), total_gai_tp); $('#total_gai_tp').text(total_gai_tp ? ZhCalc.div(total_gai_tp, 10000) : 0); $('#total_final_tp').text(total_final_tp ? ZhCalc.div(total_final_tp, 10000) : 0); } } $('#total_rate').text((total_rate ? ZhCalc.round(ZhCalc.mul(total_rate,100), 2) : 0) + '%'); if (total_rate > 0) { $('#total_rate').parents('.canyu-band').removeClass('text-success').addClass('text-danger'); } else if (total_rate < 0) { $('#total_rate').parents('.canyu-band').removeClass('text-danger').addClass('text-success'); } else if (total_rate === 0) { $('#total_rate').parents('.canyu-band').removeClass('text-success').removeClass('text-danger'); } console.log(level1List); option.series[0].data = [ ZhCalc.div(total_gu_tp, 10000), ZhCalc.div(total_gai_tp, 10000), ZhCalc.div(total_yu_tp, 10000), ZhCalc.div(total_price, 10000), ZhCalc.div(ZhCalc.add(total_change_tp, total_price), 10000), ZhCalc.div(total_final_tp, 10000), ]; if (huishouInfo) level1List.push(huishouInfo); option2.legend.data = _.map(level1List, 'name'); for (const level1 of level1List) { option2.series.push({ name: level1.name, type: 'line', stack: 'Total', data: [ZhCalc.div(level1.gu_tp, 10000), ZhCalc.div(level1.gai_tp, 10000), ZhCalc.div(level1.yu_tp, 10000), ZhCalc.div(level1.total_price, 10000), ZhCalc.div(level1.final_tp, 10000) ] }); } } myChart.setOption(option); myChart2.setOption(option2); } let resizeTimer = null; $(window).bind('resize', function () { if (resizeTimer) clearTimeout(resizeTimer); resizeTimer = setTimeout(function () { echartsReset(); }, 500); }); function echartsReset() { myChart.resize(); myChart2.resize(); } function setDashboardHeight() { function getObjHeight(select) { return select.length > 0 ? select.outerHeight(true) : 0; } $('.dashboard-height').height($(window).height() - 34 - 16); $('.agency-partheight').height($('.dashboard-height').height()/2); $('.contant-height-one').height($('.agency-partheight').height() - 52 - 20); $('.contant-height-two').height($('.agency-partheight').height() - 52 - getObjHeight($(".echart-height")) - 20); // $('.echart-height').width(parseInt($(".echart-height").width())); } setDashboardHeight(); $(window).resize(setDashboardHeight); $.subMenu({ menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list', toMenu: '#to-menu', toMiniMenu: '#to-mini-menu', key: 'menu.1.0.0', miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1', callback: function (info) { if (info.mini) { $('.panel-title').addClass('fluid'); $('#sub-menu').removeClass('panel-sidebar'); } else { $('.panel-title').removeClass('fluid'); $('#sub-menu').addClass('panel-sidebar'); } autoFlashHeight(); } }); });