|
|
|
|
@ -12,7 +12,7 @@
|
|
|
|
|
label-width="68px"
|
|
|
|
|
>
|
|
|
|
|
<el-form-item label="能源类型" prop="energyType">
|
|
|
|
|
<el-select v-model="queryParams.energyType" style="width: 100px" placeholder="请选择能源类型">
|
|
|
|
|
<el-select v-model="queryParams.energyType" style="width: 100px" placeholder="请选择能源类型" @change="handleEnergyTypeChange">
|
|
|
|
|
<el-option
|
|
|
|
|
v-for="item in energyTypeList"
|
|
|
|
|
:key="item.energyTypeId"
|
|
|
|
|
@ -223,6 +223,7 @@ export default {
|
|
|
|
|
totalConsumption: 0,
|
|
|
|
|
//计量单位
|
|
|
|
|
measurementUnit: 'kW·h',
|
|
|
|
|
chartInstance: null,
|
|
|
|
|
//采集方式
|
|
|
|
|
dateTypeList: [
|
|
|
|
|
{ label: '时', value: '13' },
|
|
|
|
|
@ -242,8 +243,9 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
tooltip: {
|
|
|
|
|
trigger: 'axis',
|
|
|
|
|
formatter: function(params) {
|
|
|
|
|
return params.data + 'kW·h'
|
|
|
|
|
formatter: (params) => {
|
|
|
|
|
const value = Array.isArray(params) ? params[0]?.data : params?.data
|
|
|
|
|
return `${value}${this.measurementUnit}`
|
|
|
|
|
},
|
|
|
|
|
textStyle: {
|
|
|
|
|
align: 'left'
|
|
|
|
|
@ -368,22 +370,32 @@ export default {
|
|
|
|
|
this.handleQuery()
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
getDateList(startTime, endTime) {
|
|
|
|
|
if (this.queryParams.dateType === '13') {
|
|
|
|
|
return getHoursBetween(startTime, endTime)
|
|
|
|
|
} else if (this.queryParams.dateType === '10') {
|
|
|
|
|
return getDatesBetween(startTime, endTime)
|
|
|
|
|
} else if (this.queryParams.dateType === '7') {
|
|
|
|
|
return getMonthsBetween(startTime, endTime)
|
|
|
|
|
} else if (this.queryParams.dateType === '4') {
|
|
|
|
|
return getYearsBetween(startTime, endTime)
|
|
|
|
|
updateMeasurementUnit() {
|
|
|
|
|
const unitMap = {
|
|
|
|
|
2: 'kW·h',
|
|
|
|
|
3: 'm³',
|
|
|
|
|
4: 't',
|
|
|
|
|
5: 'm³',
|
|
|
|
|
6: 'm³'
|
|
|
|
|
}
|
|
|
|
|
this.measurementUnit = unitMap[Number(this.queryParams.energyType)] || 'kW·h'
|
|
|
|
|
},
|
|
|
|
|
barChart() {
|
|
|
|
|
var chartDom = document.getElementById('card')
|
|
|
|
|
var myChart = echarts.init(chartDom)
|
|
|
|
|
let data = []
|
|
|
|
|
const createLinearGradient = (startColor, endColor) => ({
|
|
|
|
|
handleEnergyTypeChange() {
|
|
|
|
|
this.updateMeasurementUnit()
|
|
|
|
|
this.handleQuery()
|
|
|
|
|
},
|
|
|
|
|
getDateList(startTime, endTime) {
|
|
|
|
|
const dateTypeHandlerMap = {
|
|
|
|
|
'13': getHoursBetween,
|
|
|
|
|
'10': getDatesBetween,
|
|
|
|
|
'7': getMonthsBetween,
|
|
|
|
|
'4': getYearsBetween
|
|
|
|
|
}
|
|
|
|
|
const handler = dateTypeHandlerMap[this.queryParams.dateType]
|
|
|
|
|
return handler ? handler(startTime, endTime) : []
|
|
|
|
|
},
|
|
|
|
|
createLinearGradient(startColor, endColor) {
|
|
|
|
|
return {
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
x2: 0,
|
|
|
|
|
@ -394,56 +406,77 @@ export default {
|
|
|
|
|
{ offset: 0, color: startColor },
|
|
|
|
|
{ offset: 1, color: endColor }
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
buildChartSeriesData(rows) {
|
|
|
|
|
if (!rows.length || parseFloat(rows[0].expendSum || 0) <= 0) {
|
|
|
|
|
return { xAxisData: [], seriesData: [] }
|
|
|
|
|
}
|
|
|
|
|
const dateDataKeys = Object.keys(rows[0]).filter((key) => key.includes('dateData|'))
|
|
|
|
|
const sortedData = dateDataKeys.map((key) => {
|
|
|
|
|
const time = `${key.split('dateData|')[1]}:00:00`
|
|
|
|
|
const value = rows.reduce((sum, item) => sum + parseFloat(item[key] || 0), 0)
|
|
|
|
|
return {
|
|
|
|
|
time,
|
|
|
|
|
value: Number(value.toFixed(2)),
|
|
|
|
|
timestamp: new Date(time).getTime()
|
|
|
|
|
}
|
|
|
|
|
}).sort((a, b) => a.timestamp - b.timestamp)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
xAxisData: sortedData.map((item) => item.time.split(':')[0]),
|
|
|
|
|
seriesData: sortedData.map((item) => item.value)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
buildChartOption() {
|
|
|
|
|
const axisStyle = {
|
|
|
|
|
axisLabel: { color: '#333', fontSize: 14 },
|
|
|
|
|
axisLabel: { color: '#333', fontSize: 12 },
|
|
|
|
|
axisTick: { lineStyle: { color: '#384267', width: 1 }, show: true },
|
|
|
|
|
axisLine: { lineStyle: { color: 'rgba(255,255,255,0.1)', width: 1 }, show: true }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const option = {
|
|
|
|
|
const barColor = this.createLinearGradient(optionData?.bgColor || '#0a8ff6', '#06f8f7')
|
|
|
|
|
return {
|
|
|
|
|
grid: {
|
|
|
|
|
containLabel: true,
|
|
|
|
|
left: '2%',
|
|
|
|
|
right: '2%',
|
|
|
|
|
bottom: '5%',
|
|
|
|
|
bottom: '10%',
|
|
|
|
|
top: 20
|
|
|
|
|
},
|
|
|
|
|
tooltip: {
|
|
|
|
|
trigger: 'axis',
|
|
|
|
|
formatter: (params) => `${params[0].name}<br>${params[0].marker} ${params[0].data}kW·h`
|
|
|
|
|
formatter: (params) => `${params[0].name}<br>${params[0].marker} ${params[0].data}${this.measurementUnit}`
|
|
|
|
|
},
|
|
|
|
|
xAxis: [
|
|
|
|
|
{
|
|
|
|
|
...axisStyle,
|
|
|
|
|
data: [],
|
|
|
|
|
type: 'category',
|
|
|
|
|
splitLine: { show: false }
|
|
|
|
|
xAxis: [{
|
|
|
|
|
...axisStyle,
|
|
|
|
|
data: [],
|
|
|
|
|
type: 'category',
|
|
|
|
|
splitLine: { show: false },
|
|
|
|
|
axisLabel: {
|
|
|
|
|
...axisStyle.axisLabel,
|
|
|
|
|
rotate: 0
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
}],
|
|
|
|
|
yAxis: {
|
|
|
|
|
...axisStyle,
|
|
|
|
|
splitLine: { show: true, lineStyle: { color: 'rgba(255,255,255,0.1)' } },
|
|
|
|
|
name: ''
|
|
|
|
|
name: this.measurementUnit
|
|
|
|
|
},
|
|
|
|
|
dataZoom: [],
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
data: data,
|
|
|
|
|
data: [],
|
|
|
|
|
type: 'bar',
|
|
|
|
|
barMaxWidth: 20,
|
|
|
|
|
barWidth: '75%',
|
|
|
|
|
itemStyle: {
|
|
|
|
|
color: createLinearGradient(optionData?.bgColor || '#0a8ff6', '#06f8f7')
|
|
|
|
|
}
|
|
|
|
|
barWidth: '70%',
|
|
|
|
|
itemStyle: { color: barColor }
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
data: data,
|
|
|
|
|
data: [],
|
|
|
|
|
type: 'line',
|
|
|
|
|
stack: '总量',
|
|
|
|
|
symbol: 'circle',
|
|
|
|
|
symbolSize: 8,
|
|
|
|
|
symbolSize: 6,
|
|
|
|
|
itemStyle: {
|
|
|
|
|
normal: {
|
|
|
|
|
borderWidth: 2,
|
|
|
|
|
@ -456,63 +489,40 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
myChart.setOption(option)
|
|
|
|
|
},
|
|
|
|
|
barChart() {
|
|
|
|
|
const chartDom = document.getElementById('card')
|
|
|
|
|
if (!chartDom) return
|
|
|
|
|
if (this.chartInstance) {
|
|
|
|
|
this.chartInstance.dispose()
|
|
|
|
|
}
|
|
|
|
|
this.chartInstance = echarts.init(chartDom)
|
|
|
|
|
this.chartInstance.setOption(this.buildChartOption())
|
|
|
|
|
energyPreviewReportList(this.queryParams).then((response) => {
|
|
|
|
|
this.dataList = this.handleTree(response.data, 'objId');
|
|
|
|
|
|
|
|
|
|
this.dataList = this.handleTree(response.data, 'objId')
|
|
|
|
|
this.loading = false
|
|
|
|
|
const data = response.data || []
|
|
|
|
|
if (data.length === 0) return
|
|
|
|
|
this.totalConsumption = data.reduce((sum, item) => {
|
|
|
|
|
return sum + parseFloat(item.expendSum || 0);
|
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
|
|
if (parseFloat(data[0].expendSum) > 0){
|
|
|
|
|
const keys = Object.keys(data[0])
|
|
|
|
|
const filteredKeys = keys.filter(item => item.includes('dateData|'));
|
|
|
|
|
|
|
|
|
|
const yData = filteredKeys.map(key => {
|
|
|
|
|
return data.reduce((sum, item) => sum + parseFloat(item[key] || 0), 0).toFixed(2)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const timeData = filteredKeys.map(key => key.split('dateData|')[1] + ':00:00')
|
|
|
|
|
|
|
|
|
|
const sortedData = timeData.map((time, index) => ({
|
|
|
|
|
name: time,
|
|
|
|
|
value: parseFloat(yData[index]),
|
|
|
|
|
time: new Date(time).getTime()
|
|
|
|
|
})).sort((a, b) => b.time - a.time);
|
|
|
|
|
|
|
|
|
|
console.log(sortedData)
|
|
|
|
|
|
|
|
|
|
const xAxisData = sortedData.map(item => item.name.split(':')[0])
|
|
|
|
|
const seriesData = sortedData.map(item => item.value)
|
|
|
|
|
myChart.setOption({
|
|
|
|
|
dataZoom: [{
|
|
|
|
|
show: true,
|
|
|
|
|
type: 'slider',
|
|
|
|
|
bottom: '3%',
|
|
|
|
|
xAxisIndex: 0,
|
|
|
|
|
height: 12,
|
|
|
|
|
start: 0,
|
|
|
|
|
brushSelect: false,
|
|
|
|
|
end: (1 / (seriesData.length / 20)) * 100,
|
|
|
|
|
textStyle: {
|
|
|
|
|
fontSize: 0,
|
|
|
|
|
color: 'rgba(0,0,0,0)'
|
|
|
|
|
}
|
|
|
|
|
}],
|
|
|
|
|
xAxis: [{
|
|
|
|
|
data: xAxisData
|
|
|
|
|
}],
|
|
|
|
|
series: [{
|
|
|
|
|
data: seriesData
|
|
|
|
|
}, {
|
|
|
|
|
data: seriesData
|
|
|
|
|
}]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const rows = response.data || []
|
|
|
|
|
this.totalConsumption = rows.reduce((sum, item) => sum + parseFloat(item.expendSum || 0), 0)
|
|
|
|
|
const { xAxisData, seriesData } = this.buildChartSeriesData(rows)
|
|
|
|
|
const sliderEnd = seriesData.length <= 20 ? 100 : (20 / seriesData.length) * 100
|
|
|
|
|
this.chartInstance.setOption({
|
|
|
|
|
dataZoom: seriesData.length ? [{
|
|
|
|
|
show: true,
|
|
|
|
|
type: 'slider',
|
|
|
|
|
bottom: '3%',
|
|
|
|
|
xAxisIndex: 0,
|
|
|
|
|
height: 12,
|
|
|
|
|
start: 0,
|
|
|
|
|
brushSelect: false,
|
|
|
|
|
end: sliderEnd,
|
|
|
|
|
textStyle: {
|
|
|
|
|
fontSize: 0,
|
|
|
|
|
color: 'rgba(0,0,0,0)'
|
|
|
|
|
}
|
|
|
|
|
}] : [],
|
|
|
|
|
xAxis: [{ data: xAxisData }],
|
|
|
|
|
series: [{ data: seriesData }, { data: seriesData }]
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
@ -535,7 +545,7 @@ export default {
|
|
|
|
|
this.energyList = []
|
|
|
|
|
this.timeList.push(
|
|
|
|
|
{
|
|
|
|
|
title: '用电类型名称',
|
|
|
|
|
title: '类型名称',
|
|
|
|
|
field: 'unitName',
|
|
|
|
|
align: 'center',
|
|
|
|
|
rowspan: 2
|
|
|
|
|
@ -578,6 +588,7 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
/** 搜索按钮操作 */
|
|
|
|
|
handleQuery() {
|
|
|
|
|
this.updateMeasurementUnit()
|
|
|
|
|
let dateList = this.getDateList(
|
|
|
|
|
this.queryParams.startTime,
|
|
|
|
|
this.queryParams.endTime
|
|
|
|
|
@ -586,9 +597,11 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
/** 重置按钮操作 */
|
|
|
|
|
resetQuery() {
|
|
|
|
|
this.queryParams.energyType = 2
|
|
|
|
|
this.queryParams.dateType = '10'
|
|
|
|
|
this.queryParams.startTime = ''
|
|
|
|
|
this.queryParams.endTime = ''
|
|
|
|
|
this.updateMeasurementUnit()
|
|
|
|
|
this.handleQuery()
|
|
|
|
|
},
|
|
|
|
|
// 多选框选中数据
|
|
|
|
|
|