'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 += `