add - ems业态能耗分析

master
yinq 3 months ago
parent 855e560e00
commit bc0f4b91b3

@ -31,3 +31,11 @@ export function getProductConsumptionComparison(query) {
params: query
})
}
export function getBusinessEnergyConsumptionAnalysis(query) {
return request({
url: '/energy/report/preview/businessEnergyConsumptionAnalysis',
method: 'get',
params: query
})
}

@ -0,0 +1,709 @@
<template>
<div class="app-container">
<el-row :gutter="20">
<el-col :span="6" :xs="24">
<div class="head-container">
<el-tag
v-for="item in dynamicTags"
:key="item.monitorId"
closable
:disable-transitions="false"
@close="handleClose(item.monitorId)"
>
{{ item.label }}
</el-tag>
<el-input
v-model="deptName"
placeholder="请输入业态名称"
clearable
size="small"
prefix-icon="el-icon-search"
style="margin-bottom: 20px"
/>
</div>
<div class="head-container tree">
<el-tree
ref="tree"
:data="deptOptions"
:props="defaultProps"
:expand-on-click-node="false"
:filter-node-method="filterNode"
node-key="id"
default-expand-all
highlight-current
@node-click="handleNodeClick"
/>
</div>
</el-col>
<!--右侧数据-->
<el-col :span="18" :xs="24">
<!--头部搜索条件输入框 -->
<el-form
ref="queryForm"
:model="queryParams"
:inline="true"
size="small"
v-show="showSearch"
label-width="68px"
class="search-form"
>
<el-form-item label="采集时间">
<el-date-picker
v-model="queryParams.startTime"
:type="getDatePickerType"
value-format="yyyy-MM-dd HH:mm:ss"
:placeholder="getDatePickerPlaceholder"
style="width: 240px"
@change="handleQuery"
/>
<span class="mx-2">-</span>
<el-date-picker
v-model="queryParams.endTime"
:type="getDatePickerType"
value-format="yyyy-MM-dd HH:mm:ss"
:placeholder="getDatePickerPlaceholder"
style="width: 240px"
@change="handleQuery"
/>
</el-form-item>
<el-form-item label="时间范围" prop="status">
<el-select
v-model="queryParams.type"
placeholder="请选择"
clearable
style="width: 240px"
@change="handleTimeRangeChange"
>
<el-option
v-for="dict in timeRangeOptions"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
</el-form>
<!--图表区域 -->
<el-row :gutter="20" style="margin-bottom: 20px">
<!--左侧饼图-->
<el-col :span="8">
<el-card class="chart-card">
<div style="width: 100%; height: 360px" id="pieChart"></div>
<div class="total-expend">
总用电量{{ totalExpend }} kW·h
</div>
</el-card>
</el-col>
<!--右侧曲线图-->
<el-col :span="16">
<el-card class="chart-card">
<div style="width: 100%; height: 360px" id="lineChart"></div>
</el-card>
</el-col>
</el-row>
<!--表格区域-->
<el-card>
<el-table
v-loading="loading"
:data="tableData"
style="width: 100%"
border
>
<el-table-column
v-for="col in columns"
:key="col.key"
:prop="col.key"
:label="col.label"
:width="col.width"
align="center"
v-if="col.visible"
/>
</el-table>
</el-card>
</el-col>
</el-row>
</div>
</template>
<script>
import {getBusinessEnergyConsumptionAnalysis} from '@/api/energy/record/statistics'
import {getToken} from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import * as echarts from "echarts";
import {treeDattwo} from "@/api/energy/energy/base/typeRelation";
export default {
name: "BusinessEnergyConsumptionAnalysis",
dicts: ["sys_normal_disable", "sys_user_sex"],
components: {Treeselect},
data() {
return {
//
loading: false,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
userList: null,
//
title: "",
//
deptOptions: [],
//
open: false,
//
deptName: undefined,
//
initPassword: undefined,
//
dateRange: [],
dateRangeone: '',
dateRangetwo: '',
//
postOptions: [],
//
roleOptions: [],
//
form: {},
defaultProps: {
children: "children",
label: "lable",
},
//
upload: {
//
open: false,
//
title: "",
//
isUploading: false,
//
updateSupport: 0,
//
headers: {Authorization: "Bearer " + getToken()},
//
url: process.env.VUE_APP_BASE_API + "/system/user/importData",
},
//
queryParams: {
type: 'day',
startTime: '',
endTime: '',
energyType: 2,
businessId: '',
},
//
columns: [
{key: 'businessName', label: '业态名称', visible: true},
{key: 'monitorId', label: '计量设备编号', visible: true},
{key: 'monitorName', label: '计量设备名称', visible: true},
{key: 'expend', label: '能耗值(kW·h)', visible: true},
],
//+线
option: {
title: {
text: "环比分析",
left: "center",
},
tooltip: {
trigger: "axis",
formatter: function (params) {
var relvsl = '';
for (var i = 0, l = params.length; i < l; i++) {
relvsl += params[i].marker + ' ' + params[i].seriesName + "(KW-h):" + params[i].data + '<br>'
}
return params[0].name + '<br>' + relvsl
},
axisPointer: {
type: "cross",
crossStyle: {
color: "#999",
},
},
},
legend: {
data: [],
right: "5%",
},
xAxis: [
{
type: "category",
data: [],
axisPointer: {
type: "shadow",
},
},
],
yAxis: [
{
type: "value",
name: "单位:KW-h",
axisLine: {
show: true,
}
},
],
series: [
{
name: "",
type: "bar",
tooltip: {
valueFormatter: function (value) {
return value;
},
},
data: [],
},
],
},
optionTwo: {
title: {
text: "能耗曲线",
left: "center",
},
tooltip: {
trigger: "axis",
formatter: function (params) {
var relvsl = '';
for (var i = 0, l = params.length; i < l; i++) {
relvsl += params[i].marker + ' ' + params[i].seriesName + "(KW-h):" + params[i].data + '<br>'
}
return params[0].name + '<br>' + relvsl
},
},
legend: {
data: [],
right: '5%',
},
grid: {
left: "3%",
right: "4%",
bottom: "3%",
containLabel: true,
},
xAxis: {
type: "category",
boundaryGap: false,
data: [],
},
yAxis: {
type: "value",
name: "单位:KW-h",
axisLine: {
show: true,
}
},
series: [],
},
dynamicTags: [],
//
timeRangeOptions: [
// {label: "", value: "hour"},
{label: "日", value: "day"},
{label: "月", value: "month"},
{label: "年", value: "year"},
],
//
chartOptions: {
pieChart: {
title: {text: "能耗占比", left: "center"},
tooltip: {
trigger: "item",
formatter: "{b}<br/>用电量: {c} kW·h<br/>占比: {d}%"
},
legend: {
orient: "vertical",
top: '80%',
left: "center",
data: []
},
series: [
{
name: "能耗占比",
type: "pie",
radius: ["40%", "70%"],
avoidLabelOverlap: false,
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2
},
label: {
show: false,
formatter: '{b}: {d}%'
},
labelLine: {
show: false
},
emphasis: {
label: {
show: false,
fontSize: '16',
fontWeight: 'bold'
}
},
data: []
}
]
},
lineChart: {
title: {text: "能耗趋势", left: "center"},
tooltip: {
trigger: "axis",
formatter: function(params) {
return params[0].name + '<br/>' +
params[0].seriesName + ': ' +
params[0].value.toFixed(2) + ' kW·h';
}
},
legend: {data: [], right: "5%"},
grid: {
left: "3%",
right: "4%",
bottom: "3%",
containLabel: true
},
xAxis: {
type: "category",
boundaryGap: false,
data: [],
axisLabel: {
rotate: 45
}
},
yAxis: {
type: "value",
name: "单位:kW·h",
axisLine: {show: true},
axisLabel: {
formatter: '{value}'
}
},
series: []
}
},
//
tableData: [],
//
totalExpend: 0,
};
},
watch: {
//
deptName(val) {
this.$refs.tree.filter(val);
},
},
created() {
this.initDateTime();
this.getDeptTree();
},
mounted() {
this.initCharts();
},
methods: {
//
initDateTime() {
const now = new Date();
const startTime = new Date(now.setHours(0, 0, 0, 0));
const endTime = new Date(now.setHours(23, 59, 59, 999));
this.queryParams.startTime = this.formatDateTime(startTime, this.queryParams.type);
this.queryParams.endTime = this.formatDateTime(endTime, this.queryParams.type);
},
initCharts() {
const pieChart = echarts.init(document.getElementById("pieChart"));
const lineChart = echarts.init(document.getElementById("lineChart"));
pieChart.setOption(this.chartOptions.pieChart);
lineChart.setOption(this.chartOptions.lineChart);
},
//
formatDateTime(date, type) {
const pad = num => String(num).padStart(2, '0');
const year = date.getFullYear();
const month = pad(date.getMonth() + 1);
const day = pad(date.getDate());
const hours = pad(date.getHours());
const minutes = pad(date.getMinutes());
const seconds = pad(date.getSeconds());
switch (type) {
case 'year':
return `${year}-01-01 00:00:00`;
case 'month':
return `${year}-${month}-01 00:00:00`;
case 'day':
return `${year}-${month}-${day} 00:00:00`;
case 'hour':
default:
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
},
//
getEndDateTime(date, type) {
const pad = num => String(num).padStart(2, '0');
const year = date.getFullYear();
const month = pad(date.getMonth() + 1);
const day = pad(date.getDate());
switch (type) {
case 'year':
return `${year}-12-31 23:59:59`;
case 'month':
//
const lastDay = new Date(year, date.getMonth() + 1, 0).getDate();
return `${year}-${month}-${pad(lastDay)} 23:59:59`;
case 'day':
return `${year}-${month}-${day} 23:59:59`;
case 'hour':
default:
return `${year}-${month}-${day} 23:59:59`;
}
},
//
handleTimeRangeChange(type) {
const now = new Date();
const startTime = new Date(now.setHours(0, 0, 0, 0));
const endTime = new Date(now.setHours(23, 59, 59, 999));
this.queryParams.startTime = this.formatDateTime(startTime, type);
this.queryParams.endTime = this.getEndDateTime(endTime, type);
this.handleQuery();
},
//
tranListToTreeData(list) {
//
const treeList = []
// 使
const map = {}
// id
list.forEach(item => {
if (!item.children) {
item.children = []
}
map[item.id] = item
})
list.forEach(item => {
//
// children
// treeList
const parent = map[item.pId]
// item
if (parent) {
parent.children.push(item)
} else {
//
treeList.push(item)
}
})
//
return treeList
},
/** 查询部门下拉树结构 */
getDeptTree() {
treeDattwo().then((response) => {
response.map((item, index) => {
item,
item.oid = item.id,
item.lable = item.name
})
this.deptOptions = this.tranListToTreeData(response);
console.log(this.deptOptions)
//this.deptOptions = response.data;
});
},
//
filterNode(value, data) {
if (!value) return true;
return data.lable.indexOf(value) !== -1;
},
//
handleNodeClick(data) {
console.log("data", data);
this.queryParams.businessId = data.id; //
// this.dynamicTags.push({label: data.name, value: data.id});
this.handleQuery();
},
//tag
handleClose(item) {
this.dynamicTags.splice(this.dynamicTags.indexOf(item), 1);
let querydata = [];
this.dynamicTags.map((item) => {
querydata.push(item.value);
});
querydata.toString();
this.handleQuery();
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
userId: undefined,
monitorId: undefined,
userName: undefined,
nickName: undefined,
password: undefined,
phonenumber: undefined,
email: undefined,
sex: undefined,
status: "0",
remark: undefined,
postIds: [],
roleIds: [],
};
this.resetForm("form");
},
/** 搜索按钮操作 */
async handleQuery() {
this.loading = true; //
try {
// 线
const response = await getBusinessEnergyConsumptionAnalysis({
type: this.queryParams.type,
startTime: this.queryParams.startTime,
endTime: this.queryParams.endTime,
businessId: this.queryParams.businessId,
energyType: 2
});
// 线
this.updateEnergyChart(response.data);
} catch (error) {
console.error('获取数据失败:', error);
} finally {
this.loading = false; //
}
},
// 线
updateEnergyChart(data) {
//
this.updateTableData(data);
//
this.totalExpend = data.totalExpend || 0;
// 线
const lineChart = echarts.init(document.getElementById("lineChart"));
const xAxisData = data.lineDnbList.map(item => item.begin_time);
const seriesData = [{
name: '能耗值',
type: 'line',
data: data.lineDnbList.map(item => item.expend)
}];
this.chartOptions.lineChart.xAxis.data = xAxisData;
this.chartOptions.lineChart.series = seriesData;
lineChart.setOption(this.chartOptions.lineChart);
//
const pieChart = echarts.init(document.getElementById("pieChart"));
const pieData = Object.entries(data.pieMap).map(([name, value]) => ({
name: name,
value: value
}));
this.chartOptions.pieChart.legend.data = pieData.map(item => item.name);
this.chartOptions.pieChart.series[0].data = pieData;
pieChart.setOption(this.chartOptions.pieChart);
},
//
updateTableData(data) {
this.tableData = data.tableList;
this.loading = false;
},
},
computed: {
getDatePickerType() {
switch (this.queryParams.type) {
case 'year':
return 'year';
case 'month':
return 'month';
case 'day':
return 'date';
case 'hour':
default:
return 'date';
}
},
getDatePickerPlaceholder() {
switch (this.queryParams.type) {
case 'year':
return '选择年份';
case 'month':
return '选择月份';
case 'day':
return '选择日期';
case 'hour':
default:
return '选择日期时间';
}
}
},
};
</script>
<style lang="scss" scoped>
.tree {
width: 220px;
::v-deep .el-tree-node {
white-space: normal;
.el-tree-node__content {
height: 100%;
align-items: start;
}
}
}
.mx-2 {
margin: 0 8px;
}
.search-form {
margin-bottom: 20px;
padding: 20px;
background: #fff;
border-radius: 4px;
}
.chart-card {
height: 400px;
margin-bottom: 20px;
::v-deep .el-card__body {
height: 100%;
padding: 20px;
}
}
.total-expend {
text-align: center;
font-size: 16px;
font-weight: bold;
color: #303133;
margin-top: 0px;
}
</style>
Loading…
Cancel
Save