diff --git a/package.json b/package.json index ba21488e..beef902a 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "html2canvas": "^1.4.1", "json-editor-vue3": "^1.0.6", "jspdf": "^2.5.1", + "moment": "^2.30.1", "node-polyfill-webpack-plugin": "^4.0.0", "nprogress": "0.2.0", "print-js": "^1.6.0", diff --git a/src/api/model/qm.js b/src/api/model/qm.js index b86b55f7..d408013a 100644 --- a/src/api/model/qm.js +++ b/src/api/model/qm.js @@ -26,6 +26,13 @@ export default { return await http.post(this.url, data); }, }, + updateQuastatGoal: { + url: `${config.API_URL}/qm/quastat/update_rate_pass_t/`, + name: "更新合格率目标值", + post: async function (data = {}) { + return await http.post(this.url, data); + }, + }, //质检项目 getTestItem: { url: `${config.API_URL}/qm/testitem/`, diff --git a/src/views/enm_energy/carbon.vue b/src/views/enm_energy/carbon.vue index 5e352d7f..773b554e 100644 --- a/src/views/enm_energy/carbon.vue +++ b/src/views/enm_energy/carbon.vue @@ -101,13 +101,13 @@ width="120" > - - + --> - - + --> - - + --> let legend = { top: "2%", - data: ["碳排放量(t)"], + data: ["碳排放量(t)", "碳排放强度(t/t)"], }; -let colors = ["##36492E", "#4BA328", "#C6F47D"]; +let grid = { + right: "11%", + left: "11%", + top: "27%", +}; +let colors = ["#518A3A", "#2DAEEF", "#C6F47D"]; +let yAxis = [ + { + type: "value", + name: "碳排放量(t)", + position: "left", + alignTicks: true, + nameRotate: 50, + axisLine: { + show: true, + lineStyle: { + color: colors[0], + }, + }, + axisLabel: { + formatter: "{value}", + }, + }, + { + type: "value", + name: "碳排放强度(t/t)", + position: "right", + alignTicks: true, + nameRotate: 50, + axisLine: { + show: true, + lineStyle: { + color: colors[1], + }, + }, + axisLabel: { + formatter: "{value}", + }, + } + +]; import scEcharts from "@/components/scEcharts"; export default { components: { @@ -278,7 +318,6 @@ export default { {id:0,name:'日统计'}, {id:1,name:'月统计'}, {id:2,name:'年统计'}, - {id:3,name:'时间段'}, ], tableDatas2: [], tableDatas_day:[], @@ -389,13 +428,14 @@ export default { xAxisData_month: [], xTtimeRange: [], gyhourlyData : [], - lvhourlyData : [], + mpointList_code:"3750125939653558272,3759456603624382464,3636975194725527552", + StrengthData : [], shhourlyData : [], // 用于存储每小时的数据 gyhourlyData_month : [], - lvhourlyData_month : [], - shhourlyData_month : [], // 用于存储每小时的数据 + StrengthData_month : [], + ProductionData_month : [], // 用于存储每小时的数据 gyhourlyData_year : [], - lvhourlyData_year : [], + StrengthData_year : [], shhourlyData_year : [], // 用于存储每小时的数据 }; }, @@ -450,10 +490,10 @@ export default { }, changeDate(){ let obj = {}; - obj.type = "day"; + obj.type = "hour"; obj.start_time = this.daterange[0]; obj.end_time = this.daterange[1]; - obj.mpoint__in = "3750125939653558272"; + obj.mpoint__in = '3750125939653558272,3759456603624382464'; obj.page = 0; this.$API.enm.mpointstat.groupValues.req(obj).then((res) => { //处理res数组中的 total_val 字段 保留两位 @@ -501,7 +541,7 @@ export default { // enabled: 1, // need_display: 1, ordering: "report_sortstr", - code__in: "tpfl", + code__in: "tanpfqd, tpfl", query: "{ id, name, nickname, mgroup_name, unit, report_sortstr }", }) .then((res) => { @@ -518,6 +558,7 @@ export default { _nameLength = [], indexList = []; let mgroupObj = {}; + console.log(that.mpointList); that.mpointList.forEach((item, index) => { let indexs = _mgroup.indexOf(item.mgroup_name); if (indexs > -1) { @@ -551,12 +592,14 @@ export default { that.tableDatas2.push(obj); that.getData(item.id, index); }); - that.updateChart(that.gyhourlyData, that.shhourlyData, that.lvhourlyData); + that.updateChart(that.gyhourlyData, that.StrengthData); that.mgroupObj = mgroupObj; that.indexList = indexList; }, getData(id, index) { let that = this; + that.StrengthData = []; + that.gyhourlyData = []; let obj = {}; obj.type = "hour"; obj.year = that.year; @@ -574,6 +617,10 @@ export default { that.tableDatas2[index][keyName] = item.val; if (item.mpoint_nickname == "碳排放量"){ that.gyhourlyData[item.hour] = item.val; + }else if( + item.mpoint_nickname == "碳排放强度" + ){ + that.StrengthData[item.hour] = item.val; } }); sum = sum * 100; @@ -585,11 +632,12 @@ export default { that.$forceUpdate(); }); }, - updateChart(gyhourlyData, shhourlyData, lvhourlyData) { + updateChart(gyhourlyData, StrengthData) { let that = this; // 创建 ECharts 配置 let option = { legend: legend, + grid: grid, tooltip: { trigger: 'axis', axisPointer: { @@ -600,80 +648,84 @@ export default { type: 'category', data: ['0时', '1时', '2时', '3时', '4时', '5时', '6时', '7时', '8时', '9时', '10时', '11时', '12时', '13时', '14时', '15时', '16时', '17时', '18时', '19时', '20时', '21时', '22时', '23时'], }, - yAxis: { - type: 'value', - name: '' - }, + yAxis: yAxis, series: [{ name: '碳排放量(t)', // 此处修改为对应分类的名称 type: 'bar', - data: gyhourlyData, // 每小时的用水量 + data: gyhourlyData, + yAxisIndex: 0, itemStyle: { color: '#518A3A', }, }, + { + name: '碳排放强度(t/t)', + type: 'bar', + data: StrengthData, + yAxisIndex: 1, + itemStyle: { + color: colors[1], + }, + + }, + ] }; that.optionHour = option; }, dataLoop1() { - let that = this; - that.tableDatas = []; - that.tableDatas_day = []; - let _mgroup = [], - _nameLength = [], - indexList = []; - let mgroupObj = {}; - that.mpointList.forEach((item, index) => { - let indexs = _mgroup.indexOf(item.mgroup_name); - if (indexs > -1) { - _nameLength[indexs] += 1; - } else { - _mgroup.push(item.mgroup_name); - _nameLength.push(1); - indexList.push(index); - } + let that = this; + that.tableDatas = []; + that.tableDatas_day = []; + let _mgroup = [], _nameLength = [], indexList = []; + let mgroupObj = {}; + that.mpointList.forEach((item, index) => { + let indexs = _mgroup.indexOf(item.mgroup_name); + if (indexs > -1) { + _nameLength[indexs] += 1; + } else { + _mgroup.push(item.mgroup_name); + _nameLength.push(1); + indexList.push(index); + } - for (let i = 0; i < _mgroup.length; i++) { - mgroupObj[_mgroup[i]] = _nameLength[i]; - } - let arr = []; - arr[0] = - item.mgroup_name != null - ? item.mgroup_name - : item.nickname != null - ? item.nickname - : item.name; - arr[1] = item.nickname != null ? item.nickname : item.name; - arr[2] = item.unit; - for (let i = 0; i < that.days; i++) { - arr[i + 2] = 0; - } - that.tableDatas.push(arr); - let obj = {}; - obj.mgroupName = - item.mgroup_name != null ? item.mgroup_name : item.name; - obj.nickname = - item.nickname != null && item.nickname != "" - ? item.nickname - : item.name; - obj.unit = item.unit; + for (let i = 0; i < _mgroup.length; i++) { + mgroupObj[_mgroup[i]] = _nameLength[i]; + } + + let arr = []; + arr[0] = item.mgroup_name != null ? item.mgroup_name : item.nickname != null ? item.nickname : item.name; + arr[1] = item.nickname != null ? item.nickname : item.name; + arr[2] = item.unit; + for (let i = 0; i < that.days; i++) { + arr[i + 2] = 0; + } + + that.tableDatas.push(arr); + let obj = {}; + obj.mgroupName = item.mgroup_name != null ? item.mgroup_name : item.name; + obj.nickname = item.nickname != null && item.nickname != "" ? item.nickname : item.name; + obj.unit = item.unit; + + that.tableDatas_day.push(obj); + + // 在每次循环调用 getData1(index),确保异步操作独立 + that.getData1(index); + }); + + that.updateMonthChart(that.gyhourlyData_month, that.StrengthData_month, that.ProductionData_month); + that.mgroupObj = mgroupObj; + that.indexList = indexList; +}, - that.tableDatas_day.push(obj); - that.getData1(item.id, index); - }); - that.updateMonthChart(that.gyhourlyData_month); - that.mgroupObj = mgroupObj; - that.indexList = indexList; - - }, - updateMonthChart(gyhourlyData) { + updateMonthChart(gyhourlyData, StrengthData, ) { let that = this; // 创建 ECharts 配置 let option1 = { legend: legend, + grid: grid, tooltip: { trigger: 'axis', axisPointer: { @@ -684,55 +736,90 @@ export default { type: 'category', data: [], }, - yAxis: { - type: 'value', - name: '' - }, + yAxis: yAxis, series: [{ - name: '碳排放量(t)', // 此处修改为对应分类的名称 + name: '碳排放量(t)', type: 'bar', - data: gyhourlyData, // 每小时的用水量 + data: gyhourlyData, + yAxisIndex: 0, itemStyle: { color: '#518A3A', }, }, + { + name: '碳排放强度(t/t)', + type: 'bar', + data: StrengthData, + yAxisIndex: 1, + itemStyle: { + color: colors[1], + }, + + }, ] }; option1.xAxis.data = that.xAxisData_day; that.optionDay = option1; }, - getData1(id, index) { - let that = this; - let obj = {}; - obj.type = "day"; - obj.year = that.year; - obj.month = that.month; - obj.mpoint = id; - obj.page = 0; - this.$API.enm.mpoint.stat.req(obj).then((res) => { - let sum = 0; - res.forEach((item) => { - let ind = item.day+2; - that.tableDatas[index][ind] = item.val; - sum += Number(item.val); - let keyName = item.day + "日"; - that.tableDatas_day[index][keyName] = item.val; - if (item.mpoint_nickname == "碳排放量"){ - that.gyhourlyData_month[item.day-1] = item.val; - } - }); - sum = sum * 100; - sum = Math.round(sum); - sum = sum / 100; - let dayss = 0; - dayss = this.days + 3; - that.tableDatas[index][dayss] = sum.toFixed(2); - that.tableDatas_day[index].sum = sum.toFixed(2); - that.$forceUpdate(); - }); - }, + getData1(index) { + let that = this; + that.StrengthData_month = []; + that.gyhourlyData_month = []; + let carbonEmission = []; // 存储每一天的碳排放量 + let outputKiln = []; // 存储每一天的出窑熟料产量 + let emissionIntensity = []; // 存储每一天的碳排放强度 + let obj = {}; + obj.type = "day"; + obj.year = that.year; + obj.month = that.month; + obj.mpoint__in = this.mpointList_code; + obj.page = 0; + + this.$API.enm.mpoint.stat.req(obj).then((res) => { + let sum = 0; + res.forEach((item) => { + let ind = item.day + 2; + that.tableDatas[index][ind] = item.val; + sum += Number(item.val); + if (item.mpoint_nickname === "碳排放量") { + carbonEmission[item.day - 1] = item.val; // 存储每日的碳排放量 + } else if (item.mpoint_nickname === "出窑熟料产量") { + outputKiln[item.day - 1] = item.val; // 存储每日的出窑熟料产量 + } + if(item.mpoint_nickname == "碳排放强度"){ + return; + } + // that.tableDatas_day[index][keyName] = item.val; + if (item.mpoint_nickname == "碳排放量"){ + that.gyhourlyData_month[item.day - 1] = item.val; + } else if(item.mpoint_nickname == "出窑熟料产量"){ + that.ProductionData_month[item.day - 1] = item.val; + } + }); + // 计算碳排放强度:碳排放量 / 出窑熟料产量 + for (let i = 0; i < carbonEmission.length; i++) { + let keyName = i + 1 + "日"; + if(index==1 && carbonEmission[i] && outputKiln[i]){ + emissionIntensity[i] = carbonEmission[i] / outputKiln[i]; // 计算碳排放强度 + that.StrengthData_month[i] = emissionIntensity[i].toFixed(2); // 存入 StrengthData_month + that.tableDatas_day[index][keyName] = emissionIntensity[i].toFixed(2); // 存入 tableDatas_day + } else if(index==0 && carbonEmission[i]){ + that.tableDatas_day[index][keyName] = carbonEmission[i]; + } + } + sum = sum * 100; + sum = Math.round(sum); + sum = sum / 100; + let dayss = 0; + dayss = this.days + 3; + that.tableDatas[index][dayss] = sum.toFixed(2); + that.tableDatas_day[index].sum = sum.toFixed(2); + that.$forceUpdate(); + }); +}, + dataLoop_month() { let that = this; that.tableDatas = []; @@ -772,16 +859,17 @@ export default { : item.name; obj.unit = item.unit; that.tableDatas_month.push(obj); - that.getData_month(item.id, index); + that.getData_month(index); }); - that.updateMonthChart_month(that.gyhourlyData_year, that.shhourlyData_year, that.lvhourlyData_year); + that.updateMonthChart_month(that.gyhourlyData_year, that.StrengthData_year); that.mgroupObj = mgroupObj; that.indexList = indexList; }, - updateMonthChart_month(gyhourlyData) { + updateMonthChart_month(gyhourlyData_year, StrengthData_year) { let that = this; let option2 = { legend: legend, + grid: grid, tooltip: { trigger: 'axis', axisPointer: { @@ -792,30 +880,42 @@ export default { type: 'category', data: [], }, - yAxis: { - type: 'value', - name: '' - }, + yAxis: yAxis, series: [{ - name: '工业水', // 此处修改为对应分类的名称 + name: '碳排放量(t)', type: 'bar', - data: gyhourlyData, // 每小时的用水量 + data: gyhourlyData_year, + yAxisIndex: 0, itemStyle: { color: '#518A3A', }, - + }, + { + name: '碳排放强度(t/t)', + type: 'bar', + data: StrengthData_year, + yAxisIndex: 1, + itemStyle: { + color: colors[1], + }, } + ] }; option2.xAxis.data = that.xAxisData_month; that.optionMonth = option2; }, - getData_month(id, index) { + getData_month(index) { let that = this; + that.StrengthData_year = []; + that.gyhourlyData_year = []; + let carbonEmission = []; // 存储每一天的碳排放量 + let outputKiln = []; // 存储每一天的出窑熟料产量 + let emissionIntensity = []; // 存储每一天的碳排放强度 let obj = {}; obj.type = "month"; obj.year = that.year; - obj.mpoint = id; + obj.mpoint__in = that.mpointList_code; obj.page = 0; this.$API.enm.mpoint.stat.req(obj).then((res) => { let sum = 0; @@ -824,11 +924,34 @@ export default { that.tableDatas[index][ind] = item.val; sum += Number(item.val); let keyName = item.month + "月"; - that.tableDatas_month[index][keyName] = item.val; + // that.tableDatas_month[index][keyName] = item.val; + if (item.mpoint_nickname === "碳排放量") { + carbonEmission[item.month - 1] = item.val; // 存储每日的碳排放量 + } else if (item.mpoint_nickname === "出窑熟料产量") { + outputKiln[item.month - 1] = item.val; // 存储每日的出窑熟料产量 + } + if(item.mpoint_nickname == "碳排放强度"){ + return; + } if (item.mpoint_nickname == "碳排放量"){ that.gyhourlyData_year[item.month-1] = item.val; + }else if(item.mpoint_nickname == "碳排放强度"){ + that.StrengthData_year[item.month-1] = item.val; } + + }); + // 计算碳排放强度:碳排放量 / 出窑熟料产量 + for (let i = 0; i < carbonEmission.length; i++) { + let keyName = i + 1 + "月"; + if(index==1 && carbonEmission[i] && outputKiln[i]){ + emissionIntensity[i] = carbonEmission[i] / outputKiln[i]; // 计算碳排放强度 + that.StrengthData_year[i] = emissionIntensity[i].toFixed(2); // 存入 StrengthData_month + that.tableDatas_month[index][keyName] = emissionIntensity[i].toFixed(2); // 存入 tableDatas_day + } else if(index==0 && carbonEmission[i]){ + that.tableDatas_month[index][keyName] = carbonEmission[i]; + } + } sum = sum * 100; sum = Math.round(sum); sum = sum / 100; @@ -853,9 +976,10 @@ export default { handleCellClick1(row, column, cell, event) { let that = this; let index = that.tableDatas_day.indexOf(row); - console.log('row', row) - that.tableName = `${row.nickname}-电量日统计` - let lineData = that.tableDatas[index].slice(3, that.days + 3); + console.log("row", row, that.tableDatas_day, index); + that.tableName = `${row.nickname}` + console.log("tableDatas", that.tableDatas); + let lineData = that.tableDatas_day[index].slice(2, 13); that.option.xAxis.data = that.xAxisData_day; that.option.series[0].data = lineData; this.itemVisible = true; @@ -863,7 +987,7 @@ export default { handleCellClick_month(row, column, cell, event) { let that = this; let index = that.tableDatas_month.indexOf(row); - that.tableName = `${row.nickname}-电量日统计` + that.tableName = `${row.nickname}` //获取图数据 let lineData = that.tableDatas[index].slice(2, 13); that.option.xAxis.data = that.xAxisData_month; diff --git a/src/views/enm_kiln/report.vue b/src/views/enm_kiln/report.vue index 5a58ac90..41bab952 100644 --- a/src/views/enm_kiln/report.vue +++ b/src/views/enm_kiln/report.vue @@ -338,6 +338,7 @@