Compare commits

..

No commits in common. "b6d3b17300caec99da6ea620208d22da1c4387a3" and "0dae8cd16d8a16264fc1384e1d46cff4a04742f3" have entirely different histories.

20 changed files with 3422 additions and 3816 deletions

View File

@ -18,9 +18,9 @@ VUE_APP_TITLE = MES系统
# VUE_APP_BASE_API = 'http://192.168.2.173:48080' # VUE_APP_BASE_API = 'http://192.168.2.173:48080'
# VUE_APP_BASE_API = 'http://192.168.1.49:48082' # VUE_APP_BASE_API = 'http://192.168.1.49:48082'
# VUE_APP_BASE_API = 'http://192.168.1.8:48082' # VUE_APP_BASE_API = 'http://192.168.1.8:48082'
VUE_APP_BASE_API = 'http://192.168.4.173:48082' # VUE_APP_BASE_API = 'http://192.168.4.159:48080'
# VUE_APP_BASE_API = 'http://192.168.1.104:48082' # VUE_APP_BASE_API = 'http://192.168.1.104:48082'
# VUE_APP_BASE_API = 'http://192.168.0.33:48082' VUE_APP_BASE_API = 'http://192.168.0.33:48082'
# VUE_APP_BASE_API = 'http://192.168.1.62:48082' # VUE_APP_BASE_API = 'http://192.168.1.62:48082'
# VUE_APP_BASE_API = 'http://192.168.1.78:48082' # VUE_APP_BASE_API = 'http://192.168.1.78:48082'
# VUE_APP_BASE_API = 'http://192.168.1.47:48082' # VUE_APP_BASE_API = 'http://192.168.1.47:48082'

View File

@ -35,21 +35,3 @@ export function getQoq(data) {
data: data data: data
}) })
} }
// 获取能源设备树
export function getTree() {
return request({
url: '/analysis/energy-analysis/getTree',
method: 'get'
})
}
// 导出(走势分析)
export function exportTrend(data) {
return request({
url: '/analysis/energy-analysis/exportTrend',
method: 'post',
responseType: 'blob',
data: data
})
}

View File

@ -68,4 +68,3 @@ export function exportEnergyTypeExcel(query) {
responseType: 'blob' responseType: 'blob'
}) })
} }

View File

@ -97,8 +97,6 @@ export const DICT_TYPE = {
TABLE_NAME: 'table_name', TABLE_NAME: 'table_name',
METHOD: 'method', METHOD: 'method',
PUSH: 'push', PUSH: 'push',
ENERGY_TYPE: 'energy_type',
// ============== ORDER - 订单模块 ============= // ============== ORDER - 订单模块 =============
ORDER_STATUS: 'order_status', ORDER_STATUS: 'order_status',

View File

@ -2,43 +2,44 @@
<div <div
id="analysischartBar" id="analysischartBar"
style="width: 100%" style="width: 100%"
:style="{ height: chartHeight + 'px' }"></div> :style="{ height: chartHeight + 'px' }"
></div>
</template> </template>
<script> <script>
import * as echarts from 'echarts'; import * as echarts from 'echarts'
import resize from '@/utils/chartMixins/resize'; import resize from '@/utils/chartMixins/resize'
export default { export default {
name: 'BarChart', name: "BarChart",
mixins: [resize], mixins: [resize],
data() { data() {
return { return {
chartDom: '', chartDom: '',
chart: '', chart: '',
chartHeight: this.tableHeight(250) / 2, chartHeight: this.tableHeight(214) - 70
}; }
}, },
props: { props: {
chartData: { chartData: {
type: Array, type: Array,
required: true, required: true,
default: () => { default: () => {
return []; return []
}, }
}, },
timeDim: { timeDim: {
type: String, type: String,
default: '', default: ''
}, }
}, },
watch: { watch: {
chartData: function () { chartData: function () {
this.getChart(); this.getChart()
}, }
}, },
mounted() { mounted() {
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
this.chartHeight = this.tableHeight(250) / 2; this.chartHeight = this.tableHeight(214) - 70
}); })
}, },
methods: { methods: {
getChart() { getChart() {
@ -47,29 +48,29 @@ export default {
this.chart !== '' && this.chart !== '' &&
this.chart !== undefined this.chart !== undefined
) { ) {
this.chart.dispose(); // Dom this.chart.dispose() // Dom
} }
this.chartDom = document.getElementById('analysischartBar'); this.chartDom = document.getElementById('analysischartBar')
this.chart = echarts.init(this.chartDom); this.chart = echarts.init(this.chartDom)
let tempArr = []; let tempArr = []
let xData = []; let xData = []
let yData = []; let yData = []
let legendData = []; let legendData = []
if (this.chartData.length === 0) { if (this.chartData.length === 0) {
return false; return false
} else { } else {
tempArr = this.chartData[0].trendRespVOList; tempArr = this.chartData[0].trendRespVOList
} }
for (let k = 0; k < tempArr.length; k++) { for (let k = 0; k < tempArr.length; k++) {
let time = ''; let time = ''
if (this.timeDim === '3') { if (this.timeDim === '3') {
let year = tempArr[k].time.slice(0, 4); let year = tempArr[k].time.slice(0,4)
let weak = tempArr[k].time.slice(4, 6); let weak = tempArr[k].time.slice(4,6)
time = year + ' 第 ' + weak + ' 周'; time = year+' 第 '+weak+' 周'
} else { } else {
time = tempArr[k].time; time = tempArr[k].time
} }
xData.push(time); xData.push(time)
} }
for (let i = 0; i < this.chartData.length; i++) { for (let i = 0; i < this.chartData.length; i++) {
let obj = { let obj = {
@ -78,72 +79,70 @@ export default {
barMaxWidth: 20, barMaxWidth: 20,
label: { label: {
show: true, show: true,
position: 'top', position: 'top'
}, },
data: [], data: []
};
legendData.push(this.chartData[i].objName + this.chartData[i].objCode);
let temp = this.chartData[i].trendRespVOList;
for (let j = 0; j < temp.length; j++) {
let num = temp[j].useNum ? temp[j].useNum.toFixed(2) : '';
obj.data.push(num);
} }
yData.push(obj); legendData.push(this.chartData[i].objName + this.chartData[i].objCode)
let temp = this.chartData[i].trendRespVOList
for (let j = 0; j < temp.length; j++) {
let num = temp[j].useNum ? temp[j].useNum : ''
obj.data.push(num)
}
yData.push(obj)
} }
var option = { var option = {
color: ['#FFDC94', '#8EF0AB', '#63BDFF', '#288AFF', '#7164FF'], color:['#FFDC94','#8EF0AB','#63BDFF','#288AFF','#7164FF'],
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
axisPointer: { axisPointer: {
type: 'shadow', type: 'shadow'
}, },
formatter: function (params) { formatter: function(params) {
return ( return (
params[0].axisValue + params[0].axisValue +
`<br>` + `<br>` +
params params.map((item) => {
.map((item) => { let str = `<span style="display:inline-block;width:8px;height:8px;margin: 0 8px 0 -3px;border-radius:2px;background-color:${item.color};"></span>`
let str = `<span style="display:inline-block;width:8px;height:8px;margin: 0 8px 0 -3px;border-radius:2px;background-color:${item.color};"></span>`; let seriesNameStr = `<span style="display:inline-block;">${item.seriesName}</span>`
let seriesNameStr = `<span style="display:inline-block;">${item.seriesName}</span>`; let value = item.value ? item.value : '-'
let value = item.value ? item.value : '-'; let valueStr = `<span style="display:inline-block;margin-left:10px;color:rgba(0,0,0,0.45);">${value}</span>`
let valueStr = `<span style="display:inline-block;margin-left:10px;color:rgba(0,0,0,0.45);">${value}</span>`;
return `<span style="display:flex; justify-content:space-between; margin-bottom: 2px"> return `<span style="display:flex; justify-content:space-between; margin-bottom: 2px">
<span>${str}${seriesNameStr}</span> <span>${str}${seriesNameStr}</span>
<span>${valueStr}</span> <span>${valueStr}</span>
</span>`; </span>`
}) }).join(``)
.join(``) )
); }
},
}, },
grid: { grid: {
left: '4%', left: '4%',
right: '1%', right: '1%',
bottom: '1%', bottom: '1%',
containLabel: true, containLabel: true
}, },
legend: { legend: {
data: legendData, data: legendData,
right: '1%', right: '1%',
icon: 'rect', icon: 'rect',
itemHeight: 8, itemHeight: 8,
itemWidth: 8, itemWidth: 8
}, },
xAxis: { xAxis: {
type: 'category', type: 'category',
data: xData, data: xData,
axisLabel: { axisLabel: {
rotate: '45', rotate: "45"
}, }
}, },
yAxis: { yAxis: {
type: 'value', type: 'value'
}, },
series: yData, series: yData
}; };
option && this.chart.setOption(option); option && this.chart.setOption(option);
}, }
}, }
}; }
</script> </script>

View File

@ -0,0 +1,126 @@
<template>
<div
id="analysischartLine"
style="width: 100%"
:style="{ height: chartHeight + 'px' }"
></div>
</template>
<script>
import * as echarts from 'echarts'
import resize from '@/utils/chartMixins/resize'
export default {
name: "LineChart",
mixins: [resize],
data() {
return {
chartDom: '',
chart: '',
chartHeight: this.tableHeight(214) - 70
}
},
props: {
chartData: {
type: Array,
required: true,
default: () => {
return []
}
},
timeDim: {
type: String,
default: ''
}
},
watch: {
chartData: function () {
this.getChart()
}
},
mounted() {
window.addEventListener('resize', () => {
this.chartHeight = this.tableHeight(214) - 70
})
},
methods: {
getChart() {
if (
this.chart !== null &&
this.chart !== '' &&
this.chart !== undefined
) {
this.chart.dispose() // Dom
}
this.chartDom = document.getElementById('analysischartLine')
this.chart = echarts.init(this.chartDom)
let tempArr = []
let xData = []
let yData = []
let legendData = []
if (this.chartData.length === 0) {
return false
} else {
tempArr = this.chartData[0].trendRespVOList
}
for (let k = 0; k < tempArr.length; k++) {
let time = ''
if (this.timeDim === '3') {
let year = tempArr[k].time.slice(0,4)
let weak = tempArr[k].time.slice(4,6)
time = year+' 第 '+weak+' 周'
} else {
time = tempArr[k].time
}
xData.push(time)
}
for (let i = 0; i < this.chartData.length; i++) {
let obj = {
name: this.chartData[i].objName + this.chartData[i].objCode,
type: 'line',
stack: 'Total',
data: []
}
legendData.push(this.chartData[i].objName + this.chartData[i].objCode)
let temp = this.chartData[i].trendRespVOList
for (let j = 0; j < temp.length; j++) {
let num = temp[j].useNum ? temp[j].useNum : ''
obj.data.push(num)
}
yData.push(obj)
}
var option = {
color:['#FFDC94','#8EF0AB','#63BDFF','#288AFF','#7164FF'],
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
}
},
grid: {
left: '4%',
right: '1%',
bottom: '1%',
containLabel: true
},
legend: {
data: legendData,
right: '1%'
},
xAxis: {
type: 'category',
data: xData,
axisLabel: {
rotate: "45"
}
},
yAxis: {
type: 'value'
},
series: yData
};
option && this.chart.setOption(option);
}
}
}
</script>

View File

@ -1,47 +1,28 @@
<template> <template>
<div <div class="searchBarBox divHeight" ref="searchBarRef" :style="{ paddingRight: isFold ? '55px' : '0px' }">
class="searchBarBox divHeight" <el-form :inline="true" class="demo-form-inline">
ref="searchBarRef"
:style="{ paddingRight: isFold ? '55px' : '0px' }">
<el-form
:inline="true"
class="demo-form-inline">
<span class="blue-block"></span> <span class="blue-block"></span>
<el-form-item <el-form-item label="能源类型" required>
label="能源类型" <el-select v-model="queryParams.energyTypeId" placeholder="请选择" style="width: 100px;" size="small">
required>
<el-select
v-model="queryParams.energyTypeId"
placeholder="请选择"
style="width: 150px"
@change="chooseType"
filterable
size="small">
<el-option <el-option
v-for="item in energyTypeList" v-for="item in energyTypeList"
:key="item.id" :key="item.id"
:label="item.labelName" :label="item.name"
:value="item.id"></el-option> :value="item.id">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="时间维度" required>
label="时间维度" <el-select v-model="queryParams.timeDim" placeholder="请选择" style="width: 80px;" size="small">
required>
<el-select
v-model="queryParams.timeDim"
placeholder="请选择"
style="width: 80px"
size="small">
<el-option <el-option
v-for="item in getDictDatas(this.DICT_TYPE.TIME_DIM)" v-for="item in getDictDatas(this.DICT_TYPE.TIME_DIM)"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
:value="item.value"></el-option> :value="item.value">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="时间范围" required>
label="时间范围"
required>
<div v-show="queryParams.timeDim === '1'"> <div v-show="queryParams.timeDim === '1'">
<el-date-picker <el-date-picker
v-model="timeValue" v-model="timeValue"
@ -55,8 +36,10 @@
popper-class="noneMinute" popper-class="noneMinute"
@change="timeSelect" @change="timeSelect"
size="small" size="small"
style="width: 350px" style='width:350px;'
:clearable="false"></el-date-picker> :clearable="false"
>
</el-date-picker>
</div> </div>
<div v-show="queryParams.timeDim === '2'"> <div v-show="queryParams.timeDim === '2'">
<el-date-picker <el-date-picker
@ -69,31 +52,34 @@
:picker-options="pickerOptions" :picker-options="pickerOptions"
:clearable="false" :clearable="false"
size="small" size="small"
style="width: 350px" style='width:350px;'
@change="timeSelect"></el-date-picker> @change="timeSelect"
>
</el-date-picker>
</div> </div>
<div v-show="queryParams.timeDim === '3'"> <div v-show="queryParams.timeDim === '3'">
<el-date-picker <el-date-picker
v-model="weekValue1" v-model="weekValue1"
type="week" type="week"
format="yyyy 第 WW 周" format="yyyy 第 WW 周"
style="width: 170px" style='width:170px;'
:picker-options="pickerOptionsWeek" :picker-options="pickerOptionsWeek"
@change="startWeek" @change="startWeek"
:clearable="false" :clearable="false"
size="small" size="small"
placeholder="选择周"></el-date-picker> placeholder="选择周">
- </el-date-picker>-
<el-date-picker <el-date-picker
v-model="weekValue2" v-model="weekValue2"
type="week" type="week"
format="yyyy 第 WW 周" format="yyyy 第 WW 周"
:picker-options="pickerOptionsWeek" :picker-options="pickerOptionsWeek"
style="width: 170px" style='width:170px;'
@change="endWeek" @change="endWeek"
:clearable="false" :clearable="false"
size="small" size="small"
placeholder="选择周"></el-date-picker> placeholder="选择周">
</el-date-picker>
</div> </div>
<div v-show="queryParams.timeDim === '4'"> <div v-show="queryParams.timeDim === '4'">
<el-date-picker <el-date-picker
@ -106,12 +92,14 @@
:clearable="false" :clearable="false"
:picker-options="pickerOptions" :picker-options="pickerOptions"
size="small" size="small"
style="width: 350px" style='width:350px;'
@change="timeSelect"></el-date-picker> @change="timeSelect"
>
</el-date-picker>
</div> </div>
<div v-show="queryParams.timeDim === '5'"> <div v-show="queryParams.timeDim === '5'">
<el-date-picker <el-date-picker
style="width: 170px" style='width:170px;'
v-model="yearValue1" v-model="yearValue1"
type="year" type="year"
:picker-options="pickerOptions" :picker-options="pickerOptions"
@ -119,10 +107,11 @@
placeholder="选择年" placeholder="选择年"
@change="startYear" @change="startYear"
size="small" size="small"
:clearable="false"></el-date-picker> :clearable="false"
- >
</el-date-picker>-
<el-date-picker <el-date-picker
style="width: 170px" style='width:170px;'
v-model="yearValue2" v-model="yearValue2"
type="year" type="year"
:picker-options="pickerOptions" :picker-options="pickerOptions"
@ -130,96 +119,58 @@
placeholder="选择年" placeholder="选择年"
@change="endYear" @change="endYear"
size="small" size="small"
:clearable="false"></el-date-picker> :clearable="false"
>
</el-date-picker>
</div> </div>
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="对象维度" required>
v-if="energyType !== 0" <el-select v-model="queryParams.objType" placeholder="请选择" style="width: 80px;" @change="selectObjs" size="small">
label="对象维度"
required>
<el-select
v-model="queryParams.objType"
placeholder="请选择"
style="width: 80px"
@change="selectObjs"
:disabled="energyType === 2"
size="small">
<el-option <el-option
v-for="item in getDictDatas(this.DICT_TYPE.OBJECT_TYPE)" v-for="item in getDictDatas(this.DICT_TYPE.OBJECT_TYPE)"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
:value="item.value"></el-option> :value="item.value">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="对象选择" required>
label="对象选择" <el-select v-model="queryParams.objIds" placeholder="请选择" multiple :multiple-limit='5' collapse-tags style="width: 200px;" size="small">
required>
<el-select
v-model="queryParams.objIds"
placeholder="请选择"
multiple
:multiple-limit="5"
collapse-tags
filterable
style="width: 200px"
size="small">
<el-option <el-option
v-for="item in objectList" v-for="item in objectList"
:key="item.id" :key="item.id"
:label="item.name" :label="item.name"
:value="item.id"> :value="item.id">
<span style="float: left">{{ item.name }}</span> <span style="float: left">{{ item.name }}</span>
<span style="float: right; color: #8492a6; font-size: 13px"> <span style="float: right; color: #8492a6; font-size: 13px">{{ item.code }}</span>
{{ item.code }}
</span>
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button <el-button type="primary" size="small" @click="search">查询</el-button>
type="primary"
size="small"
@click="search">
查询
</el-button>
<el-button
size="small"
@click="resetBtn">
重置
</el-button>
<span class="separateStyle"></span> <span class="separateStyle"></span>
<el-button <el-button size="small" @click="resetBtn">重置</el-button>
type="primary"
size="small"
plain
@click="exportBtn">
导出
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<span <span v-if="isFold" class="foldClass" @click='switchMode'>
v-if="isFold"
class="foldClass"
@click="switchMode">
{{ isExpand ? '收起' : '展开' }} {{ isExpand ? '收起' : '展开' }}
<svg-icon :icon-class="isExpand ? 'upward' : 'downward'" /> <svg-icon :icon-class="isExpand ? 'upward' : 'downward'" />
</span> </span>
</div> </div>
</template> </template>
<script> <script>
import { getEnergyTypeListAll } from '@/api/base/energyType'; import { getEnergyTypeListAll } from "@/api/base/energyType"
import { getLineAll } from '@/api/base/productionLine'; import { getLineAll } from "@/api/base/productionLine"
import { getWorkShopAll } from '@/api/base/workshopSection'; import { getWorkShopAll } from "@/api/base/workshopSection"
import { getFactoryList } from '@/api/core/base/factory'; import { getEquipmentAll } from "@/api/base/equipment"
import moment from 'moment'; import moment from 'moment'
export default { export default {
name: 'searchArea', name: 'searchArea',
props: { props: {
isFold: { isFold: {//
//
type: Boolean, type: Boolean,
default: false, default: false
}, }
}, },
data() { data() {
return { return {
@ -231,309 +182,275 @@ export default {
objType: '', objType: '',
timeDim: null, timeDim: null,
startTime: null, startTime: null,
endTime: null, endTime: null
}, },
energyType: 0, //12 timeValue: [],// 7
timeValue: [], // 7 dateValue: [],// 30
dateValue: [], // 30 weekValue1: null,//24
weekValue1: null, //24
weekValue2: null, weekValue2: null,
monthValue: [], //24 monthValue: [],//24
yearValue1: null, //10 yearValue1: null,//10
yearValue2: null, yearValue2: null,
energyTypeList: [], energyTypeList: [],
objectList: [], objectList: [],
pickerOptions: { pickerOptions: {
disabledDate(date) { disabledDate(date) {
return date.getTime() > Date.now(); return date.getTime() > Date.now()
}, }
}, },
pickerOptionsWeek: { pickerOptionsWeek: {
disabledDate(time) { disabledDate(time) {
let day = Date.now(); let day = Date.now()
let limitTime = moment(day).day(-1); let limitTime = moment(day).day(-1)
return time.getTime() > new Date(limitTime).getTime(); return time.getTime() > new Date(limitTime).getTime()
}, }
}, }
}; }
}, },
mounted() { mounted() {
this.getTypeList(); this.getTypeList()
this.queryParams.timeDim = this.getDictDatas( this.queryParams.timeDim = this.getDictDatas(this.DICT_TYPE.TIME_DIM)[0].value //
this.DICT_TYPE.TIME_DIM
)[0].value; //
}, },
methods: { methods: {
getTypeList() { getTypeList() {
getEnergyTypeListAll().then((res) => { getEnergyTypeListAll().then((res) => {
this.energyTypeList = res.data || []; this.energyTypeList = res.data || []
}); })
},
//
chooseType(id) {
let val;
this.energyTypeList.map((item) => {
if (item.id === id) {
val = item.name;
}
});
if (val == 1 || val == 2) {
this.energyType = 1;
this.queryParams.objType = null;
} else {
this.energyType = 2;
this.queryParams.objType = this.getDictDatas(
this.DICT_TYPE.OBJECT_TYPE
)[0].value;
}
this.selectObjs(this.queryParams.objType);
}, },
// //
timeSelect() { timeSelect() {
switch (this.queryParams.timeDim) { switch (this.queryParams.timeDim) {
case '1': case '1':
if (!this.timeValue) { if (!this.timeValue) {
this.$modal.msgError('时间范围不能为空'); this.$modal.msgError('时间范围不能为空')
return false; return false
} }
if (this.timeValue[1] - this.timeValue[0] > 7 * 24 * 3600000) { if (this.timeValue[1] - this.timeValue[0] > 7*24*3600000) {
this.$modal.msgError('最大时间范围为7天请重新选择'); this.$modal.msgError('最大时间范围为7天请重新选择')
this.timeValue = []; this.timeValue = []
} }
break; break
case '2': case '2':
if (!this.dateValue) { if (!this.dateValue) {
this.$modal.msgError('时间范围不能为空'); this.$modal.msgError('时间范围不能为空')
return false; return false
} }
if (this.dateValue[1] - this.dateValue[0] > 29 * 24 * 3600000) { if (this.dateValue[1] - this.dateValue[0] > 29*24*3600000) {
this.$modal.msgError('最大时间范围为30天请重新选择'); // 0:00:0023:59:59 this.$modal.msgError('最大时间范围为30天请重新选择') // 0:00:0023:59:59
this.dateValue = []; this.dateValue = []
} }
break; break
case '4': case '4':
if (!this.monthValue) { if (!this.monthValue) {
this.$modal.msgError('时间范围不能为空'); this.$modal.msgError('时间范围不能为空')
return false; return false
} }
if (this.monthValue[1] - this.monthValue[0] > 729 * 24 * 3600000) { if (this.monthValue[1] - this.monthValue[0] > 729*24*3600000) {
this.$modal.msgError('最大时间范围为24个月请重新选择'); // this.$modal.msgError('最大时间范围为24个月请重新选择')//
this.monthValue = []; this.monthValue = []
} }
break; break
default: default:
} }
}, },
// //
startYear() { startYear() {
if (this.yearValue2 && this.yearValue2 < this.yearValue1) { if (this.yearValue2 && this.yearValue2 < this.yearValue1) {
this.$modal.msgError('开始时间不能晚于结束时间,请重新选择'); this.$modal.msgError('开始时间不能晚于结束时间,请重新选择')
this.yearValue1 = null; this.yearValue1 = null
return false; return false
} }
if (this.yearValue1 && this.yearValue2) { if (this.yearValue1 && this.yearValue2) {
if (this.yearValue2 - this.yearValue1 > 10 * 365 * 24 * 3600000) { if (this.yearValue2 - this.yearValue1 > 10*365*24*3600000) {
this.$modal.msgError('最大时间范围为10年请重新选择'); this.$modal.msgError('最大时间范围为10年请重新选择')
this.yearValue1 = null; this.yearValue1 = null
return false; return false
} }
} }
}, },
endYear() { endYear() {
if (this.yearValue2 && this.yearValue2 < this.yearValue1) { if (this.yearValue2 && this.yearValue2 < this.yearValue1) {
this.$modal.msgError('结束时间不能早于开始时间,请重新选择'); this.$modal.msgError('结束时间不能早于开始时间,请重新选择')
this.yearValue2 = null; this.yearValue2 = null
return false; return false
} }
if (this.yearValue1 && this.yearValue2) { if (this.yearValue1 && this.yearValue2) {
if (this.yearValue2 - this.yearValue1 > 10 * 365 * 24 * 3600000) { if (this.yearValue2 - this.yearValue1 > 10*365*24*3600000) {
this.$modal.msgError('最大时间范围为10年请重新选择'); this.$modal.msgError('最大时间范围为10年请重新选择')
this.yearValue2 = null; this.yearValue2 = null
return false; return false
} }
} }
}, },
// //
startWeek() { startWeek() {
if (this.weekValue1 && this.weekValue2) { if (this.weekValue1 && this.weekValue2) {
let a = new Date(this.weekValue1).getTime(); let a = new Date(this.weekValue1).getTime()
let b = new Date(this.weekValue2).getTime(); let b = new Date(this.weekValue2).getTime()
if (a > b) { if (a > b) {
this.$modal.msgError('开始时间不能晚于结束时间,请重新选择'); this.$modal.msgError('开始时间不能晚于结束时间,请重新选择')
this.weekValue1 = null; this.weekValue1 = null
return false; return false
} }
if (b - a > 167 * 24 * 3600000) { if (b - a > 167*24*3600000) {
this.$modal.msgError('最大时间范围为24周请重新选择'); this.$modal.msgError('最大时间范围为24周请重新选择')
this.weekValue1 = null; this.weekValue1 = null
return false; return false
} }
} }
}, },
endWeek() { endWeek() {
if (this.weekValue1 && this.weekValue2) { if (this.weekValue1 && this.weekValue2) {
let a = new Date(this.weekValue1).getTime(); let a = new Date(this.weekValue1).getTime()
let b = new Date(this.weekValue2).getTime(); let b = new Date(this.weekValue2).getTime()
if (a > b) { if (a > b) {
this.$modal.msgError('结束时间不能早于开始时间,请重新选择'); this.$modal.msgError('结束时间不能早于开始时间,请重新选择')
this.weekValue2 = null; this.weekValue2 = null
return false; return false
} }
if (b - a > 167 * 24 * 3600000) { if (b - a > 167*24*3600000) {
this.$modal.msgError('最大时间范围为24周请重新选择'); this.$modal.msgError('最大时间范围为24周请重新选择')
this.weekValue2 = null; this.weekValue2 = null
return false; return false
} }
} }
}, },
// //
selectObjs(val) { selectObjs(val) {
console.log(val); console.log(val)
switch (val) { switch (val) {
case '1': case '1':
getFactoryList().then((res) => { getLineAll().then(res => {
this.objectList = res.data || []; this.objectList = res.data || []
this.queryParams.objIds = []; this.queryParams.objIds = []
}); })
break; break;
case '2': case '2':
getLineAll().then((res) => { getWorkShopAll().then(res => {
this.objectList = res.data || []; this.objectList = res.data || []
this.queryParams.objIds = []; this.queryParams.objIds = []
}); })
break; break;
default: default:
getWorkShopAll().then((res) => { getEquipmentAll().then(res => {
this.objectList = res.data || []; this.objectList = res.data || []
this.queryParams.objIds = []; this.queryParams.objIds = []
}); })
} }
}, },
// //
search() { search() {
if (!this.queryParams.energyTypeId) { if (!this.queryParams.energyTypeId) {
this.$modal.msgError('请选择能源类型'); this.$modal.msgError('请选择能源类型')
return false; return false
} }
if (!this.queryParams.timeDim) { if (!this.queryParams.timeDim) {
this.$modal.msgError('请选择时间维度'); this.$modal.msgError('请选择时间维度')
return false; return false
} }
switch (this.queryParams.timeDim) { switch (this.queryParams.timeDim) {
case '1': case '1':
if (this.timeValue && this.timeValue.length > 0) { if (this.timeValue && this.timeValue.length > 0) {
this.queryParams.startTime = this.timeValue[0]; this.queryParams.startTime = this.timeValue[0]
this.queryParams.endTime = this.timeValue[1]; // this.queryParams.endTime = this.timeValue[1] //
} else { } else {
this.$modal.msgError('时间范围不能为空'); this.$modal.msgError('时间范围不能为空')
return false; return false
} }
break; break
case '2': case '2':
if (this.dateValue.length > 0) { if (this.dateValue.length > 0) {
this.queryParams.startTime = this.dateValue[0]; this.queryParams.startTime = this.dateValue[0]
this.queryParams.endTime = this.dateValue[1] + 86399000; // 23:59:59 this.queryParams.endTime = this.dateValue[1] + 86399000 // 23:59:59
} else { } else {
this.$modal.msgError('日范围不能为空'); this.$modal.msgError('日范围不能为空')
return false; return false
} }
break; break
case '3': case '3':
if (this.weekValue1 && this.weekValue2) { if (this.weekValue1 && this.weekValue2) {
let a = let a = moment(this.weekValue1).day(0).format('YYYY-MM-DD') + ' 00:00:00'
moment(this.weekValue1).day(0).format('YYYY-MM-DD') + ' 00:00:00'; let b = moment(this.weekValue2).day(6).format('YYYY-MM-DD') + ' 23:59:59'
let b = this.queryParams.startTime = new Date(a).getTime()
moment(this.weekValue2).day(6).format('YYYY-MM-DD') + ' 23:59:59'; this.queryParams.endTime = new Date(b).getTime()
this.queryParams.startTime = new Date(a).getTime();
this.queryParams.endTime = new Date(b).getTime();
} else { } else {
this.$modal.msgError('周范围不能为空'); this.$modal.msgError('周范围不能为空')
return false; return false
} }
break; break
case '4': // case '4'://
if (this.monthValue.length > 0) { if (this.monthValue.length > 0) {
this.queryParams.startTime = this.monthValue[0]; this.queryParams.startTime = this.monthValue[0]
this.queryParams.endTime = this.transformTime(this.monthValue[1]); this.queryParams.endTime = this.transformTime(this.monthValue[1])
} else { } else {
this.$modal.msgError('月范围不能为空'); this.$modal.msgError('月范围不能为空')
return false; return false
} }
break; break
default: // default://
if (this.yearValue1 && this.yearValue2) { if (this.yearValue1 && this.yearValue2) {
if (this.yearValue2 < this.yearValue1) { if (this.yearValue2 < this.yearValue1) {
this.$modal.msgError('结束时间不能早于开始时间'); this.$modal.msgError('结束时间不能早于开始时间')
return false; return false
} else { } else {
this.queryParams.startTime = this.yearValue1; this.queryParams.startTime = this.yearValue1
this.queryParams.endTime = this.transformYear(this.yearValue2); this.queryParams.endTime = this.transformYear(this.yearValue2)
} }
} else { } else {
this.$modal.msgError('年范围不能为空'); this.$modal.msgError('年范围不能为空')
return false; return false
} }
} }
if (!this.queryParams.objType) { if (!this.queryParams.objType) {
this.$modal.msgError('请选择对象维度'); this.$modal.msgError('请选择对象维度')
return false; return false
} }
if (this.queryParams.objIds.length === 0) { if (this.queryParams.objIds.length === 0) {
this.$modal.msgError('请选择对象'); this.$modal.msgError('请选择对象')
return false; return false
} }
this.queryParams.startTime = this.queryParams.startTime + ''; this.queryParams.startTime = this.queryParams.startTime + ''
this.queryParams.endTime = this.queryParams.endTime + ''; this.queryParams.endTime = this.queryParams.endTime + ''
console.log(this.queryParams); console.log(this.queryParams)
this.$emit('submit', this.queryParams); this.$emit('submit', this.queryParams)
}, },
resetBtn() { resetBtn() {
this.queryParams.energyTypeId = null; this.queryParams.energyTypeId = null
this.queryParams.timeDim = this.getDictDatas( this.queryParams.timeDim = this.getDictDatas(this.DICT_TYPE.TIME_DIM)[0].value //
this.DICT_TYPE.TIME_DIM this.queryParams.objIds = []
)[0].value; // this.queryParams.objType = ''
this.queryParams.objIds = []; this.timeValue = []
this.queryParams.objType = ''; this.dateValue = []
this.timeValue = []; this.weekValue1 = null
this.dateValue = []; this.weekValue2 = null
this.weekValue1 = null; this.monthValue = []
this.weekValue2 = null; this.yearValue1 = null
this.monthValue = []; this.yearValue2 = null
this.yearValue1 = null;
this.yearValue2 = null;
}, },
// transformTime(timeStamp) {//
exportBtn() { let year = moment(timeStamp).format('YYYY')
this.$emit('export'); let month = moment(timeStamp).format('MM')
let newData = moment(new Date(year,month,0)).format('YYYY-MM-DD') + ' 23:59:59'
let value = new Date(newData).getTime()
return value
}, },
transformTime(timeStamp) { transformYear(timeStamp) {//
// let year = moment(timeStamp).format('YYYY')
let year = moment(timeStamp).format('YYYY'); let newData = year+'-12-31 23:59:59'
let month = moment(timeStamp).format('MM'); let value = new Date(newData).getTime()
let newData = return value
moment(new Date(year, month, 0)).format('YYYY-MM-DD') + ' 23:59:59';
let value = new Date(newData).getTime();
return value;
}, },
transformYear(timeStamp) { switchMode() {//
// this.isExpand = !this.isExpand
let year = moment(timeStamp).format('YYYY'); const element = this.$refs.searchBarRef
let newData = year + '-12-31 23:59:59';
let value = new Date(newData).getTime();
return value;
},
switchMode() {
//
this.isExpand = !this.isExpand;
const element = this.$refs.searchBarRef;
if (this.isExpand) { if (this.isExpand) {
element.classList.remove('divHeight'); element.classList.remove('divHeight')
} else { } else {
element.classList.add('divHeight'); element.classList.add('divHeight')
} }
}, }
}, }
}; }
</script> </script>
<style lang='scss'> <style lang='scss'>
/* 时间整点 */ /* 时间整点 */
@ -546,11 +463,11 @@ export default {
.demo-form-inline { .demo-form-inline {
.el-date-editor .el-range__icon { .el-date-editor .el-range__icon {
font-size: 16px; font-size: 16px;
color: #0b58ff; color: #0B58FF;
} }
.el-input__prefix .el-icon-date { .el-input__prefix .el-icon-date {
font-size: 16px; font-size: 16px;
color: #0b58ff; color: #0B58FF;
} }
} }
</style> </style>
@ -560,15 +477,11 @@ export default {
display: inline-block; display: inline-block;
width: 4px; width: 4px;
height: 16px; height: 16px;
background-color: #0b58ff; background-color: #0B58FF;
border-radius: 1px; border-radius: 1px;
margin-right: 8px; margin-right: 8px;
margin-top: 12px; margin-top: 12px;
} }
.el-form-item {
margin-right: 10px;
margin-bottom: 4px;
}
} }
.searchBarBox .foldClass { .searchBarBox .foldClass {
position: absolute; position: absolute;
@ -576,7 +489,7 @@ export default {
right: 0; right: 0;
cursor: pointer; cursor: pointer;
font-size: 12px; font-size: 12px;
color: #0b58ff; color:#0B58FF;
} }
.searchBarBox .foldClass .iconfont { .searchBarBox .foldClass .iconfont {
font-size: 14px; font-size: 14px;
@ -589,7 +502,7 @@ export default {
display: inline-block; display: inline-block;
width: 1px; width: 1px;
height: 24px; height: 24px;
background: #e8e8e8; background: #E8E8E8;
vertical-align: middle; vertical-align: middle;
margin: 0 10px; margin: 0 10px;
} }

View File

@ -1,129 +1,96 @@
<template> <template>
<div <div class="app-container contrastAnalysisBox" id="contrastAnalysisBox">
class="app-container contrastAnalysisBox"
id="contrastAnalysisBox">
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<search-area <search-area :isFold="isFold" @submit="getList"/>
:isFold="isFold" <el-tabs v-model="activeName" @tab-click="switchChart" v-show='chartData.length'>
@submit="getList" <el-tab-pane label="柱状图" name="bar">
@export="exportExl" /> <bar-chart ref="analysisBarChart" :chartData="chartData" :timeDim="timeDim" />
<div v-show="chartData.length"> </el-tab-pane>
<bar-chart <el-tab-pane label="折线图" name="line">
ref="analysisBarChart" <line-chart ref="analysisLineChart" :chartData="chartData" :timeDim="timeDim"/>
:chartData="chartData" </el-tab-pane>
:timeDim="timeDim" /> </el-tabs>
<base-table
:table-props="tableProps"
:table-data="list"
:max-height="tableH"
class="contrast-out-table" />
</div>
<!-- 没有数据 --> <!-- 没有数据 -->
<div <div class="no-data-bg" v-show='!chartData.length'></div>
class="no-data-bg"
v-show="!chartData.length"></div>
</div> </div>
</template> </template>
<script> <script>
import { getCompare } from '@/api/analysis/energyAnalysis'; import { getCompare } from "@/api/analysis/energyAnalysis"
import SearchArea from './components/searchArea'; import SearchArea from "./components/searchArea"
import BarChart from './components/barChart'; import BarChart from "./components/barChart"
import tableHeightMixin from '@/mixins/lb/tableHeightMixin'; import LineChart from "./components/lineChart"
import FileSaver from 'file-saver';
import * as XLSX from 'xlsx/xlsx.mjs';
// import moment from 'moment' // import moment from 'moment'
export default { export default {
name: 'ContrastAnalysis', name: 'ContrastAnalysis',
components: { SearchArea, BarChart }, components: { SearchArea, BarChart, LineChart },
mixins: [tableHeightMixin],
data() { data() {
return { return {
isFold: false, isFold: false,
activeName: 'bar',
chartData: [], chartData: [],
timeDim: '', timeDim: ''
tableProps: [], }
list: [],
tableH: this.tableHeight(250) / 2,
};
}, },
mounted() { mounted() {
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
this.isFold = this.searchBarWidth('contrastAnalysisBox', 1437); this.tableH = this.tableHeight(260)
this.isFold = this.searchBarWidth('contrastAnalysisBox', 1437)
// console.log(document.getElementById("contrastAnalysisBox").offsetWidth) // console.log(document.getElementById("contrastAnalysisBox").offsetWidth)
}); })
this.isFold = this.searchBarWidth('contrastAnalysisBox', 1437); this.isFold = this.searchBarWidth('contrastAnalysisBox', 1437)
}, },
methods: { methods: {
_setTableHeight() {
this.tableH = this.tableHeight(250) / 2;
},
getList(params) { getList(params) {
this.timeDim = params.timeDim; this.timeDim = params.timeDim
getCompare({ ...params }).then((res) => { getCompare({ ...params }).then((res) => {
console.log(res)
if (res.code === 0) { if (res.code === 0) {
this.getTableList(res.data || []); this.chartData = res.data || []
this.chartData = res.data || [];
} else { } else {
this.chartData = []; this.chartData = []
} }
}); })
}, },
getTableList(arr) { switchChart() {
this.tableProps = []; if (this.activeName === 'bar') {
this.list = []; this.$nextTick((res) => {
let tempX = []; this.$refs.analysisBarChart.getChart()
let timeArr = arr[0].trendRespVOList || []; })
this.list = timeArr.map((item) => {
return { time: item.time };
});
for (let i = 0; i < arr.length; i++) {
let obj = {};
obj.prop = arr[i].objId;
obj.label = arr[i].objName;
obj.minWidth = 100;
tempX.push(obj);
let tiemList = arr[i].trendRespVOList;
for (let j = 0; j < tiemList.length; j++) {
this.list[j][arr[i].objId] = tiemList[j].useNum
? tiemList[j].useNum.toFixed(2)
: null;
}
}
this.tableProps = [{ prop: 'time', label: '时间' }].concat(tempX);
},
//
exportExl() {
if (this.list.length > 0) {
var wb = XLSX.utils.table_to_book(
document.querySelector('.contrast-out-table')
);
let fileName = '对比分析.xlsx';
var wbout = XLSX.write(wb, {
bookType: 'xlsx',
bookSST: true,
type: 'array',
});
try {
FileSaver.saveAs(
new Blob([wbout], { type: 'application/octet-stream' }),
fileName
);
this.$message.success('导出成功');
} catch (e) {
if (typeof console !== 'undefined') console.log(e, wbout);
}
return wbout;
} else { } else {
this.$modal.msgWarning('暂无数据导出'); this.$nextTick((res) => {
this.$refs.analysisLineChart.getChart()
})
} }
}, }
}, }
}; }
</script> </script>
<style lang='scss'> <style lang='scss'>
.contrastAnalysisBox { .contrastAnalysisBox {
.contrast-out-table { .el-tabs__nav::after {
margin-top: 20px; content: "";
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 2px;
background-color: #e4e7ed;
/* z-index: 1; */
}
.el-tabs__nav-wrap::after {
width: 0;
}
.el-tabs__item {
padding: 0 10px;
}
.el-tabs__item:hover {
color: rgba(0, 0, 0, 0.85);
}
.el-tabs__item.is-active {
color: rgba(0, 0, 0, 0.85);
}
.el-tabs__item {
color: rgba(0, 0, 0, 0.45);
} }
} }
</style> </style>

View File

@ -1,44 +1,28 @@
<template> <template>
<el-form <el-form :inline="true" class="demo-form-inline">
:inline="true"
class="demo-form-inline">
<span class="blue-block"></span> <span class="blue-block"></span>
<el-form-item <el-form-item label="对象选择" required>
label="对象选择" <el-cascader
required> v-model="objArr"
<el-select :options="objList"
v-model="queryParams.objId" :props="{ checkStrictly: true, value: 'id', label: 'name' }"
placeholder="请选择" popper-class="cascaderParent"
style="width: 250px" size="small"
filterable style="width: 250px;"
size="small"> clearable></el-cascader>
<el-option
v-for="item in objList"
:key="item.id"
:label="item.name"
:value="item.id"
:clearable="false"></el-option>
</el-select>
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="时间维度" required>
label="时间维度" <el-select v-model="queryParams.type" placeholder="请选择" style="width: 80px;" size="small">
required>
<el-select
v-model="queryParams.type"
placeholder="请选择"
style="width: 80px"
size="small">
<el-option <el-option
v-for="item in timeType" v-for="item in timeType"
:key="item.id" :key="item.id"
:label="item.name" :label="item.name"
:value="item.id" :value="item.id"
:clearable="false"></el-option> :clearable="false">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="时间" required>
label="时间"
required>
<div v-show="queryParams.type === 1"> <div v-show="queryParams.type === 1">
<el-date-picker <el-date-picker
v-model="monthValue" v-model="monthValue"
@ -47,7 +31,8 @@
@change="selectTime" @change="selectTime"
:clearable="false" :clearable="false"
size="small" size="small"
placeholder="选择月"></el-date-picker> placeholder="选择月">
</el-date-picker>
</div> </div>
<div v-show="queryParams.type === 2"> <div v-show="queryParams.type === 2">
<el-date-picker <el-date-picker
@ -58,7 +43,8 @@
@change="selectTime" @change="selectTime"
:clearable="false" :clearable="false"
size="small" size="small"
placeholder="选择周"></el-date-picker> placeholder="选择周">
</el-date-picker>
</div> </div>
<div v-show="queryParams.type === 3"> <div v-show="queryParams.type === 3">
<el-date-picker <el-date-picker
@ -68,34 +54,24 @@
@change="selectTime" @change="selectTime"
:clearable="false" :clearable="false"
size="small" size="small"
placeholder="选择日"></el-date-picker> placeholder="选择日">
</el-date-picker>
</div> </div>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button <el-button type="primary" size="small" @click="search">查询</el-button>
type="primary"
size="small"
@click="search">
查询
</el-button>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<span class="separateStyle"></span> <span class="separateStyle"></span>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button <el-button type="primary" size="small" @click="exportData" plain>导出</el-button>
type="primary"
size="small"
@click="exportData"
plain>
导出
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</template> </template>
<script> <script>
import { getTree } from '@/api/analysis/energyAnalysis'; import { getTree } from '@/api/base/factory'
import moment from 'moment'; import moment from 'moment'
export default { export default {
name: 'searchArea', name: 'searchArea',
data() { data() {
@ -104,126 +80,133 @@ export default {
queryParams: { queryParams: {
type: 1, type: 1,
searchTime: null, searchTime: null,
objId: null, objId: null
objType: 1,
}, },
timeType: [ timeType: [
{ id: 1, name: '月' }, {id: 1, name: '月'},
{ id: 2, name: '周' }, {id: 2, name: '周'},
{ id: 3, name: '日' }, {id: 3, name: '日'}
], ],
monthValue: '', monthValue: '',
weekValue: '', weekValue: '',
dateValue: '', dateValue: '',
objArr: [],
objList: [], objList: [],
pickerOptions: { pickerOptions: {
disabledDate(date) { disabledDate(date) {
return date.getTime() > Date.now(); return date.getTime() > Date.now()
}, }
}, },
pickerOptionsWeek: { pickerOptionsWeek: {
disabledDate(time) { disabledDate(time) {
let day = Date.now(); let day = Date.now()
let limitTime = moment(day).day(-1); let limitTime = moment(day).day(-1)
return time.getTime() > new Date(limitTime).getTime(); return time.getTime() > new Date(limitTime).getTime()
}, }
}, }
}; }
}, },
mounted() { mounted() {
this.getObjTree(); this.getObjTree()
}, },
methods: { methods: {
getObjTree() { getObjTree() {
getTree().then((res) => { getTree().then(res => {
this.objList = res.data || []; this.objList = res.data || []
if (this.objList.length > 0) { })
this.queryParams.objId = this.objList[0].id;
}
});
}, },
selectTime() { selectTime() {
switch (this.queryParams.type) { switch (this.queryParams.type) {
case 1: case 1:
this.queryParams.searchTime = this.monthValue; this.queryParams.searchTime = this.monthValue
break; break;
case 2: case 2:
this.queryParams.searchTime = this.weekValue; this.queryParams.searchTime = this.weekValue
break; break;
default: default:
this.queryParams.searchTime = this.dateValue; this.queryParams.searchTime = this.dateValue
} }
}, },
// //
search() { search() {
if (!this.queryParams.objId) { if (this.objArr.length === 0) {
this.$modal.msgError('请选择对象'); this.$modal.msgError('请选择对象')
return false; return false
} else {
this.queryParams.objId = this.objArr[this.objArr.length-1]
} }
if (!this.queryParams.type) { if (!this.queryParams.type) {
this.$modal.msgError('请选择时间维度'); this.$modal.msgError('请选择时间维度')
return false; return false
} }
if (!this.queryParams.searchTime) { if (!this.queryParams.searchTime) {
this.$modal.msgError('请选择时间'); this.$modal.msgError('请选择时间')
return false; return false
} }
switch (this.queryParams.type) { switch (this.queryParams.type) {
case 1: case 1:
this.queryParams.searchTime = this.transformTime(this.monthValue); this.queryParams.searchTime = this.transformTime(this.monthValue)
break; break;
case 2: case 2:
let value = let value = moment(this.weekValue).day(6).format('YYYY-MM-DD') + ' 23:59:59'
moment(this.weekValue).day(6).format('YYYY-MM-DD') + ' 23:59:59'; this.queryParams.searchTime = new Date(value).getTime()
this.queryParams.searchTime = new Date(value).getTime();
break; break;
default: default:
let value2 = let value2 = moment(this.dateValue).format('YYYY-MM-DD') + ' 23:59:59'
moment(this.dateValue).format('YYYY-MM-DD') + ' 23:59:59'; this.queryParams.searchTime = new Date(value2).getTime()
this.queryParams.searchTime = new Date(value2).getTime();
} }
this.$emit('submit', this.queryParams); this.$emit('submit', this.queryParams)
}, },
exportData() { exportData() {
let name; let name
if (this.queryParams.objId) { if (this.queryParams.objId) {
name = this.getObjName(this.objList, this.queryParams.objId); name = this.getObjName(this.objList, this.queryParams.objId)
} else { } else {
this.$modal.msgWarning('对象不能为空'); this.$modal.msgWarning("对象不能为空")
return false; return false
} }
this.$emit('exportD', { name: name }); this.$emit('exportD', {name: name})
}, },
// name // name
getObjName(list, id) { getObjName(list, id) {
let _this = this
for (let i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
let a = list[i]; let a = list[i]
if (a.id === id) { if (a.id === id) {
return a.name; return a.name
} else {
if (a.children && a.children.length > 0) {
let res = _this.getObjName(a.children, id)
if (res) {
return res
}
}
} }
} }
}, },
transformTime(timeStamp) { transformTime(timeStamp) {//
// let year = moment(timeStamp).format('YYYY')
let year = moment(timeStamp).format('YYYY'); let month = moment(timeStamp).format('MM')
let month = moment(timeStamp).format('MM'); let newData = moment(new Date(year,month,0)).format('YYYY-MM-DD') + ' 23:59:59'
let newData = let value = new Date(newData).getTime()
moment(new Date(year, month, 0)).format('YYYY-MM-DD') + ' 23:59:59'; return value
let value = new Date(newData).getTime(); }
return value; }
}, }
},
};
</script> </script>
<style lang='scss'> <style lang='scss'>
/* 级联选择器 */
.cascaderParent .el-cascader-panel .el-scrollbar:first-child .el-radio {
display: none;
}
.demo-form-inline { .demo-form-inline {
.el-date-editor .el-range__icon { .el-date-editor .el-range__icon {
font-size: 16px; font-size: 16px;
color: #0b58ff; color: #0B58FF;
} }
.el-input__prefix .el-icon-date { .el-input__prefix .el-icon-date {
font-size: 16px; font-size: 16px;
color: #0b58ff; color: #0B58FF;
} }
} }
</style> </style>
@ -232,7 +215,7 @@ export default {
display: inline-block; display: inline-block;
width: 1px; width: 1px;
height: 24px; height: 24px;
background: #e8e8e8; background: #E8E8E8;
vertical-align: middle; vertical-align: middle;
} }
.demo-form-inline { .demo-form-inline {
@ -240,14 +223,10 @@ export default {
display: inline-block; display: inline-block;
width: 4px; width: 4px;
height: 16px; height: 16px;
background-color: #0b58ff; background-color: #0B58FF;
border-radius: 1px; border-radius: 1px;
margin-right: 8px; margin-right: 8px;
margin-top: 10px; margin-top: 10px;
} }
.el-form-item {
margin-right: 10px;
margin-bottom: 4px;
}
} }
</style> </style>

View File

@ -1,34 +1,29 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<search-area <search-area @submit="getList" @exportD="exportData"/>
@submit="getList"
@exportD="exportData" />
<!-- 表格 --> <!-- 表格 -->
<div v-show="chartData.length"> <div v-show="chartData.length">
<base-table <base-table
:table-props="tableProps" :table-props="tableProps"
:table-data="list" :table-data="list"
class="qoq-out-table" /> class="qoq-out-table"
/>
<div class="chartTitle">环比分析图</div> <div class="chartTitle">环比分析图</div>
<div style="width: 100%"> <div style='width: 100%'>
<line-chart <line-chart ref="analysisLineChart" :chartData="chartData"/>
ref="analysisLineChart"
:chartData="chartData" />
</div> </div>
</div> </div>
<!-- 没有数据 --> <!-- 没有数据 -->
<div <div class="no-data-bg" v-show='!chartData.length'></div>
class="no-data-bg"
v-show="!chartData.length"></div>
</div> </div>
</template> </template>
<script> <script>
import { getQoq } from '@/api/analysis/energyAnalysis'; import { getQoq } from "@/api/analysis/energyAnalysis"
import SearchArea from './components/searchArea'; import SearchArea from "./components/searchArea"
import LineChart from './components/lineChart'; import LineChart from "./components/lineChart"
import FileSaver from 'file-saver'; import FileSaver from "file-saver"
import * as XLSX from 'xlsx/xlsx.mjs'; import * as XLSX from 'xlsx/xlsx.mjs'
export default { export default {
name: 'QoqAnalysis', name: 'QoqAnalysis',
components: { SearchArea, LineChart }, components: { SearchArea, LineChart },
@ -36,90 +31,87 @@ export default {
return { return {
chartData: [], chartData: [],
tableProps: [], tableProps: [],
list: [], list: []
}; }
}, },
methods: { methods: {
getList(params) { getList(params) {
getQoq({ ...params }).then((res) => { getQoq({ ...params }).then((res) => {
if (res.code === 0 && res.data) { if (res.code === 0 && res.data) {
this.getTableList(res.data); this.getTableList(res.data)
} else { } else {
this.chartData = []; this.chartData = []
this.list = []; this.list = []
} }
}); })
}, },
getTableList(arr) { getTableList(arr) {
let data = arr.data; let data = arr.data
let nameData = arr.nameData; let nameData = arr.nameData
let tempX = []; let tempX = []
data[0].data.map((item) => { data[0].data.map((item) => {
let obj = {}; let obj = {}
obj.prop = item.dynamicName; obj.prop = item.dynamicName
obj.label = item.dynamicName; obj.label = item.dynamicName
obj.id = item.id; obj.id = item.id
obj.children = []; obj.children = []
tempX.push(obj); tempX.push(obj)
}); })
for (let i = 0; i < nameData.length; i++) { for (let i = 0; i < nameData.length; i++) {
for (let j = 0; j < tempX.length; j++) { for (let j = 0; j < tempX.length; j++) {
if (tempX[j].id === nameData[i].parentId) { if (tempX[j].id === nameData[i].parentId) {
let obj = {}; let obj = {}
obj.prop = tempX[j].prop + '_' + nameData[i].name; obj.prop = tempX[j].prop + '_' + nameData[i].name
obj.label = nameData[i].name; obj.label = nameData[i].name
tempX[j].children.push(obj); tempX[j].children.push(obj)
} }
} }
} }
this.tableProps = [{ prop: 'time', label: '时间' }].concat(tempX); this.tableProps = [{prop: 'time',label: '时间'}].concat(tempX)
// //
this.list = []; this.list = []
for (let k = 0; k < data.length; k++) { for (let k = 0; k < data.length; k++) {
let obj = {}; let obj = {}
obj.time = data[k].time; obj.time = data[k].time
let arr1 = data[k].data; let arr1 = data[k].data
obj.type = []; obj.type = []
for (let q = 0; q < arr1.length; q++) { for (let q = 0; q < arr1.length; q++) {
let name = arr1[q].dynamicName; let name = arr1[q].dynamicName
obj.type.push(name); obj.type.push(name)
let arr2 = arr1[q].children; let arr2 = arr1[q].children
for (let p = 0; p < arr2.length; p++) { for (let p = 0; p < arr2.length; p++) {
let prop = name + '_' + arr2[p].dynamicName; let prop = name + '_' + arr2[p].dynamicName
obj[prop] = arr2[p].dynamicValue; obj[prop] = arr2[p].dynamicValue
} }
} }
this.list.push(obj); this.list.push(obj)
} }
this.chartData = this.list; this.chartData = this.list
}, },
exportData(val) { exportData(val) {
if (this.list.length > 0) { if (this.list.length > 0) {
var wb = XLSX.utils.table_to_book( var wb = XLSX.utils.table_to_book(document.querySelector(".qoq-out-table"))
document.querySelector('.qoq-out-table') let fileName = val.name + "环比分析.xlsx"
);
let fileName = val.name + '环比分析.xlsx';
var wbout = XLSX.write(wb, { var wbout = XLSX.write(wb, {
bookType: 'xlsx', bookType: "xlsx",
bookSST: true, bookSST: true,
type: 'array', type: "array"
}); })
try { try {
FileSaver.saveAs( FileSaver.saveAs(
new Blob([wbout], { type: 'application/octet-stream' }), new Blob([wbout], { type: "application/octet-stream" }),
fileName fileName
); )
this.$message.success('导出成功');
} catch (e) { } catch (e) {
if (typeof console !== 'undefined') console.log(e, wbout); if (typeof console !== "undefined") console.log(e, wbout);
} }
return wbout; return wbout
} else { } else {
this.$modal.msgWarning('暂无数据导出'); this.$modal.msgWarning("暂无数据导出")
} }
}, }
}, }
}; }
</script> </script>
<style lang='scss' scoped> <style lang='scss' scoped>
.chartTitle { .chartTitle {
@ -132,7 +124,7 @@ export default {
display: inline-block; display: inline-block;
width: 4px; width: 4px;
height: 18px; height: 18px;
background-color: #0b58ff; background-color: #0B58FF;
border-radius: 1px; border-radius: 1px;
margin-right: 8px; margin-right: 8px;
vertical-align: bottom; vertical-align: bottom;

View File

@ -2,43 +2,44 @@
<div <div
id="analysischartLine" id="analysischartLine"
style="width: 100%" style="width: 100%"
:style="{ height: chartHeight + 'px' }"></div> :style="{ height: chartHeight + 'px' }"
></div>
</template> </template>
<script> <script>
import * as echarts from 'echarts'; import * as echarts from 'echarts'
import resize from '@/utils/chartMixins/resize'; import resize from '@/utils/chartMixins/resize'
export default { export default {
name: 'LineChart', name: "LineChart",
mixins: [resize], mixins: [resize],
data() { data() {
return { return {
chartDom: '', chartDom: '',
chart: '', chart: '',
chartHeight: this.tableHeight(214) - 100, chartHeight: this.tableHeight(214) - 70
}; }
}, },
props: { props: {
chartData: { chartData: {
type: Array, type: Array,
required: true, required: true,
default: () => { default: () => {
return []; return []
}, }
}, },
timeDim: { timeDim: {
type: String, type: String,
default: '', default: ''
}, }
}, },
watch: { watch: {
chartData: function () { chartData: function () {
this.getChart(); this.getChart()
}, }
}, },
mounted() { mounted() {
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
this.chartHeight = this.tableHeight(214) - 70; this.chartHeight = this.tableHeight(214) - 70
}); })
}, },
methods: { methods: {
getChart() { getChart() {
@ -47,27 +48,27 @@ export default {
this.chart !== '' && this.chart !== '' &&
this.chart !== undefined this.chart !== undefined
) { ) {
this.chart.dispose(); // Dom this.chart.dispose() // Dom
} }
this.chartDom = document.getElementById('analysischartLine'); this.chartDom = document.getElementById('analysischartLine')
this.chart = echarts.init(this.chartDom); this.chart = echarts.init(this.chartDom)
let xData = []; let xData = []
let yData = []; let yData = []
for (let i = 0; i < this.chartData.length; i++) { for (let i = 0; i < this.chartData.length; i++) {
let time = ''; let time = ""
if (this.timeDim === '3') { if (this.timeDim === '3') {
let year = this.chartData[i].time.slice(0, 4); let year = this.chartData[i].time.slice(0,4)
let weak = this.chartData[i].time.slice(4, 6); let weak = this.chartData[i].time.slice(4,6)
time = year + ' 第 ' + weak + ' 周'; time = year+' 第 '+weak+' 周'
} else { } else {
time = this.chartData[i].time; time = this.chartData[i].time
} }
xData.push(time); xData.push(time)
yData.push(this.chartData[i].useNum); yData.push(this.chartData[i].useNum)
} }
var option = { var option = {
color: ['#288AFF'], color:['#288AFF'],
// tooltip: { // tooltip: {
// trigger: 'axis' // trigger: 'axis'
// }, // },
@ -75,28 +76,28 @@ export default {
left: '4%', left: '4%',
right: '1%', right: '1%',
bottom: '1%', bottom: '1%',
containLabel: true, containLabel: true
}, },
xAxis: { xAxis: {
type: 'category', type: 'category',
data: xData, data: xData,
axisLabel: { axisLabel: {
rotate: '45', rotate: "45"
}, }
}, },
yAxis: { yAxis: {
type: 'value', type: 'value'
}, },
series: [ series: [
{ {
data: yData, data: yData,
type: 'line', type: 'line'
}, }
], ]
}; };
option && this.chart.setOption(option); option && this.chart.setOption(option);
}, }
}, }
}; }
</script> </script>

View File

@ -1,79 +1,38 @@
<template> <template>
<div <div class="searchBarBox divHeight" ref="searchBarRef" :style="{ paddingRight: isFold ? '55px' : '0px' }">
class="searchBarBox divHeight" <el-form :inline="true" class="demo-form-inline">
ref="searchBarRef"
:style="{ paddingRight: isFold ? '55px' : '0px' }">
<el-form
:inline="true"
class="demo-form-inline">
<span class="blue-block"></span> <span class="blue-block"></span>
<el-form-item <el-form-item label="能源类型" required>
label="能源类型" <el-select v-model="queryParams.energyTypeId" placeholder="请选择" style="width: 100px;" size="small">
required>
<el-select
v-model="queryParams.energyTypeId"
placeholder="请选择"
size="small"
@change="chooseType"
filterable
style="width: 100%">
<el-option <el-option
v-for="item in energyTypeList" v-for="item in energyTypeList"
:key="item.id" :key="item.id"
:label="item.labelName" :label="item.name"
:value="item.id"></el-option> :value="item.id">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="对象选择" required>
v-if="energyType === 1"
label="对象选择"
required>
<el-cascader <el-cascader
v-model="objArr" v-model="objArr"
:options="objList" :options="objList"
:show-all-levels="false"
:props="{ checkStrictly: true, value: 'id', label: 'name' }" :props="{ checkStrictly: true, value: 'id', label: 'name' }"
popper-class="cascaderParent"
size="small" size="small"
@change="changeLine"
clearable></el-cascader> clearable></el-cascader>
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="时间维度" required>
v-if="energyType === 2" <el-select v-model="queryParams.timeDim" placeholder="请选择" style="width: 80px;" size="small">
label="对象选择"
required>
<el-select
v-model="objId"
placeholder="请选择"
style="width: 250px"
filterable
size="small">
<el-option
v-for="item in objList"
:key="item.id"
:label="item.name"
:value="item.id"
:clearable="false"></el-option>
</el-select>
</el-form-item>
<el-form-item
label="时间维度"
required>
<el-select
v-model="queryParams.timeDim"
placeholder="请选择"
style="width: 80px"
size="small">
<el-option <el-option
v-for="item in getDictDatas(this.DICT_TYPE.TIME_DIM)" v-for="item in getDictDatas(this.DICT_TYPE.TIME_DIM)"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
:value="item.value" :value="item.value"
size="small"></el-option> size="small">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="时间范围" required>
label="时间范围"
required>
<div v-show="queryParams.timeDim === '1'"> <div v-show="queryParams.timeDim === '1'">
<el-date-picker <el-date-picker
v-model="timeValue" v-model="timeValue"
@ -87,7 +46,9 @@
popper-class="noneMinute" popper-class="noneMinute"
@change="timeSelect" @change="timeSelect"
size="small" size="small"
style="width: 350px"></el-date-picker> style='width:350px;'
>
</el-date-picker>
</div> </div>
<div v-show="queryParams.timeDim === '2'"> <div v-show="queryParams.timeDim === '2'">
<el-date-picker <el-date-picker
@ -100,28 +61,31 @@
:picker-options="pickerOptions" :picker-options="pickerOptions"
@change="timeSelect" @change="timeSelect"
size="small" size="small"
style="width: 350px"></el-date-picker> style='width:350px;'
>
</el-date-picker>
</div> </div>
<div v-show="queryParams.timeDim === '3'"> <div v-show="queryParams.timeDim === '3'">
<el-date-picker <el-date-picker
v-model="weekValue1" v-model="weekValue1"
type="week" type="week"
format="yyyy 第 WW 周" format="yyyy 第 WW 周"
style="width: 170px" style='width:170px;'
:picker-options="pickerOptionsWeek" :picker-options="pickerOptionsWeek"
@change="startWeek" @change="startWeek"
size="small" size="small"
placeholder="选择周"></el-date-picker> placeholder="选择周">
- </el-date-picker>-
<el-date-picker <el-date-picker
v-model="weekValue2" v-model="weekValue2"
type="week" type="week"
format="yyyy 第 WW 周" format="yyyy 第 WW 周"
:picker-options="pickerOptionsWeek" :picker-options="pickerOptionsWeek"
style="width: 170px" style='width:170px;'
@change="endWeek" @change="endWeek"
size="small" size="small"
placeholder="选择周"></el-date-picker> placeholder="选择周">
</el-date-picker>
</div> </div>
<div v-show="queryParams.timeDim === '4'"> <div v-show="queryParams.timeDim === '4'">
<el-date-picker <el-date-picker
@ -133,74 +97,59 @@
value-format="timestamp" value-format="timestamp"
:picker-options="pickerOptions" :picker-options="pickerOptions"
size="small" size="small"
style="width: 350px" style='width:350px;'
@change="timeSelect"></el-date-picker> @change="timeSelect"
>
</el-date-picker>
</div> </div>
<div v-show="queryParams.timeDim === '5'"> <div v-show="queryParams.timeDim === '5'">
<el-date-picker <el-date-picker
style="width: 170px" style='width:170px;'
v-model="yearValue1" v-model="yearValue1"
type="year" type="year"
:picker-options="pickerOptions" :picker-options="pickerOptions"
value-format="timestamp" value-format="timestamp"
placeholder="选择年" placeholder="选择年"
size="small" size="small"
@change="startYear"></el-date-picker> @change="startYear"
- >
</el-date-picker>-
<el-date-picker <el-date-picker
style="width: 170px" style='width:170px;'
v-model="yearValue2" v-model="yearValue2"
type="year" type="year"
:picker-options="pickerOptions" :picker-options="pickerOptions"
value-format="timestamp" value-format="timestamp"
placeholder="选择年" placeholder="选择年"
size="small" size="small"
@change="endYear"></el-date-picker> @change="endYear"
>
</el-date-picker>
</div> </div>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button <el-button type="primary" size="small" @click="search">查询</el-button>
type="primary"
size="small"
@click="handBtn('search')">
查询
</el-button>
<el-button
size="small"
@click="resetBtn">
重置
</el-button>
<span class="separateStyle"></span> <span class="separateStyle"></span>
<el-button <el-button size="small" @click="resetBtn">重置</el-button>
type="primary"
size="small"
plain
@click="handBtn('exportBtn')">
导出
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<span <span v-if="isFold" class="foldClass" @click='switchMode'>
v-if="isFold"
class="foldClass"
@click="switchMode">
{{ isExpand ? '收起' : '展开' }} {{ isExpand ? '收起' : '展开' }}
<svg-icon :icon-class="isExpand ? 'upward' : 'downward'" /> <svg-icon :icon-class="isExpand ? 'upward' : 'downward'" />
</span> </span>
</div> </div>
</template> </template>
<script> <script>
import { getTree } from '@/api/analysis/energyAnalysis'; import { getEnergyTypeListAll } from "@/api/base/energyType"
import { getEnergyTypeListAll } from '@/api/base/energyType'; import { getTree } from '@/api/base/factory'
import moment from 'moment'; import moment from 'moment'
export default { export default {
name: 'searchArea', name: 'searchArea',
props: { props: {
isFold: { isFold: {//
//
type: Boolean, type: Boolean,
default: false, default: false
}, }
}, },
data() { data() {
return { return {
@ -211,315 +160,258 @@ export default {
objId: null, objId: null,
timeDim: null, timeDim: null,
startTime: null, startTime: null,
endTime: null, endTime: null
objType: 1, //12线3
}, },
objId: null,
objType: 1, //12线3,使
energyTypeList: [],
energyType: 0, //12
objArr: [], objArr: [],
timeValue: [], // 7 timeValue: [],// 7
dateValue: [], // 30 dateValue: [],// 30
weekValue1: null, //24 weekValue1: null,//24
weekValue2: null, weekValue2: null,
monthValue: [], //24 monthValue: [],//24
yearValue1: null, //10 yearValue1: null,//10
yearValue2: null, yearValue2: null,
energyTypeList: [],
objList: [], objList: [],
pickerOptions: { pickerOptions: {
disabledDate(date) { disabledDate(date) {
return date.getTime() > Date.now(); return date.getTime() > Date.now()
}, }
}, },
pickerOptionsWeek: { pickerOptionsWeek: {
disabledDate(time) { disabledDate(time) {
let day = Date.now(); let day = Date.now()
let limitTime = moment(day).day(-1); let limitTime = moment(day).day(-1)
return time.getTime() > new Date(limitTime).getTime(); return time.getTime() > new Date(limitTime).getTime()
}, }
}, }
}; }
}, },
mounted() { mounted() {
this.getEnergyList(); this.getTypeList()
this.getObjTree(); this.getObjTree()
this.queryParams.timeDim = this.getDictDatas( this.queryParams.timeDim = this.getDictDatas(this.DICT_TYPE.TIME_DIM)[0].value //
this.DICT_TYPE.TIME_DIM this.timeValue = [moment().startOf('day'), moment().endOf('day')-59*61*1000]
)[0].value; //
this.timeValue = [
moment().startOf('day'),
moment().endOf('day') - 59 * 61 * 1000,
];
}, },
methods: { methods: {
getObjTree() { getTypeList() {
getTree().then((res) => {
this.objList = res.data || [];
if (this.objList.length > 0) {
this.objId = this.objList[0].id;
}
});
},
//
getEnergyList() {
getEnergyTypeListAll().then((res) => { getEnergyTypeListAll().then((res) => {
this.energyTypeList = res.data || []; this.energyTypeList = res.data || []
}); })
}, },
// getObjTree() {
chooseType(id) { getTree().then(res => {
let val; this.objList = res.data || []
this.energyTypeList.map((item) => { })
if (item.id === id) {
val = item.name;
}
});
if (val == 1 || val == 2) {
this.energyType = 1;
} else {
this.energyType = 2;
}
},
// /线/
changeLine(val) {
this.objType = val.length || 0;
}, },
// //
timeSelect() { timeSelect() {
switch (this.queryParams.timeDim) { switch (this.queryParams.timeDim) {
case '1': case '1':
if (!this.timeValue) { if (!this.timeValue) {
this.$modal.msgError('时间范围不能为空'); this.$modal.msgError('时间范围不能为空')
return false; return false
} }
if (this.timeValue[1] - this.timeValue[0] > 7 * 24 * 3600000) { if (this.timeValue[1] - this.timeValue[0] > 7*24*3600000) {
this.$modal.msgError('最大时间范围为7天请重新选择'); this.$modal.msgError('最大时间范围为7天请重新选择')
this.timeValue = []; this.timeValue = []
} }
break; break
case '2': case '2':
if (!this.dateValue) { if (!this.dateValue) {
this.$modal.msgError('时间范围不能为空'); this.$modal.msgError('时间范围不能为空')
return false; return false
} }
if (this.dateValue[1] - this.dateValue[0] > 29 * 24 * 3600000) { if (this.dateValue[1] - this.dateValue[0] > 29*24*3600000) {
this.$modal.msgError('最大时间范围为30天请重新选择'); // 0:00:0023:59:59 this.$modal.msgError('最大时间范围为30天请重新选择') // 0:00:0023:59:59
this.dateValue = []; this.dateValue = []
} }
break; break
case '4': case '4':
if (!this.monthValue) { if (!this.monthValue) {
this.$modal.msgError('时间范围不能为空'); this.$modal.msgError('时间范围不能为空')
return false; return false
} }
if (this.monthValue[1] - this.monthValue[0] > 729 * 24 * 3600000) { if (this.monthValue[1] - this.monthValue[0] > 729*24*3600000) {
this.$modal.msgError('最大时间范围为24个月请重新选择'); // this.$modal.msgError('最大时间范围为24个月请重新选择')//
this.monthValue = []; this.monthValue = []
} }
break; break
default: default:
} }
}, },
// //
startYear() { startYear() {
if (this.yearValue2 && this.yearValue2 < this.yearValue1) { if (this.yearValue2 && this.yearValue2 < this.yearValue1) {
this.$modal.msgError('开始时间不能晚于结束时间,请重新选择'); this.$modal.msgError('开始时间不能晚于结束时间,请重新选择')
this.yearValue1 = null; this.yearValue1 = null
return false; return false
} }
if (this.yearValue1 && this.yearValue2) { if (this.yearValue1 && this.yearValue2) {
if (this.yearValue2 - this.yearValue1 > 10 * 365 * 24 * 3600000) { if (this.yearValue2 - this.yearValue1 > 10*365*24*3600000) {
this.$modal.msgError('最大时间范围为10年请重新选择'); this.$modal.msgError('最大时间范围为10年请重新选择')
this.yearValue1 = null; this.yearValue1 = null
return false; return false
} }
} }
}, },
endYear() { endYear() {
if (this.yearValue2 && this.yearValue2 < this.yearValue1) { if (this.yearValue2 && this.yearValue2 < this.yearValue1) {
this.$modal.msgError('结束时间不能早于开始时间,请重新选择'); this.$modal.msgError('结束时间不能早于开始时间,请重新选择')
this.yearValue2 = null; this.yearValue2 = null
return false; return false
} }
if (this.yearValue1 && this.yearValue2) { if (this.yearValue1 && this.yearValue2) {
if (this.yearValue2 - this.yearValue1 > 10 * 365 * 24 * 3600000) { if (this.yearValue2 - this.yearValue1 > 10*365*24*3600000) {
this.$modal.msgError('最大时间范围为10年请重新选择'); this.$modal.msgError('最大时间范围为10年请重新选择')
this.yearValue2 = null; this.yearValue2 = null
return false; return false
} }
} }
}, },
// //
startWeek() { startWeek() {
if (this.weekValue1 && this.weekValue2) { if (this.weekValue1 && this.weekValue2) {
let a = new Date(this.weekValue1).getTime(); let a = new Date(this.weekValue1).getTime()
let b = new Date(this.weekValue2).getTime(); let b = new Date(this.weekValue2).getTime()
if (a > b) { if (a > b) {
this.$modal.msgError('开始时间不能晚于结束时间,请重新选择'); this.$modal.msgError('开始时间不能晚于结束时间,请重新选择')
this.weekValue1 = null; this.weekValue1 = null
return false; return false
} }
if (b - a > 167 * 24 * 3600000) { if (b - a > 167*24*3600000) {
this.$modal.msgError('最大时间范围为24周请重新选择'); this.$modal.msgError('最大时间范围为24周请重新选择')
this.weekValue1 = null; this.weekValue1 = null
return false; return false
} }
} }
}, },
endWeek() { endWeek() {
if (this.weekValue1 && this.weekValue2) { if (this.weekValue1 && this.weekValue2) {
let a = new Date(this.weekValue1).getTime(); let a = new Date(this.weekValue1).getTime()
let b = new Date(this.weekValue2).getTime(); let b = new Date(this.weekValue2).getTime()
if (a > b) { if (a > b) {
this.$modal.msgError('结束时间不能早于开始时间,请重新选择'); this.$modal.msgError('结束时间不能早于开始时间,请重新选择')
this.weekValue2 = null; this.weekValue2 = null
return false; return false
} }
if (b - a > 167 * 24 * 3600000) { if (b - a > 167*24*3600000) {
this.$modal.msgError('最大时间范围为24周请重新选择'); this.$modal.msgError('最大时间范围为24周请重新选择')
this.weekValue2 = null; this.weekValue2 = null
return false; return false
} }
} }
}, },
// //
handBtn(val) { search() {
if (!this.queryParams.energyTypeId) { if (!this.queryParams.energyTypeId) {
this.$modal.msgError('请选择能源类型'); this.$modal.msgError('请选择能源类型')
return false; return false
} }
if (this.energyType == 1) {
if (this.objArr.length === 0) { if (this.objArr.length === 0) {
this.$modal.msgError('请选择对象'); this.$modal.msgError('请选择对象')
return false; return false
} else { } else {
this.queryParams.objId = this.objArr[this.objArr.length - 1]; this.queryParams.objId = this.objArr[this.objArr.length-1]
this.queryParams.objType = this.objType;
} }
} else if (this.energyType == 2) {
if (!this.objId) {
this.$modal.msgError('请选择对象');
return false;
} else {
this.queryParams.objId = this.objId;
this.queryParams.objType = 1;
}
}
if (!this.queryParams.timeDim) { if (!this.queryParams.timeDim) {
this.$modal.msgError('请选择时间维度'); this.$modal.msgError('请选择时间维度')
return false; return false
} }
switch (this.queryParams.timeDim) { switch (this.queryParams.timeDim) {
case '1': case '1':
if (this.timeValue && this.timeValue.length > 0) { if (this.timeValue && this.timeValue.length > 0) {
this.queryParams.startTime = this.timeValue[0]; this.queryParams.startTime = this.timeValue[0]
this.queryParams.endTime = this.timeValue[1]; // this.queryParams.endTime = this.timeValue[1] //
} else { } else {
this.$modal.msgError('时间范围不能为空'); this.$modal.msgError('时间范围不能为空')
return false; return false
} }
break; break
case '2': case '2':
if (this.dateValue && this.dateValue.length > 0) { if (this.dateValue && this.dateValue.length > 0) {
this.queryParams.startTime = this.dateValue[0]; this.queryParams.startTime = this.dateValue[0]
this.queryParams.endTime = this.dateValue[1] + 86399000; // 23:59:59 this.queryParams.endTime = this.dateValue[1] + 86399000 // 23:59:59
} else { } else {
this.$modal.msgError('日范围不能为空'); this.$modal.msgError('日范围不能为空')
return false; return false
} }
break; break
case '3': case '3':
if (this.weekValue1 && this.weekValue2) { if (this.weekValue1 && this.weekValue2) {
let a = let a = moment(this.weekValue1).day(0).format('YYYY-MM-DD') + ' 00:00:00'
moment(this.weekValue1).day(0).format('YYYY-MM-DD') + ' 00:00:00'; let b = moment(this.weekValue2).day(6).format('YYYY-MM-DD') + ' 23:59:59'
let b = this.queryParams.startTime = new Date(a).getTime()
moment(this.weekValue2).day(6).format('YYYY-MM-DD') + ' 23:59:59'; this.queryParams.endTime = new Date(b).getTime()
this.queryParams.startTime = new Date(a).getTime();
this.queryParams.endTime = new Date(b).getTime();
} else { } else {
this.$modal.msgError('周范围不能为空'); this.$modal.msgError('周范围不能为空')
return false; return false
} }
break; break
case '4': // case '4'://
if (this.monthValue && this.monthValue.length > 0) { if (this.monthValue && this.monthValue.length > 0) {
this.queryParams.startTime = this.monthValue[0]; this.queryParams.startTime = this.monthValue[0]
this.queryParams.endTime = this.transformTime(this.monthValue[1]); this.queryParams.endTime = this.transformTime(this.monthValue[1])
} else { } else {
this.$modal.msgError('月范围不能为空'); this.$modal.msgError('月范围不能为空')
return false; return false
} }
break; break
default: // default://
if (this.yearValue1 && this.yearValue2) { if (this.yearValue1 && this.yearValue2) {
if (this.yearValue2 < this.yearValue1) { if (this.yearValue2 < this.yearValue1) {
this.$modal.msgError('结束时间不能早于开始时间'); this.$modal.msgError('结束时间不能早于开始时间')
return false; return false
} else { } else {
this.queryParams.startTime = this.yearValue1; this.queryParams.startTime = this.yearValue1
this.queryParams.endTime = this.transformYear(this.yearValue2); this.queryParams.endTime = this.transformYear(this.yearValue2)
} }
} else { } else {
this.$modal.msgError('年范围不能为空'); this.$modal.msgError('年范围不能为空')
return false; return false
} }
} }
this.queryParams.startTime = this.queryParams.startTime + ''; this.queryParams.startTime = this.queryParams.startTime + ''
this.queryParams.endTime = this.queryParams.endTime + ''; this.queryParams.endTime = this.queryParams.endTime + ''
if (val === 'search') { this.$emit('submit', this.queryParams)
this.$emit('submit', this.queryParams);
} else {
this.$emit('export', this.queryParams);
}
}, },
// //
resetBtn() { resetBtn() {
this.queryParams.energyTypeId = null; this.queryParams.energyTypeId = null
this.energyType = 0; this.queryParams.objId = null
this.queryParams.objId = null; this.objArr = []
this.objId = null; this.queryParams.timeDim = this.getDictDatas(this.DICT_TYPE.TIME_DIM)[0].value //
this.objType = 1; this.timeValue = [moment().startOf('day'), moment().endOf('day')-59*61*1000]
this.objArr = [];
this.queryParams.timeDim = this.getDictDatas(
this.DICT_TYPE.TIME_DIM
)[0].value; //
this.timeValue = [
moment().startOf('day'),
moment().endOf('day') - 59 * 61 * 1000,
];
}, },
transformTime(timeStamp) { transformTime(timeStamp) {//
// let year = moment(timeStamp).format('YYYY')
let year = moment(timeStamp).format('YYYY'); let month = moment(timeStamp).format('MM')
let month = moment(timeStamp).format('MM'); let newData = moment(new Date(year,month,0)).format('YYYY-MM-DD') + ' 23:59:59'
let newData = let value = new Date(newData).getTime()
moment(new Date(year, month, 0)).format('YYYY-MM-DD') + ' 23:59:59'; return value
let value = new Date(newData).getTime();
return value;
}, },
transformYear(timeStamp) { transformYear(timeStamp) {//
// let year = moment(timeStamp).format('YYYY')
let year = moment(timeStamp).format('YYYY'); let newData = year+'-12-31 23:59:59'
let newData = year + '-12-31 23:59:59'; let value = new Date(newData).getTime()
let value = new Date(newData).getTime(); return value
return value;
}, },
switchMode() { switchMode() {//
// this.isExpand = !this.isExpand
this.isExpand = !this.isExpand; const element = this.$refs.searchBarRef
const element = this.$refs.searchBarRef;
if (this.isExpand) { if (this.isExpand) {
element.classList.remove('divHeight'); element.classList.remove('divHeight')
} else { } else {
element.classList.add('divHeight'); element.classList.add('divHeight')
} }
}, }
}, }
}; }
</script> </script>
<style lang='scss'> <style lang='scss'>
/* 级联选择器 */
.cascaderParent .el-cascader-panel .el-scrollbar:first-child .el-radio {
display: none;
}
/* 时间整点 */ /* 时间整点 */
.noneMinute .el-time-spinner__wrapper { .noneMinute .el-time-spinner__wrapper {
width: 100%; width: 100%;
@ -530,11 +422,11 @@ export default {
.demo-form-inline { .demo-form-inline {
.el-date-editor .el-range__icon { .el-date-editor .el-range__icon {
font-size: 16px; font-size: 16px;
color: #0b58ff; color: #0B58FF;
} }
.el-input__prefix .el-icon-date { .el-input__prefix .el-icon-date {
font-size: 16px; font-size: 16px;
color: #0b58ff; color: #0B58FF;
} }
} }
</style> </style>
@ -544,15 +436,11 @@ export default {
display: inline-block; display: inline-block;
width: 4px; width: 4px;
height: 16px; height: 16px;
background-color: #0b58ff; background-color: #0B58FF;
border-radius: 1px; border-radius: 1px;
margin-right: 8px; margin-right: 8px;
margin-top: 12px; margin-top: 12px;
} }
.el-form-item {
margin-right: 10px;
margin-bottom: 4px;
}
} }
.searchBarBox .foldClass { .searchBarBox .foldClass {
position: absolute; position: absolute;
@ -560,7 +448,7 @@ export default {
right: 0; right: 0;
cursor: pointer; cursor: pointer;
font-size: 12px; font-size: 12px;
color: #0b58ff; color:#0B58FF;
} }
.searchBarBox .foldClass .iconfont { .searchBarBox .foldClass .iconfont {
font-size: 14px; font-size: 14px;
@ -573,7 +461,7 @@ export default {
display: inline-block; display: inline-block;
width: 1px; width: 1px;
height: 24px; height: 24px;
background: #e8e8e8; background: #E8E8E8;
vertical-align: middle; vertical-align: middle;
margin: 0 10px; margin: 0 10px;
} }

View File

@ -1,113 +1,94 @@
<template> <template>
<div <div class="app-container trendAnalysisBox" id="trendAnalysisBox">
class="app-container trendAnalysisBox"
id="trendAnalysisBox">
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<search-area <search-area :isFold="isFold" @submit="getList"/>
:isFold="isFold" <el-tabs v-model="activeName" @tab-click="switchChart" v-show='chartData.length'>
@submit="getList" <el-tab-pane label="柱状图" name="bar">
@export="exportExl" /> <bar-chart ref="analysisBarChart" :chartData="chartData" :timeDim="timeDim"/>
<div v-show="chartData.length"> </el-tab-pane>
<base-table <el-tab-pane label="折线图" name="line">
:table-props="tableProps" <line-chart ref="analysisLineChart" :chartData="chartData" :timeDim="timeDim"/>
:table-data="list" </el-tab-pane>
class="trend-out-table" /> </el-tabs>
<line-chart
ref="analysisLineChart"
:chartData="chartData"
:timeDim="timeDim" />
</div>
<!-- 没有数据 --> <!-- 没有数据 -->
<div <div class="no-data-bg" v-show='!chartData.length'></div>
class="no-data-bg"
v-show="!chartData.length"></div>
</div> </div>
</template> </template>
<script> <script>
import { getEnergyTrend, exportTrend } from '@/api/analysis/energyAnalysis'; import { getEnergyTrend } from "@/api/analysis/energyAnalysis"
import SearchArea from './components/searchArea'; import SearchArea from "./components/searchArea"
import LineChart from './components/lineChart'; import BarChart from "./components/barChart"
import LineChart from "./components/lineChart"
// import moment from 'moment' // import moment from 'moment'
export default { export default {
name: 'TrendAnalysis', name: 'TrendAnalysis',
components: { SearchArea, LineChart }, components: { SearchArea, BarChart, LineChart },
data() { data() {
return { return {
isFold: false, isFold: false,
activeName: 'bar',
chartData: [], chartData: [],
timeDim: '', timeDim: ''
tableProps: [], }
list: [],
};
}, },
mounted() { mounted() {
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
this.tableH = this.tableHeight(260); this.tableH = this.tableHeight(260)
this.isFold = this.searchBarWidth('trendAnalysisBox', 1480); this.isFold = this.searchBarWidth('trendAnalysisBox', 1263)
}); })
this.isFold = this.searchBarWidth('trendAnalysisBox', 1480); this.isFold = this.searchBarWidth('trendAnalysisBox', 1263)
}, },
methods: { methods: {
getList(params) { getList(params) {
this.timeDim = params.timeDim; this.timeDim = params.timeDim
getEnergyTrend({ ...params }).then((res) => { getEnergyTrend({ ...params }).then((res) => {
if (res.code === 0) { if (res.code === 0) {
this.getTableList(res.data || []); this.chartData = res.data
this.chartData = res.data || [];
} else { } else {
this.chartData = []; this.chartData = []
} }
}); })
}, },
getTableList(arr) { switchChart() {
this.tableProps = []; if (this.activeName === 'bar') {
this.list = []; this.$nextTick((res) => {
let tempX = []; this.$refs.analysisBarChart.getChart()
let listObj = { useNum: '消耗量' }; // })
for (let i = 0; i < arr.length; i++) { } else {
let obj = {}; this.$nextTick((res) => {
obj.prop = arr[i].time; this.$refs.analysisLineChart.getChart()
obj.label = arr[i].time; })
obj.minWidth = 100;
tempX.push(obj);
listObj[arr[i].time] = arr[i].useNum || null;
} }
this.tableProps = [{ prop: 'useNum', label: '时间' }].concat(tempX); }
this.list.push(listObj); }
}, }
// excel
exportExl(params) {
exportTrend({ ...params }).then((res) => {
// let fileName = '';
// const contentDisposition = res.headers['content-disposition'];
// if (contentDisposition) {
// fileName = decodeURIComponent(
// contentDisposition.slice(
// contentDisposition.indexOf('filename=') + 9
// )
// );
// }
const blob = new Blob([res.data]);
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = (e) => {
const a = document.createElement('a');
a.download = '走势分析';
a.href = e.target.result;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
this.$message.success('导出成功');
};
});
},
},
};
</script> </script>
<style lang='scss'> <style lang='scss'>
.trendAnalysisBox { .trendAnalysisBox {
.trend-out-table { .el-tabs__nav::after {
margin-bottom: 15px; content: "";
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 2px;
background-color: #e4e7ed;
/* z-index: 1; */
}
.el-tabs__nav-wrap::after {
width: 0;
}
.el-tabs__item {
padding: 0 10px;
}
.el-tabs__item:hover {
color: rgba(0, 0, 0, 0.85);
}
.el-tabs__item.is-active {
color: rgba(0, 0, 0, 0.85);
}
.el-tabs__item {
color: rgba(0, 0, 0, 0.45);
} }
} }
</style> </style>

View File

@ -1,44 +1,27 @@
<template> <template>
<el-form <el-form :inline="true" class="demo-form-inline">
:inline="true"
class="demo-form-inline">
<span class="blue-block"></span> <span class="blue-block"></span>
<el-form-item <el-form-item label="对象选择" required>
label="对象选择" <el-cascader
required> v-model="objArr"
<el-select :options="objList"
v-model="queryParams.objId" :props="{ checkStrictly: true, value: 'id', label: 'name' }"
placeholder="请选择" popper-class="cascaderParent"
style="width: 250px" size="small"
filterable clearable></el-cascader>
size="small">
<el-option
v-for="item in objList"
:key="item.id"
:label="item.name"
:value="item.id"
:clearable="false"></el-option>
</el-select>
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="时间维度" required>
label="时间维度" <el-select v-model="queryParams.type" placeholder="请选择" style="width: 80px;" size="small">
required>
<el-select
v-model="queryParams.type"
placeholder="请选择"
style="width: 80px"
size="small">
<el-option <el-option
v-for="item in timeType" v-for="item in timeType"
:key="item.id" :key="item.id"
:label="item.name" :label="item.name"
:value="item.id" :value="item.id"
:clearable="false"></el-option> :clearable="false">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="时间" required>
label="时间"
required>
<div v-show="queryParams.type === 1 || queryParams.type === 2"> <div v-show="queryParams.type === 1 || queryParams.type === 2">
<el-date-picker <el-date-picker
v-model="yearValue" v-model="yearValue"
@ -47,7 +30,8 @@
@change="selectTime" @change="selectTime"
:clearable="false" :clearable="false"
size="small" size="small"
placeholder="选择年"></el-date-picker> placeholder="选择年">
</el-date-picker>
</div> </div>
<div v-show="queryParams.type === 3"> <div v-show="queryParams.type === 3">
<el-date-picker <el-date-picker
@ -57,34 +41,24 @@
@change="selectTime" @change="selectTime"
:clearable="false" :clearable="false"
size="small" size="small"
placeholder="选择月"></el-date-picker> placeholder="选择月">
</el-date-picker>
</div> </div>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button <el-button type="primary" size="small" @click="search">查询</el-button>
type="primary"
size="small"
@click="search">
查询
</el-button>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<span class="separateStyle"></span> <span class="separateStyle"></span>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button <el-button type="primary" size="small" @click="exportData" plain>导出</el-button>
type="primary"
size="small"
@click="exportData"
plain>
导出
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</template> </template>
<script> <script>
import { getTree } from '@/api/analysis/energyAnalysis'; import { getTree } from '@/api/base/factory'
import moment from 'moment'; import moment from 'moment'
export default { export default {
name: 'searchArea', name: 'searchArea',
data() { data() {
@ -93,111 +67,119 @@ export default {
queryParams: { queryParams: {
type: 1, // 123 type: 1, // 123
searchTime: null, searchTime: null,
objId: null, objId: null
objType: 1,
}, },
timeType: [ timeType: [
{ id: 1, name: '季度' }, {id: 1, name: '季度'},
{ id: 2, name: '月' }, {id: 2, name: '月'},
{ id: 3, name: '日' }, {id: 3, name: '日'}
], ],
yearValue: '', yearValue: '',
yearMonth: '', yearMonth: '',
objArr: [],
objList: [], objList: [],
pickerOptions: { pickerOptions: {
disabledDate(date) { disabledDate(date) {
return date.getTime() > Date.now(); return date.getTime() > Date.now()
}, }
}, }
}; }
}, },
mounted() { mounted() {
this.getObjTree(); this.getObjTree()
}, },
methods: { methods: {
getObjTree() { getObjTree() {
getTree().then((res) => { getTree().then(res => {
this.objList = res.data || []; this.objList = res.data || []
if (this.objList.length > 0) { })
this.queryParams.objId = this.objList[0].id;
}
});
}, },
selectTime() { selectTime() {
if (this.queryParams.type === 3) { if (this.queryParams.type === 3) {
this.queryParams.searchTime = this.yearMonth; this.queryParams.searchTime = this.yearMonth
} else { } else {
this.queryParams.searchTime = this.yearValue; this.queryParams.searchTime = this.yearValue
} }
}, },
// //
search() { search() {
if (!this.queryParams.objId) { if (this.objArr.length === 0) {
this.$modal.msgError('请选择对象'); this.$modal.msgError('请选择对象')
return false; return false
} else {
this.queryParams.objId = this.objArr[this.objArr.length-1]
} }
if (!this.queryParams.type) { if (!this.queryParams.type) {
this.$modal.msgError('请选择时间维度'); this.$modal.msgError('请选择时间维度')
return false; return false
} }
if (!this.queryParams.searchTime) { if (!this.queryParams.searchTime) {
this.$modal.msgError('请选择时间'); this.$modal.msgError('请选择时间')
return false; return false
} }
if (this.queryParams.type === 3) { if (this.queryParams.type === 3) {
this.queryParams.searchTime = this.transformTime(this.yearMonth) + ''; this.queryParams.searchTime = this.transformTime(this.yearMonth) + ''
} else { } else {
this.queryParams.searchTime = this.transformYear(this.yearValue) + ''; this.queryParams.searchTime = this.transformYear(this.yearValue) + ''
} }
this.$emit('submit', this.queryParams); this.$emit('submit', this.queryParams)
}, },
exportData() { exportData() {
let name; let name
if (this.queryParams.objId) { if (this.queryParams.objId) {
name = this.getObjName(this.objList, this.queryParams.objId); name = this.getObjName(this.objList, this.queryParams.objId)
} else { } else {
this.$modal.msgWarning('对象不能为空'); this.$modal.msgWarning("对象不能为空")
return false; return false
} }
this.$emit('exportD', { name: name }); this.$emit('exportD', {name: name})
}, },
// name // name
getObjName(list, id) { getObjName(list, id) {
let _this = this
for (let i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
let a = list[i]; let a = list[i]
if (a.id === id) { if (a.id === id) {
return a.name; return a.name
} else {
if (a.children && a.children.length > 0) {
let res = _this.getObjName(a.children, id)
if (res) {
return res
}
}
} }
} }
}, },
transformTime(timeStamp) { transformTime(timeStamp) {//
// let year = moment(timeStamp).format('YYYY')
let year = moment(timeStamp).format('YYYY'); let month = moment(timeStamp).format('MM')
let month = moment(timeStamp).format('MM'); let newData = moment(new Date(year,month,0)).format('YYYY-MM-DD') + ' 23:59:59'
let newData = let value = new Date(newData).getTime()
moment(new Date(year, month, 0)).format('YYYY-MM-DD') + ' 23:59:59'; return value
let value = new Date(newData).getTime();
return value;
}, },
transformYear(timeStamp) { transformYear(timeStamp) {//
// let year = moment(timeStamp).format('YYYY')
let year = moment(timeStamp).format('YYYY'); let newData = year+'-12-31 23:59:59'
let newData = year + '-12-31 23:59:59'; let value = new Date(newData).getTime()
let value = new Date(newData).getTime(); return value
return value; }
}, }
}, }
};
</script> </script>
<style lang='scss'> <style lang='scss'>
/* 级联选择器 */
.cascaderParent .el-cascader-panel .el-scrollbar:first-child .el-radio {
display: none;
}
.demo-form-inline { .demo-form-inline {
.el-date-editor .el-range__icon { .el-date-editor .el-range__icon {
font-size: 16px; font-size: 16px;
color: #0b58ff; color: #0B58FF;
} }
.el-input__prefix .el-icon-date { .el-input__prefix .el-icon-date {
font-size: 16px; font-size: 16px;
color: #0b58ff; color: #0B58FF;
} }
} }
</style> </style>
@ -207,21 +189,17 @@ export default {
display: inline-block; display: inline-block;
width: 4px; width: 4px;
height: 16px; height: 16px;
background-color: #0b58ff; background-color: #0B58FF;
border-radius: 1px; border-radius: 1px;
margin-right: 8px; margin-right: 8px;
margin-top: 10px; margin-top: 10px;
} }
.el-form-item {
margin-right: 10px;
margin-bottom: 4px;
}
} }
.separateStyle { .separateStyle {
display: inline-block; display: inline-block;
width: 1px; width: 1px;
height: 24px; height: 24px;
background: #e8e8e8; background: #E8E8E8;
vertical-align: middle; vertical-align: middle;
} }
</style> </style>

View File

@ -1,50 +1,36 @@
<template> <template>
<el-form <el-form ref="form" :rules="rules" label-width="100px" :model="form">
ref="form" <el-form-item label="关联表名" prop="plcId">
:rules="rules" <el-select v-model="form.plcId" placeholder="请选择" style="width: 100%;" filterable>
label-width="100px"
:model="form">
<el-form-item
label="关联表名"
prop="plcId">
<el-select
v-model="form.plcId"
placeholder="请选择"
style="width: 100%"
filterable>
<el-option <el-option
v-for="item in plcList" v-for="item in plcList"
:key="item.id" :key="item.id"
:label="item.plcTableName" :label="item.plcTableName"
:value="item.id"></el-option> :value="item.id">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="对象" prop="bindObjectId">
label="对象"
prop="bindObjectId">
<el-cascader <el-cascader
style="width: 100%" style='width: 100%;'
v-model="objIds" v-model="objIds"
:options="objList" :options="objList"
:props="{ checkStrictly: true, value: 'id', label: 'name' }" :props="{ checkStrictly: true, value: 'id', label: 'name' }"
popper-class="cascaderParent"
@change="selectObj" @change="selectObj"
clearable></el-cascader> clearable></el-cascader>
</el-form-item> </el-form-item>
</el-form> </el-form>
</template> </template>
<script> <script>
import { import { getEnergyPlcConnect, updateEnergyPlcConnect, createEnergyPlcConnect } from '@/api/base/energyPlcConnect'
getEnergyPlcConnect, import { getEnergyPlcAll } from '@/api/base/energyPlc'
updateEnergyPlcConnect,
createEnergyPlcConnect,
} from '@/api/base/energyPlcConnect';
import { getEnergyPlcAll } from '@/api/base/energyPlc';
export default { export default {
name: 'EnergyPlcConnectAdd', name: 'EnergyPlcConnectAdd',
props: { props: {
objList: { objList: {
type: Array, type: Array,
default: () => [], default: () => []
}, },
}, },
data() { data() {
@ -53,103 +39,101 @@ export default {
id: '', id: '',
plcId: '', plcId: '',
bindObjectId: '', bindObjectId: '',
bindObjectType: '', bindObjectType: ''
}, },
objIds: [], // objIds: [],//
plcList: [], plcList: [],
isEdit: false, // isEdit: false, //
rules: { rules: {
plcId: [ plcId: [{ required: true, message: '关联表名不能为空', trigger: 'change' }],
{ required: true, message: '关联表名不能为空', trigger: 'change' }, bindObjectId: [{ required: true, message: '对象不能为空', trigger: 'change' }]
], }
bindObjectId: [ }
{ required: true, message: '对象不能为空', trigger: 'change' },
],
},
};
}, },
methods: { methods: {
init(id) { init(id) {
getEnergyPlcAll().then((res) => { getEnergyPlcAll().then((res) => {
this.plcList = res.data || []; this.plcList = res.data || []
}); })
if (id) { if (id) {
this.isEdit = true; this.isEdit = true
this.form.id = id; this.form.id = id
getEnergyPlcConnect(id).then((res) => { getEnergyPlcConnect( id ).then((res) => {
if (res.code === 0) { if (res.code === 0) {
this.form = res.data; this.form = res.data
this.objIds = this.changeDetSelect( this.objIds = this.changeDetSelect(this.form.bindObjectId, this.objList)
this.form.bindObjectId,
this.objList
);
} }
}); })
} else { } else {
this.isEdit = false; this.isEdit = false
this.form.id = ''; this.form.id = ''
} }
}, },
// //
changeDetSelect(key, treeData) { changeDetSelect(key, treeData) {
let arr = []; // let arr = [] //
let returnArr = []; // let returnArr = [] //
let depth = 0; // let depth = 0 //
// //
function childrenEach(childrendData, depthN) { function childrenEach(childrendData, depthN) {
for (var j = 0; j < childrendData.length; j++) { for (var j = 0; j < childrendData.length; j++) {
depth = depthN; depth = depthN
arr[depthN] = childrendData[j].id; arr[depthN] = childrendData[j].id
if (childrendData[j].id == key) { if (childrendData[j].id == key) {
returnArr = arr.slice(0, depthN + 1); returnArr = arr.slice(0, depthN + 1)
break; break
} else { } else {
if (childrendData[j].children) { if (childrendData[j].children) {
depth++; depth++
childrenEach(childrendData[j].children, depth); childrenEach(childrendData[j].children, depth)
} }
} }
} }
return returnArr; return returnArr
} }
return childrenEach(treeData, depth); return childrenEach(treeData, depth)
}, },
selectObj(val) { selectObj(val) {
this.form.bindObjectId = val[val.length - 1]; this.form.bindObjectId = val[val.length-1]
this.form.bindObjectType = val.length - 1; this.form.bindObjectType = val.length-1
}, },
submitForm() { submitForm() {
this.$refs['form'].validate((valid) => { this.$refs['form'].validate((valid) => {
if (valid) { if (valid) {
if (this.isEdit) { if (this.isEdit) {
// //
updateEnergyPlcConnect({ ...this.form }).then((res) => { updateEnergyPlcConnect({...this.form}).then((res) => {
if (res.code === 0) { if (res.code === 0) {
this.$modal.msgSuccess('操作成功'); this.$modal.msgSuccess("操作成功");
this.$emit('successSubmit'); this.$emit('successSubmit')
} }
}); })
} else { } else {
createEnergyPlcConnect({ ...this.form }).then((res) => { createEnergyPlcConnect({...this.form}).then((res) => {
if (res.code === 0) { if (res.code === 0) {
this.$modal.msgSuccess('操作成功'); this.$modal.msgSuccess("操作成功");
this.$emit('successSubmit'); this.$emit('successSubmit')
} }
}); })
} }
} else { } else {
return false; return false
} }
}); })
}, },
formClear() { formClear() {
this.form.id = ''; this.form.id = ''
this.form.plcId = ''; this.form.plcId = ''
this.form.bindObjectId = ''; this.form.bindObjectId = ''
this.form.bindObjectType = ''; this.form.bindObjectType = ''
this.objIds = []; this.objIds = []
this.isEdit = false; this.isEdit = false
}, }
}, }
}; }
</script> </script>
<style>
.cascaderParent .el-cascader-panel .el-scrollbar:first-child .el-radio {
display: none;
}
</style>

View File

@ -1,95 +1,67 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<search-bar <search-bar :formConfigs="formConfig" ref="searchBarForm" @headBtnClick="buttonClick" />
:formConfigs="formConfig"
ref="searchBarForm"
@headBtnClick="buttonClick" />
<!-- 列表 --> <!-- 列表 -->
<base-table <base-table :page="queryParams.pageNo" :limit="queryParams.pageSize" :table-props="tableProps" :table-data="list"
:page="queryParams.pageNo"
:limit="queryParams.pageSize"
:table-props="tableProps"
:table-data="list"
:max-height="tableH"> :max-height="tableH">
<method-btn <method-btn v-if="tableBtn.length" slot="handleBtn" :width="160" label="操作" :method-list="tableBtn"
v-if="tableBtn.length"
slot="handleBtn"
:width="160"
label="操作"
:method-list="tableBtn"
@clickBtn="handleClick" /> @clickBtn="handleClick" />
</base-table> </base-table>
<pagination <pagination :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" :total="total"
:page.sync="queryParams.pageNo"
:limit.sync="queryParams.pageSize"
:total="total"
@pagination="getList" /> @pagination="getList" />
<!-- 新增 --> <!-- 新增 -->
<base-dialog <base-dialog :dialogTitle="addOrEditTitle" :dialogVisible="centervisible" @cancel="handleCancel"
:dialogTitle="addOrEditTitle" @confirm="handleConfirm" :before-close="handleCancel" width='30%'>
:dialogVisible="centervisible" <energy-plc-connect-add ref="energyPlcConnect" :objList="objList" @successSubmit="successSubmit" />
@cancel="handleCancel"
@confirm="handleConfirm"
:before-close="handleCancel"
width="30%">
<energy-plc-connect-add
ref="energyPlcConnect"
:objList="objList"
@successSubmit="successSubmit" />
</base-dialog> </base-dialog>
<!-- 参数绑定/查看 --> <!-- 参数绑定/查看 -->
<energy-plc-param <energy-plc-param v-if="paramVisible" ref="plcParam" @closeDrawer="closeDrawer"
v-if="paramVisible"
ref="plcParam"
@closeDrawer="closeDrawer"
:energyTypeList="energyTypeList"></energy-plc-param> :energyTypeList="energyTypeList"></energy-plc-param>
</div> </div>
</template> </template>
<script> <script>
import { import { getEnergyPlcConnectPage, deleteEnergyPlcConnect } from "@/api/base/energyPlcConnect";
getEnergyPlcConnectPage,
deleteEnergyPlcConnect,
} from '@/api/base/energyPlcConnect';
// import { publicFormatter } from '@/utils/dict' // import { publicFormatter } from '@/utils/dict'
import { getTree } from '@/api/analysis/energyAnalysis'; import { getTree } from '@/api/base/factory'
import { getEnergyTypeListAll } from '@/api/base/energyType'; import { getEnergyTypeListAll } from '@/api/base/energyType'
import EnergyPlcConnectAdd from './components/energyPlcConnectAdd'; import EnergyPlcConnectAdd from './components/energyPlcConnectAdd'
import EnergyPlcParam from './components/energyPlcParam'; import EnergyPlcParam from './components/energyPlcParam'
const tableProps = [ const tableProps = [
{ {
prop: 'objName', prop: 'objName',
label: '对象', label: '对象'
}, },
{ {
prop: 'objCode', prop: 'objCode',
label: '对象编码', label: '对象编码',
showOverflowtooltip: true, showOverflowtooltip: true
}, },
{ {
prop: 'plcTableName', prop: 'plcTableName',
label: '关联表名', label: '关联表名'
}, },
{ {
prop: 'plcTableCode', prop: 'plcTableCode',
label: '关联表编码', label: '关联表编码',
minWidth: 150, minWidth: 150,
showOverflowtooltip: true, showOverflowtooltip: true
}, },
{ {
prop: 'cnName', prop: 'cnName',
label: '标识名', label: '标识名',
minWidth: 150, minWidth: 150,
showOverflowtooltip: true, showOverflowtooltip: true
}, },
{ {
prop: 'varNum', prop: 'varNum',
label: '绑定参数数量', label: '绑定参数数量'
}, }
]; ]
export default { export default {
name: 'EnergyPlcConnect', name: "EnergyPlcConnect",
components: { EnergyPlcConnectAdd, EnergyPlcParam }, components: { EnergyPlcConnectAdd, EnergyPlcParam },
data() { data() {
return { return {
@ -98,51 +70,49 @@ export default {
type: 'input', type: 'input',
label: '标识名', label: '标识名',
placeholder: '标识名', placeholder: '标识名',
param: 'cnName', param: 'cnName'
}, },
{ {
type: 'button', type: 'button',
btnName: '查询', btnName: '查询',
name: 'search', name: 'search',
color: 'primary', color: 'primary'
}, },
{ {
type: 'separate', type: 'separate'
}, },
{ {
type: this.$auth.hasPermi('base:energy-plc-connect:create') type: this.$auth.hasPermi('base:energy-plc-connect:create') ? 'button' : '',
? 'button'
: '',
btnName: '新增', btnName: '新增',
name: 'add', name: 'add',
color: 'success', color: 'success',
plain: true, plain: true
}, }
], ],
tableProps, tableProps,
tableBtn: [ tableBtn: [
this.$auth.hasPermi('base:energy-plc-connect:bind') this.$auth.hasPermi('base:energy-plc-connect:bind')
? { ? {
type: 'connect', type: 'connect',
btnName: '绑定', btnName: '绑定'
} }
: undefined, : undefined,
{ {
type: 'detail', type: 'detail',
btnName: '详情', btnName: '详情'
}, },
this.$auth.hasPermi('base:energy-plc-connect:update') this.$auth.hasPermi('base:energy-plc-connect:update')
? { ? {
type: 'edit', type: 'edit',
btnName: '编辑', btnName: '编辑'
} }
: undefined, : undefined,
this.$auth.hasPermi('base:energy-plc-connect:delete') this.$auth.hasPermi('base:energy-plc-connect:delete')
? { ? {
type: 'delete', type: 'delete',
btnName: '删除', btnName: '删除'
} }
: undefined, : undefined
].filter((v) => v), ].filter((v) => v),
tableH: this.tableHeight(260), tableH: this.tableHeight(260),
// //
@ -150,121 +120,117 @@ export default {
// //
list: [], list: [],
// //
addOrEditTitle: '', addOrEditTitle: "",
// //
centervisible: false, centervisible: false,
// //
queryParams: { queryParams: {
pageNo: 1, pageNo: 1,
pageSize: 20, pageSize: 20,
cnName: null, cnName: null
}, },
paramVisible: false, paramVisible: false,
energyTypeList: [], energyTypeList: [],
objList: [], objList: []
}; };
}, },
created() { created() {
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
this.tableH = this.tableHeight(260); this.tableH = this.tableHeight(260)
}); })
this.getList(); this.getList();
}, },
mounted() { mounted() {
// //
this.getEnergyTypeList(); this.getEnergyTypeList()
// //
this.getObjTree(); this.getObjTree()
}, },
methods: { methods: {
buttonClick(val) { buttonClick(val) {
switch (val.btnName) { switch (val.btnName) {
case 'search': case 'search':
this.queryParams.pageNo = 1; this.queryParams.pageNo = 1;
this.queryParams.cnName = val.cnName; this.queryParams.cnName = val.cnName
this.getList(); this.getList()
break; break
default: default:
this.addOrEditTitle = '新增'; this.addOrEditTitle = '新增'
this.centervisible = true; this.centervisible = true
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.energyPlcConnect.init(); this.$refs.energyPlcConnect.init()
}); })
} }
}, },
/** 查询列表 */ /** 查询列表 */
getList() { getList() {
getEnergyPlcConnectPage(this.queryParams).then((response) => { getEnergyPlcConnectPage(this.queryParams).then(response => {
let arr = response.data.list || []; let arr = response.data.list || [];
this.list = arr; this.list = arr
this.total = response.data.total; this.total = response.data.total;
}); });
}, },
handleClick(val) { handleClick(val) {
console.log(val); console.log(val)
switch (val.type) { switch (val.type) {
case 'edit': case 'edit':
this.addOrEditTitle = '编辑'; this.addOrEditTitle = '编辑'
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.energyPlcConnect.init(val.data.id); this.$refs.energyPlcConnect.init(val.data.id)
}); })
this.centervisible = true; this.centervisible = true
break; break
case 'delete': case 'delete':
this.handleDelete(val.data); this.handleDelete(val.data)
break; break
case 'detail': case 'detail':
this.paramVisible = true; this.paramVisible = true
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.plcParam.init(val.data, 'detail'); this.$refs.plcParam.init(val.data, 'detail')
}); })
break; break
default: default:
this.paramVisible = true; this.paramVisible = true
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.plcParam.init(val.data, 'connect'); this.$refs.plcParam.init(val.data, 'connect')
}); })
} }
}, },
handleCancel() { handleCancel() {
this.$refs.energyPlcConnect.formClear(); this.$refs.energyPlcConnect.formClear()
this.centervisible = false; this.centervisible = false
this.addOrEditTitle = ''; this.addOrEditTitle = ''
}, },
handleConfirm() { handleConfirm() {
this.$refs.energyPlcConnect.submitForm(); this.$refs.energyPlcConnect.submitForm()
}, },
successSubmit() { successSubmit() {
this.handleCancel(); this.handleCancel()
this.getList(); this.getList()
}, },
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
this.$modal this.$modal.confirm('是否确认删除对象为"' + row.objName + '"的数据项?').then(function () {
.confirm('是否确认删除对象为"' + row.objName + '"的数据项?')
.then(function () {
return deleteEnergyPlcConnect(row.id); return deleteEnergyPlcConnect(row.id);
}) }).then(() => {
.then(() => {
this.queryParams.pageNo = 1; this.queryParams.pageNo = 1;
this.getList(); this.getList();
this.$modal.msgSuccess('删除成功'); this.$modal.msgSuccess("删除成功");
}) }).catch(() => { });
.catch(() => {});
}, },
closeDrawer() { closeDrawer() {
this.getList(); this.getList()
}, },
getEnergyTypeList() { getEnergyTypeList() {
getEnergyTypeListAll().then((res) => { getEnergyTypeListAll().then((res) => {
this.energyTypeList = res.data || []; this.energyTypeList = res.data || []
}); })
}, },
getObjTree() { getObjTree() {
getTree().then((res) => { getTree().then(res => {
this.objList = res.data || []; this.objList = res.data || []
}); })
}, }
}, }
}; };
</script> </script>

View File

@ -1,161 +1,79 @@
<template> <template>
<el-form <el-form ref="form" :rules="rules" label-width="100px" :model="form">
ref="form"
:rules="rules"
label-width="100px"
:model="form">
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<el-form-item <el-form-item label="能源类型" prop="name">
label="能源类型" <el-input v-model="form.name"></el-input>
prop="name">
<el-select
v-model="form.name"
placeholder="请选择"
style="width: 100%">
<el-option
v-for="item in getDictDatas(DICT_TYPE.ENERGY_TYPE)"
:key="item.value"
:label="item.label"
:value="item.value"></el-option>
</el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item <el-form-item label="类型编码" prop="code">
label="类型编码" <el-input v-model="form.code" disabled></el-input>
prop="code">
<el-input
v-model="form.code"
disabled></el-input>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<el-form-item <el-form-item label="单位" prop="unit">
label="单位" <el-select v-model="form.unit" placeholder="请选择" style="width: 100%;">
prop="unit"> <el-option v-for="item in getDictDatas(DICT_TYPE.ENERGY_UNIT)" :key="item.value" :label="item.label"
<el-select :value="item.value">
v-model="form.unit" </el-option>
placeholder="请选择"
filterable
style="width: 100%">
<el-option
v-for="item in getDictDatas(DICT_TYPE.UNIT_DICT)"
:key="item.value"
:label="item.label"
:value="item.value"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item <el-form-item label="计价方式" prop="pricingMethod">
label="计价方式" <el-select v-model="form.pricingMethod" placeholder="请选择" style="width: 100%;">
prop="pricingMethod"> <el-option label="时间段" :value='0'></el-option>
<el-select <el-option label="使用量" :value='1'></el-option>
v-model="form.pricingMethod" <el-option label="固定价位" :value='2'></el-option>
placeholder="请选择"
style="width: 100%">
<el-option
label="时间段"
:value="0"></el-option>
<el-option
label="使用量"
:value="1"></el-option>
<el-option
label="固定价位"
:value="2"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row> <el-row>
<el-col <el-col :span="12" v-show="form.pricingMethod === 2">
:span="12" <el-form-item label="单价(元)" prop="pricingMethod">
v-show="form.pricingMethod === 2"> <el-input-number v-model="form.singlePrice" :precision="2" :min="0" :max="999999999"
<el-form-item style="width: 100%;"></el-input-number>
label="单价(元)"
prop="pricingMethod">
<el-input-number
v-model="form.singlePrice"
:precision="2"
:min="0"
:max="999999999"
style="width: 100%"></el-input-number>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col <el-col :span="12" v-show="form.pricingMethod === 1">
:span="12" <el-form-item label="计量维度" prop="dim">
v-show="form.pricingMethod === 1"> <el-select v-model="form.dim" placeholder="请选择" style="width: 100%;">
<el-form-item <el-option label="月" :value='4'></el-option>
label="计量维度" <el-option label="年" :value='5'></el-option>
prop="dim">
<el-select
v-model="form.dim"
placeholder="请选择"
style="width: 100%">
<el-option
label="月"
:value="4"></el-option>
<el-option
label="年"
:value="5"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col <el-col :span="24" v-show="form.pricingMethod === 0">
:span="24" <el-form-item label="时间段" prop="pricingMethod">
v-show="form.pricingMethod === 0"> <base-table :key='timeKye' :table-props="tableProps1" :table-data="tableData1"
<el-form-item :add-button-show="addButtonShow" @emitButtonClick="emitButtonClick1" @emitFun="inputChange1">
label="时间段" <method-btn v-if="tableBtn.length" slot="handleBtn" :width="80" label="操作" :method-list="tableBtn"
prop="pricingMethod">
<base-table
:key="timeKye"
:table-props="tableProps1"
:table-data="tableData1"
:add-button-show="addButtonShow"
@emitButtonClick="emitButtonClick1"
@emitFun="inputChange1">
<method-btn
v-if="tableBtn.length"
slot="handleBtn"
:width="80"
label="操作"
:method-list="tableBtn"
@clickBtn="handleClick1" /> @clickBtn="handleClick1" />
</base-table> </base-table>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col <el-col :span="24" v-show="form.pricingMethod === 1">
:span="24" <el-form-item label="使用量" prop="pricingMethod">
v-show="form.pricingMethod === 1"> <base-table :key='usedKye' :table-props="tableProps2" :table-data="tableData2"
<el-form-item :add-button-show="addButtonShow" @emitButtonClick="emitButtonClick2" @emitFun="inputChange2">
label="使用量" <method-btn v-if="tableBtn.length" slot="handleBtn" :width="80" label="操作" :method-list="tableBtn"
prop="pricingMethod">
<base-table
:key="usedKye"
:table-props="tableProps2"
:table-data="tableData2"
:add-button-show="addButtonShow"
@emitButtonClick="emitButtonClick2"
@emitFun="inputChange2">
<method-btn
v-if="tableBtn.length"
slot="handleBtn"
:width="80"
label="操作"
:method-list="tableBtn"
@clickBtn="handleClick2" /> @clickBtn="handleClick2" />
</base-table> </base-table>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row> <el-row>
<el-col :span="24"> <el-col :span="12">
<el-form-item <el-form-item label="是否推送" prop="push">
label="描述" <el-switch v-model="form.push"></el-switch>
prop="description"> </el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="描述" prop="description">
<el-input v-model="form.description"></el-input> <el-input v-model="form.description"></el-input>
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -163,31 +81,26 @@
</el-form> </el-form>
</template> </template>
<script> <script>
import { import { getEnergyType, updateEnergyType, createEnergyType, getEnergyTypeCode } from '@/api/base/energyType'
getEnergyType, import inputArea from './InputArea.vue'
updateEnergyType, import timePickerArea from './TimePickerArea.vue'
createEnergyType,
getEnergyTypeCode,
} from '@/api/base/energyType';
import inputArea from './InputArea.vue';
import timePickerArea from './TimePickerArea.vue';
const tableProps1 = [ const tableProps1 = [
{ {
prop: 'startTime', prop: 'startTime',
label: '开始时间', label: '开始时间',
subcomponent: timePickerArea, subcomponent: timePickerArea
}, },
{ {
prop: 'endTime', prop: 'endTime',
label: '结束时间', label: '结束时间',
subcomponent: timePickerArea, subcomponent: timePickerArea
}, },
{ {
prop: 'price', prop: 'price',
label: '单价(元)', label: '单价(元)',
subcomponent: inputArea, subcomponent: inputArea
}, }
]; ]
const tableProps2 = [ const tableProps2 = [
{ {
prop: 'startUsed', prop: 'startUsed',
@ -197,14 +110,14 @@ const tableProps2 = [
{ {
prop: 'endUsed', prop: 'endUsed',
label: '上限量', label: '上限量',
subcomponent: inputArea, subcomponent: inputArea
}, },
{ {
prop: 'price', prop: 'price',
label: '单价(元)', label: '单价(元)',
subcomponent: inputArea, subcomponent: inputArea
}, }
]; ]
export default { export default {
name: 'energyTypeAdd', name: 'energyTypeAdd',
data() { data() {
@ -217,16 +130,13 @@ export default {
singlePrice: 0, singlePrice: 0,
pricingMethod: 2, pricingMethod: 2,
dim: '', dim: '',
description: '', push: false,
description: ''
}, },
isEdit: false, // isEdit: false, //
rules: { rules: {
name: [ name: [{ required: true, message: '能源类型不能为空', trigger: 'blur' }],
{ required: true, message: '能源类型不能为空', trigger: 'blur' }, pricingMethod: [{ required: true, message: '计价方式不能为空', trigger: 'change' }]
],
pricingMethod: [
{ required: true, message: '计价方式不能为空', trigger: 'change' },
],
}, },
timeKye: 0, timeKye: 0,
usedKye: 0, usedKye: 0,
@ -237,129 +147,130 @@ export default {
tableBtn: [ tableBtn: [
{ {
type: 'delete', type: 'delete',
name: '删除', name: '删除'
}, }
], ],
addButtonShow: '新增', addButtonShow: '新增'
}; }
}, },
methods: { methods: {
init(id) { init(id) {
if (id) { if (id) {
this.isEdit = true; this.isEdit = true
this.form.id = id; this.form.id = id
getEnergyType(id).then((res) => { getEnergyType(id).then((res) => {
if (res.code === 0) { if (res.code === 0) {
this.form.name = res.data.name; this.form.name = res.data.name
this.form.code = res.data.code; this.form.code = res.data.code
this.form.unit = res.data.unit; this.form.unit = res.data.unit
this.form.pricingMethod = res.data.pricingMethod; this.form.pricingMethod = res.data.pricingMethod
this.form.description = res.data.description; this.form.push = res.data.push ? true : false
this.form.description = res.data.description
switch (this.form.pricingMethod) { switch (this.form.pricingMethod) {
case 0: case 0:
this.tableData1 = res.data.segPriceList || []; this.tableData1 = res.data.segPriceList || []
break; break;
case 1: case 1:
this.tableData2 = res.data.usedPriceList || []; this.tableData2 = res.data.usedPriceList || []
this.form.dim = res.data.dim; this.form.dim = res.data.dim
break; break;
default: default:
this.form.singlePrice = res.data.singlePrice || 0; this.form.singlePrice = res.data.singlePrice || 0
} }
} }
}); })
console.log(this.form); console.log(this.form)
} else { } else {
this.isEdit = false; this.isEdit = false
this.form.id = ''; this.form.id = ''
getEnergyTypeCode().then((res) => { getEnergyTypeCode().then((res) => {
this.form.code = res.data; this.form.code = res.data
}); })
} }
}, },
// //
inputChange1(val) { inputChange1(val) {
this.tableData1[val._pageIndex - 1][val.prop] = val[val.prop]; this.tableData1[val._pageIndex - 1][val.prop] = val[val.prop]
if (this.tableData1.length > val._pageIndex && val.prop === 'endTime') { if ((this.tableData1.length > val._pageIndex) && val.prop === 'endTime') {
this.tableData1[val._pageIndex].startTime = val[val.prop]; this.tableData1[val._pageIndex].startTime = val[val.prop]
} }
this.timeKye++; this.timeKye++
}, },
inputChange2(val) { inputChange2(val) {
// //
if (!!val.endUsed && val.endUsed <= val.startUsed) { if (!!val.endUsed && (val.endUsed <= val.startUsed)) {
this.$modal.msgError('上限值不能等于或者小于下限值'); this.$modal.msgError('上限值不能等于或者小于下限值')
return false; return false
} }
this.tableData2[val._pageIndex - 1][val.prop] = val[val.prop]; this.tableData2[val._pageIndex - 1][val.prop] = val[val.prop]
if (this.tableData2.length > val._pageIndex && val.prop === 'endUsed') { if ((this.tableData2.length > val._pageIndex) && val.prop === 'endUsed') {
this.tableData2[val._pageIndex].startUsed = val[val.prop]; this.tableData2[val._pageIndex].startUsed = val[val.prop]
} }
this.usedKye++; this.usedKye++
}, },
// //
emitButtonClick1() { emitButtonClick1() {
let n = this.tableData1.length; let n = this.tableData1.length
let obj = {}; let obj = {}
obj.startTime = n === 0 ? '' : this.tableData1[n - 1].endTime; obj.startTime = n === 0 ? '' : this.tableData1[n - 1].endTime
obj.endTime = ''; obj.endTime = ''
obj.price = 0; obj.price = 0
this.tableData1.push(obj); this.tableData1.push(obj)
}, },
emitButtonClick2() { emitButtonClick2() {
let n = this.tableData2.length; let n = this.tableData2.length
let obj = {}; let obj = {}
obj.startUsed = n === 0 ? 0 : this.tableData2[n - 1].endUsed; obj.startUsed = n === 0 ? 0 : this.tableData2[n - 1].endUsed
obj.endUsed = 0; obj.endUsed = 0
obj.price = 0; obj.price = 0
this.tableData2.push(obj); this.tableData2.push(obj)
}, },
// //
handleClick1(val) { handleClick1(val) {
this.tableData1.splice(val.data._pageIndex - 1, 1); this.tableData1.splice(val.data._pageIndex - 1, 1)
this.timeKye++; this.timeKye++
}, },
handleClick2(val) { handleClick2(val) {
this.tableData2.splice(val.data._pageIndex - 1, 1); this.tableData2.splice(val.data._pageIndex - 1, 1)
this.usedKye++; this.usedKye++
}, },
submitForm() { submitForm() {
this.$refs['form'].validate((valid) => { this.$refs['form'].validate((valid) => {
if (valid) { if (valid) {
switch (this.form.pricingMethod) { switch (this.form.pricingMethod) {
case 0: // case 0://
if (this.tableData1.length === 0) { if (this.tableData1.length === 0) {
this.$modal.msgError('时间段表格数据不能为空'); this.$modal.msgError('时间段表格数据不能为空')
return false; return false
} else { } else {
this.tableData1.map((item) => { this.tableData1.map(item => {
if (item.price <= 0) { if (item.price <= 0) {
this.$modal.msgError('单价有误请检查,请检查'); this.$modal.msgError('单价有误请检查,请检查')
return false; return false
} }
}); })
} }
break; break;
case 1: // 使 case 1:// 使
if (this.tableData2.length === 0) { if (this.tableData2.length === 0) {
this.$modal.msgError('使用量表格数据不能为空'); this.$modal.msgError('使用量表格数据不能为空')
return false; return false
} else { } else {
this.tableData1.map((item) => { this.tableData1.map(item => {
if (item.price <= 0) { if (item.price <= 0) {
this.$modal.msgError('单价有误请检查,请检查'); this.$modal.msgError('单价有误请检查,请检查')
return false; return false
} }
}); })
} }
break; break;
default: // default://
if (!this.form.singlePrice) { if (!this.form.singlePrice) {
this.$modal.msgError('单价有误请检查,请检查'); this.$modal.msgError('单价有误请检查,请检查')
return false; return false
} }
} }
console.log(this.form); console.log(this.form)
if (this.isEdit) { if (this.isEdit) {
// //
updateEnergyType({ updateEnergyType({
@ -370,18 +281,16 @@ export default {
pricingMethod: this.form.pricingMethod, pricingMethod: this.form.pricingMethod,
description: this.form.description, description: this.form.description,
dim: this.form.pricingMethod === 1 ? this.form.dim : '', dim: this.form.pricingMethod === 1 ? this.form.dim : '',
singlePrice: singlePrice: this.form.pricingMethod === 2 ? this.form.singlePrice : '',
this.form.pricingMethod === 2 ? this.form.singlePrice : '', segPriceList: this.form.pricingMethod === 0 ? this.tableData1 : [],
segPriceList: usedPriceList: this.form.pricingMethod === 1 ? this.tableData2 : [],
this.form.pricingMethod === 0 ? this.tableData1 : [], push: this.form.push ? 1 : 0
usedPriceList:
this.form.pricingMethod === 1 ? this.tableData2 : [],
}).then((res) => { }).then((res) => {
if (res.code === 0) { if (res.code === 0) {
this.$modal.msgSuccess('操作成功'); this.$modal.msgSuccess("操作成功");
this.$emit('successSubmit'); this.$emit('successSubmit')
} }
}); })
} else { } else {
createEnergyType({ createEnergyType({
code: this.form.code, code: this.form.code,
@ -390,33 +299,31 @@ export default {
pricingMethod: this.form.pricingMethod, pricingMethod: this.form.pricingMethod,
description: this.form.description, description: this.form.description,
dim: this.form.pricingMethod === 1 ? this.form.dim : '', dim: this.form.pricingMethod === 1 ? this.form.dim : '',
singlePrice: singlePrice: this.form.pricingMethod === 2 ? this.form.singlePrice : '',
this.form.pricingMethod === 2 ? this.form.singlePrice : '', segPriceList: this.form.pricingMethod === 0 ? this.tableData1 : [],
segPriceList: usedPriceList: this.form.pricingMethod === 1 ? this.tableData2 : [],
this.form.pricingMethod === 0 ? this.tableData1 : [], push: this.form.push ? 1 : 0
usedPriceList:
this.form.pricingMethod === 1 ? this.tableData2 : [],
}).then((res) => { }).then((res) => {
if (res.code === 0) { if (res.code === 0) {
this.$modal.msgSuccess('操作成功'); this.$modal.msgSuccess("操作成功");
this.$emit('successSubmit'); this.$emit('successSubmit')
} }
}); })
} }
} else { } else {
return false; return false
} }
}); })
}, },
formClear() { formClear() {
this.$refs.form.resetFields(); this.$refs.form.resetFields()
this.form.singlePrice = 0; this.form.singlePrice = 0
this.isEdit = false; this.isEdit = false
this.timeKye = 0; this.timeKye = 0
this.usedKye = 0; this.usedKye = 0
this.tableData1 = []; this.tableData1 = []
this.tableData2 = []; this.tableData2 = []
}, }
}, }
}; }
</script> </script>

View File

@ -1,191 +1,224 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<search-bar <search-bar
:formConfigs="formConfig" :formConfigs="formConfig"
ref="searchBarForm" ref="searchBarForm"
:removeBlue="true" @headBtnClick="buttonClick"
@headBtnClick="buttonClick" /> />
<!-- 列表 --> <!-- 列表 -->
<base-table <base-table
:page="queryParams.pageNo" :page="queryParams.pageNo"
:limit="queryParams.pageSize" :limit="queryParams.pageSize"
:table-props="tableProps" :table-props="tableProps"
:table-data="list" :table-data="list"
:max-height="tableH"> :max-height="tableH"
>
<method-btn <method-btn
v-if="tableBtn.length" v-if="tableBtn.length"
slot="handleBtn" slot="handleBtn"
:width="80" :width="80"
label="操作" label="操作"
:method-list="tableBtn" :method-list="tableBtn"
@clickBtn="handleClick" /> @clickBtn="handleClick"
/>
</base-table> </base-table>
<pagination
:page.sync="queryParams.pageNo"
:limit.sync="queryParams.pageSize"
:total="total"
@pagination="getList"
/>
<!-- 新增 --> <!-- 新增 -->
<base-dialog <base-dialog
:dialogTitle="addOrEditTitle" :dialogTitle="addOrEditTitle"
:dialogVisible="centervisible" :dialogVisible="centervisible"
@cancel="handleCancel" @cancel="handleCancel"
@confirm="handleConfirm" @confirm="handleConfirm"
:before-close="handleCancel"> :before-close="handleCancel"
<energy-type-add >
ref="energyType" <energy-type-add ref="energyType" @successSubmit="successSubmit" />
@successSubmit="successSubmit" />
</base-dialog> </base-dialog>
</div> </div>
</template> </template>
<script> <script>
import { getEnergyTypePage, deleteEnergyType } from '@/api/base/energyType'; import { getEnergyTypePage, deleteEnergyType } from "@/api/base/energyType";
import { publicFormatter } from '@/utils/dict'; import { publicFormatter } from '@/utils/dict'
import InnerTable from './components/InnerTable'; import InnerTable from './components/InnerTable'
import EnergyTypeAdd from './components/energyTypeAdd'; import EnergyTypeAdd from './components/energyTypeAdd'
const tableProps = [ const tableProps = [
{ {
prop: 'code', prop: 'code',
label: '类型编码', label: '类型编码',
showOverflowtooltip: true, showOverflowtooltip: true,
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'name', prop: 'name',
label: '能源类型', label: '能源类型'
filter: publicFormatter('energy_type'),
}, },
{ {
prop: 'unit', prop: 'unit',
label: '单位', label: '单位',
filter: publicFormatter('unit_dict'), filter: publicFormatter('energy_unit')
}, },
{ {
prop: 'pricingMethod', prop: 'pricingMethod',
label: '计价方式', label: '计价方式'
},
{
prop: 'push',
label: '是否推送',
filter: publicFormatter('push')
}, },
{ {
prop: 'price', prop: 'price',
label: '价格(元)', label: '价格(元)',
subcomponent: InnerTable, subcomponent: InnerTable
}, }
]; ]
export default { export default {
name: 'EnergyType', name: "EnergyType",
components: { EnergyTypeAdd }, components: { EnergyTypeAdd },
data() { data() {
return { return {
formConfig: [ formConfig: [
{
type: 'input',
label: '能源类型',
placeholder: '能源类型',
param: 'name'
},
{
type: 'button',
btnName: '查询',
name: 'search',
color: 'primary'
},
{
type: this.$auth.hasPermi('base:energy-type:create') ? 'separate' : '',
},
{ {
type: this.$auth.hasPermi('base:energy-type:create') ? 'button' : '', type: this.$auth.hasPermi('base:energy-type:create') ? 'button' : '',
btnName: '新增', btnName: '新增',
name: 'add', name: 'add',
color: 'success', color: 'success',
plain: true, plain: true
}, }
], ],
tableProps, tableProps,
tableBtn: [ tableBtn: [
this.$auth.hasPermi('base:energy-type:update') this.$auth.hasPermi('base:energy-type:update')
? { ? {
type: 'edit', type: 'edit',
btnName: '编辑', btnName: '编辑'
} }
: undefined, : undefined,
this.$auth.hasPermi('base:energy-type:delete') this.$auth.hasPermi('base:energy-type:delete')
? { ? {
type: 'delete', type: 'delete',
btnName: '删除', btnName: '删除'
} }
: undefined, : undefined
].filter((v) => v), ].filter((v) => v),
tableH: this.tableHeight(220), tableH: this.tableHeight(260),
pricingMethodList: [ pricingMethodList: [
{ value: 0, label: '分时间段计价' }, {value: 0,label: '分时间段计价'},
{ value: 1, label: '分使用量计价' }, {value: 1,label: '分使用量计价'},
{ value: 2, label: '单一计价' }, {value: 2,label: '单一计价'}
], ],
// //
total: 0, total: 0,
// //
list: [], list: [],
// //
addOrEditTitle: '', addOrEditTitle: "",
// //
centervisible: false, centervisible: false,
// //
queryParams: { queryParams: {
pageNo: 1, pageNo: 1,
pageSize: 100, pageSize: 20,
}, name: null,
code: null
}
}; };
}, },
created() { created() {
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
this.tableH = this.tableHeight(220); this.tableH = this.tableHeight(260)
}); })
this.getList(); this.getList();
}, },
methods: { methods: {
buttonClick() { buttonClick(val) {
this.addOrEditTitle = '新增'; switch (val.btnName) {
this.centervisible = true; case 'search':
this.queryParams.pageNo = 1;
this.queryParams.name = val.name
this.queryParams.code = val.code
this.getList()
break
default:
this.addOrEditTitle = '新增'
this.centervisible = true
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.energyType.init(); this.$refs.energyType.init()
}); })
}
}, },
/** 查询列表 */ /** 查询列表 */
getList() { getList() {
getEnergyTypePage(this.queryParams).then((response) => { getEnergyTypePage(this.queryParams).then(response => {
let arr = response.data.list || []; let arr = response.data.list || [];
arr && arr&&arr.map(item => {
arr.map((item) => { this.pricingMethodList.map(i => {
this.pricingMethodList.map((i) => {
if (item.pricingMethod === i.value) { if (item.pricingMethod === i.value) {
item.pricingMethod = i.label; item.pricingMethod = i.label
} }
}); })
}); })
this.list = arr; this.list = arr
this.total = response.data.total; this.total = response.data.total;
}); });
}, },
handleClick(val) { handleClick(val) {
switch (val.type) { switch (val.type) {
case 'edit': case 'edit':
this.addOrEditTitle = '编辑'; this.addOrEditTitle = '编辑'
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.energyType.init(val.data.id); this.$refs.energyType.init(val.data.id)
}); })
this.centervisible = true; this.centervisible = true
break; break
default: default:
this.handleDelete(val.data); this.handleDelete(val.data)
} }
}, },
handleCancel() { handleCancel() {
this.$refs.energyType.formClear(); this.$refs.energyType.formClear()
this.centervisible = false; this.centervisible = false
this.addOrEditTitle = ''; this.addOrEditTitle = ''
}, },
handleConfirm() { handleConfirm() {
this.$refs.energyType.submitForm(); this.$refs.energyType.submitForm()
}, },
successSubmit() { successSubmit() {
this.handleCancel(); this.handleCancel()
this.getList(); this.getList()
}, },
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
this.$modal this.$modal.confirm('是否确认删除能源类型为"' + row.name + '"的数据项?').then(function() {
.confirm('是否确认删除能源类型为"' + row.name + '"的数据项?')
.then(function () {
return deleteEnergyType(row.id); return deleteEnergyType(row.id);
}) }).then(() => {
.then(() => {
this.queryParams.pageNo = 1; this.queryParams.pageNo = 1;
this.getList(); this.getList();
this.$modal.msgSuccess('删除成功'); this.$modal.msgSuccess("删除成功");
}) }).catch(() => {});
.catch(() => {}); }
}, }
},
}; };
</script> </script>

View File

@ -1,35 +1,22 @@
<template> <template>
<el-form <el-form ref="form" :rules="rules" label-width="110px" :model="form">
ref="form"
:rules="rules"
label-width="110px"
:model="form">
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<el-form-item <el-form-item label="抄表方式" prop="method">
label="抄表方式" <el-select v-model="form.method" placeholder="请选择" style="width: 100%;" @change="changeMethod">
prop="method">
<el-select
v-model="form.method"
placeholder="请选择"
style="width: 100%"
@change="changeMethod">
<el-option <el-option
v-for="item in getDictDatas(DICT_TYPE.METHOD)" v-for="item in getDictDatas(DICT_TYPE.METHOD)"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
:value="item.value"></el-option> :value="item.value">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col <el-col :span="12" v-if='form.method == 1'>
:span="12" <el-form-item label="监控对象" prop="objectId">
v-if="form.method == 1">
<el-form-item
label="监控对象"
prop="objectId">
<el-cascader <el-cascader
style="width: 100%" style='width: 100%;'
v-model="objIds" v-model="objIds"
:options="objList" :options="objList"
:props="{ checkStrictly: true, value: 'id', label: 'name' }" :props="{ checkStrictly: true, value: 'id', label: 'name' }"
@ -38,123 +25,73 @@
clearable></el-cascader> clearable></el-cascader>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col <el-col :span="12" v-if='form.method == 2'>
:span="12" <el-form-item label="水/气表名" prop="tableName">
v-if="form.method == 2"> <el-select v-model="form.tableName" placeholder="请选择" style="width: 100%;">
<el-form-item
label="能源表名"
prop="tableName">
<el-select
v-model="form.tableName"
placeholder="请选择"
style="width: 100%">
<el-option <el-option
v-for="item in getDictDatas(DICT_TYPE.TABLE_NAME)" v-for="item in getDictDatas(DICT_TYPE.TABLE_NAME)"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
:value="item.value"></el-option> :value="item.value">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item <el-form-item label="监控能源类型" prop="energyTypeId">
label="监控能源类型" <el-select v-model="form.energyTypeId" placeholder="请选择" style="width: 100%;" filterable @change="toggleType">
prop="energyTypeId">
<el-select
v-model="form.energyTypeId"
placeholder="请选择"
style="width: 100%"
filterable
@change="toggleType">
<el-option <el-option
v-for="item in this.energyTypeList" v-for="item in this.energyTypeList"
:key="item.id" :key="item.id"
:label="item.name" :label="item.name"
:value="item.id"></el-option> :value="item.id">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col <el-col :span="12" v-if='form.method == 1'>
:span="12" <el-form-item label="监控模式" prop="type">
v-if="form.method == 1"> <el-select v-model="form.type" placeholder="请选择" style="width: 100%;" @change="typeChange">
<el-form-item <el-option label="合并" :value= "1" ></el-option>
label="监控模式" <el-option label="详细" :value= "2" ></el-option>
prop="type">
<el-select
v-model="form.type"
placeholder="请选择"
style="width: 100%"
@change="typeChange">
<el-option
label="合并"
:value="1"></el-option>
<el-option
label="详细"
:value="2"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col <el-col :span="12" v-if='form.method == 1'>
:span="12" <el-form-item label="监控详细参数" prop="type" v-if="form.type === 2">
v-if="form.method == 1"> <el-select v-model="form.plcParamId" placeholder="请选择" style="width: 100%;" @change="selectDetail">
<el-form-item
label="监控详细参数"
prop="type"
v-if="form.type === 2">
<el-select
v-model="form.plcParamId"
placeholder="请选择"
style="width: 100%"
@change="selectDetail">
<el-option <el-option
v-for="item in detailList" v-for="item in detailList"
:key="item.id" :key="item.id"
:label="item.name" :label="item.name"
:value="item.id"></el-option> :value="item.id">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item <el-form-item label="指标类型" prop="limitType">
label="指标类型" <el-select v-model="form.limitType" placeholder="请选择" style="width: 100%;" :disabled='form.method == 2'>
prop="limitType">
<el-select
v-model="form.limitType"
placeholder="请选择"
style="width: 100%"
:disabled="form.method == 2">
<el-option <el-option
v-for="item in getDictDatas(DICT_TYPE.MONITOR_INDEX_TYPE)" v-for="item in getDictDatas(DICT_TYPE.MONITOR_INDEX_TYPE)"
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
:value="item.value"></el-option> :value="item.value">
</el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="消耗量阈值"> <el-form-item label="消耗量阈值">
<el-input-number <el-input-number v-model="form.minValue" placeholder="最小值" :max="9999999" style="width: 50%;"></el-input-number>
v-model="form.minValue" <el-input-number v-model="form.maxValue" placeholder="最大值" :max="9999999" style="width: 50%;"></el-input-number>
placeholder="最小值"
:max="9999999"
style="width: 50%"></el-input-number>
<el-input-number
v-model="form.maxValue"
placeholder="最大值"
:max="9999999"
style="width: 50%"></el-input-number>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
</el-form> </el-form>
</template> </template>
<script> <script>
import { import { getEnergyLimit, updateEnergyLimit, createEnergyLimit, getEnergyParamList } from '@/api/monitoring/energyLimit'
getEnergyLimit,
updateEnergyLimit,
createEnergyLimit,
getEnergyParamList,
} from '@/api/monitoring/energyLimit';
export default { export default {
name: 'energyLimitAdd', name: 'energyLimitAdd',
props: { props: {
@ -162,13 +99,13 @@ export default {
type: Array, type: Array,
required: true, required: true,
default: () => { default: () => {
return []; return []
}, }
}, },
objList: { objList: {
type: Array, type: Array,
default: () => [], default: () => []
}, }
}, },
data() { data() {
return { return {
@ -182,176 +119,161 @@ export default {
plcParamId: '', plcParamId: '',
limitType: '', limitType: '',
minValue: 0, minValue: 0,
maxValue: 0, maxValue: 0
}, },
objIds: [], // objIds: [],//
isEdit: false, // isEdit: false, //
rules: { rules: {
method: [ method: [{ required: true, message: '抄表方式不能为空', trigger: 'change' }],
{ required: true, message: '抄表方式不能为空', trigger: 'change' }, objectId: [{ required: true, message: '监控对象不能为空', trigger: 'change' }],
], energyTypeId: [{ required: true, message: '能源类型不能为空', trigger: 'change' }],
objectId: [ type: [{ required: true, message: '监控模式不能为空', trigger: 'change' }],
{ required: true, message: '监控对象不能为空', trigger: 'change' }, limitType: [{ required: true, message: '指标类型不能为空', trigger: 'change' }]
],
energyTypeId: [
{ required: true, message: '能源类型不能为空', trigger: 'change' },
],
type: [
{ required: true, message: '监控模式不能为空', trigger: 'change' },
],
limitType: [
{ required: true, message: '指标类型不能为空', trigger: 'change' },
],
}, },
detailList: [], detailList: []
}; }
}, },
methods: { methods: {
init(id) { init(id) {
if (id) { if (id) {
this.isEdit = true; this.isEdit = true
this.form.id = id; this.form.id = id
getEnergyLimit(id).then((res) => { getEnergyLimit( id ).then((res) => {
if (res.code === 0) { if (res.code === 0) {
this.form = res.data; this.form = res.data
this.form.plcParamId = res.data.plcParamId || ''; this.form.plcParamId = res.data.plcParamId || ''
this.form.method = this.form.method ? this.form.method + '' : ''; this.form.method = this.form.method ? this.form.method + '' : ''
this.form.limitType = this.form.limitType this.form.limitType = this.form.limitType ? this.form.limitType + '' : ''
? this.form.limitType + '' this.objIds = this.changeDetSelect(this.form.objectId, this.objList)
: '';
this.objIds = this.changeDetSelect(
this.form.objectId,
this.objList
);
if (this.form.type === 2) { if (this.form.type === 2) {
this.getDetailList(); this.getDetailList()
} }
} }
}); })
} else { } else {
this.isEdit = false; this.isEdit = false
this.form.id = ''; this.form.id = ''
} }
}, },
// //
changeMethod() { changeMethod() {
if (this.form.method === '2') { if(this.form.method === '2'){
this.form.limitType = '2'; this.form.limitType = "2"
} else { }else{
this.form.limitType = ''; this.form.limitType = ''
} }
}, },
// //
getDetailList() { getDetailList() {
getEnergyParamList({ getEnergyParamList({
objId: this.form.objectId, objId: this.form.objectId,
energyTypeId: this.form.energyTypeId, energyTypeId: this.form.energyTypeId
}).then((res) => { }).then((res) => {
if (res.code === 0) { if (res.code === 0) {
this.detailList = res.data; this.detailList = res.data
} else { } else {
this.detailList = []; this.detailList = []
} }
}); })
}, },
typeChange(val) { typeChange(val) {
console.log(this.form); console.log(this.form)
this.form.plcParamId = ''; this.form.plcParamId = ''
if (val === 2) { if (val === 2) {
if (this.form.objectId && this.form.energyTypeId) { if (this.form.objectId && this.form.energyTypeId) {
this.getDetailList(); this.getDetailList()
} }
} }
}, },
toggleType() { toggleType() {
if (this.form.energyTypeId && this.form.type) { if (this.form.energyTypeId && this.form.type) {
this.getDetailList(); this.getDetailList()
this.form.plcParamId = ''; this.form.plcParamId = ''
} }
}, },
// //
changeDetSelect(key, treeData) { changeDetSelect(key, treeData) {
let arr = []; // let arr = [] //
let returnArr = []; // let returnArr = [] //
let depth = 0; // let depth = 0 //
// //
function childrenEach(childrendData, depthN) { function childrenEach(childrendData, depthN) {
for (var j = 0; j < childrendData.length; j++) { for (var j = 0; j < childrendData.length; j++) {
depth = depthN; depth = depthN
arr[depthN] = childrendData[j].id; arr[depthN] = childrendData[j].id
if (childrendData[j].id == key) { if (childrendData[j].id == key) {
returnArr = arr.slice(0, depthN + 1); returnArr = arr.slice(0, depthN + 1)
break; break
} else { } else {
if (childrendData[j].children) { if (childrendData[j].children) {
depth++; depth++
childrenEach(childrendData[j].children, depth); childrenEach(childrendData[j].children, depth)
} }
} }
} }
return returnArr; return returnArr
} }
return childrenEach(treeData, depth); return childrenEach(treeData, depth)
}, },
selectObj(val) { selectObj(val) {
this.form.objectId = val[val.length - 1]; this.form.objectId = val[val.length-1]
this.form.objectType = val.length - 1; this.form.objectType = val.length-1
if (this.form.energyTypeId && this.form.type) { if (this.form.energyTypeId && this.form.type) {
this.getDetailList(); this.getDetailList()
this.form.plcParamId = ''; this.form.plcParamId = ''
} }
}, },
selectDetail() { selectDetail() {
this.$forceUpdate(); this.$forceUpdate()
}, },
submitForm() { submitForm() {
this.$refs['form'].validate((valid) => { this.$refs['form'].validate((valid) => {
if (valid) { if (valid) {
if (this.form.type === 2 && !this.form.plcParamId) { if (this.form.type === 2 && !this.form.plcParamId) {
this.$modal.msgError('监控模式为详细时,详细参数为必填'); this.$modal.msgError("监控模式为详细时,详细参数为必填");
return false; return false
} }
if (this.form.minValue && this.form.maxValue) { if (this.form.minValue && this.form.maxValue) {
if (this.form.minValue > this.form.maxValue) { if (this.form.minValue > this.form.maxValue) {
this.$modal.msgError('消耗量阈值,最小值不能大于最大值'); this.$modal.msgError("消耗量阈值,最小值不能大于最大值");
return false; return false
} }
} }
this.form.minValue = this.form.minValue || 0; this.form.minValue = this.form.minValue || 0
this.form.maxValue = this.form.maxValue || 0; this.form.maxValue = this.form.maxValue || 0
if (this.isEdit) { if (this.isEdit) {
// //
updateEnergyLimit({ ...this.form }).then((res) => { updateEnergyLimit({...this.form}).then((res) => {
if (res.code === 0) { if (res.code === 0) {
this.$modal.msgSuccess('操作成功'); this.$modal.msgSuccess("操作成功");
this.$emit('successSubmit'); this.$emit('successSubmit')
} }
}); })
} else { } else {
createEnergyLimit({ ...this.form }).then((res) => { createEnergyLimit({...this.form}).then((res) => {
if (res.code === 0) { if (res.code === 0) {
this.$modal.msgSuccess('操作成功'); this.$modal.msgSuccess("操作成功");
this.$emit('successSubmit'); this.$emit('successSubmit')
} }
}); })
} }
} else { } else {
return false; return false
} }
}); })
}, },
formClear() { formClear() {
this.$refs.form.resetFields(); this.$refs.form.resetFields()
this.form.type = ''; this.form.type = ''
this.form.plcParamId = ''; this.form.plcParamId = ''
this.form.minValue = null; this.form.minValue = null
this.form.maxValue = null; this.form.maxValue = null
this.objIds = ''; this.objIds = ''
this.detailList = []; this.detailList = []
this.isEdit = false; this.isEdit = false
}, }
}, }
}; }
</script> </script>
<style> <style>
.cascaderParent .el-cascader-panel .el-scrollbar:first-child .el-radio { .cascaderParent .el-cascader-panel .el-scrollbar:first-child .el-radio {

View File

@ -1,30 +1,35 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<search-bar <search-bar
:formConfigs="formConfig" :formConfigs="formConfig"
ref="searchBarForm" ref="searchBarForm"
@headBtnClick="buttonClick" /> @headBtnClick="buttonClick"
/>
<!-- 列表 --> <!-- 列表 -->
<base-table <base-table
:page="queryParams.pageNo" :page="queryParams.pageNo"
:limit="queryParams.pageSize" :limit="queryParams.pageSize"
:table-props="tableProps" :table-props="tableProps"
:table-data="list" :table-data="list"
:max-height="tableH"> :max-height="tableH"
>
<method-btn <method-btn
v-if="tableBtn.length" v-if="tableBtn.length"
slot="handleBtn" slot="handleBtn"
:width="80" :width="80"
label="操作" label="操作"
:method-list="tableBtn" :method-list="tableBtn"
@clickBtn="handleClick" /> @clickBtn="handleClick"
/>
</base-table> </base-table>
<pagination <pagination
:page.sync="queryParams.pageNo" :page.sync="queryParams.pageNo"
:limit.sync="queryParams.pageSize" :limit.sync="queryParams.pageSize"
:total="total" :total="total"
@pagination="getList" /> @pagination="getList"
/>
<!-- 新增 --> <!-- 新增 -->
<base-dialog <base-dialog
:dialogTitle="addOrEditTitle" :dialogTitle="addOrEditTitle"
@ -32,70 +37,63 @@
@cancel="handleCancel" @cancel="handleCancel"
@confirm="handleConfirm" @confirm="handleConfirm"
:before-close="handleCancel" :before-close="handleCancel"
width="50%"> width='50%'
<energy-limit-add >
ref="energyLimit" <energy-limit-add ref="energyLimit" @successSubmit="successSubmit" :energyTypeList="energyTypeList" :objList="objList"/>
@successSubmit="successSubmit"
:energyTypeList="energyTypeList"
:objList="objList" />
</base-dialog> </base-dialog>
</div> </div>
</template> </template>
<script> <script>
import { import { getEnergyLimitPage, deleteEnergyLimit } from "@/api/monitoring/energyLimit";
getEnergyLimitPage, import { getEnergyTypeListAll } from "@/api/base/energyType";
deleteEnergyLimit, import { getTree } from '@/api/base/factory'
} from '@/api/monitoring/energyLimit'; import { publicFormatter } from '@/utils/dict'
import { getEnergyTypeListAll } from '@/api/base/energyType'; import EnergyLimitAdd from './components/energyLimitAdd'
import { getTree } from '@/api/base/factory';
import { publicFormatter } from '@/utils/dict';
import EnergyLimitAdd from './components/energyLimitAdd';
const tableProps = [ const tableProps = [
{ {
prop: 'method', prop: 'method',
label: '抄表方式', label: '抄表方式',
filter: publicFormatter('method'), filter: publicFormatter('method')
}, },
{ {
prop: 'objName', prop: 'objName',
label: '监控对象', label: '监控对象'
}, },
{ {
prop: 'objCode', prop: 'objCode',
label: '对象编码', label: '对象编码'
}, },
{ {
prop: 'tableName', prop: 'tableName',
label: '能源表名', label: '水/气表名',
filter: publicFormatter('table_name'), filter: publicFormatter('table_name')
}, },
{ {
prop: 'energyType', prop: 'energyType',
label: '能源类型', label: '能源类型'
filter: publicFormatter('energy_type'),
}, },
{ {
prop: 'type', prop: 'type',
label: '监控模式', label: '监控模式',
filter: (val) => (val != null ? ['合并', '详细'][val - 1] : '-'), filter: (val) => (val != null ? ['合并', '详细'][val-1] : '-'),
}, },
{ {
prop: 'plcParamName', prop: 'plcParamName',
label: '监控参数', label: '监控参数'
}, },
{ {
prop: 'limitType', prop: 'limitType',
label: '指标类型', label: '指标类型',
filter: publicFormatter('monitor_index_type'), filter: publicFormatter('monitor_index_type')
}, },
{ {
prop: 'limitValue', prop: 'limitValue',
label: '阈值', label: '阈值'
}, }
]; ]
export default { export default {
name: 'EnergyLimit', name: "EnergyLimit",
components: { EnergyLimitAdd }, components: { EnergyLimitAdd },
data() { data() {
return { return {
@ -104,7 +102,7 @@ export default {
type: 'select', type: 'select',
label: '能源类型', label: '能源类型',
selectOptions: [], selectOptions: [],
param: 'energyTypeId', param: 'energyTypeId'
}, },
{ {
type: 'select', type: 'select',
@ -112,41 +110,39 @@ export default {
selectOptions: this.getDictDatas(this.DICT_TYPE.MONITOR_INDEX_TYPE), selectOptions: this.getDictDatas(this.DICT_TYPE.MONITOR_INDEX_TYPE),
labelField: 'label', labelField: 'label',
valueField: 'value', valueField: 'value',
param: 'limitType', param: 'limitType'
}, },
{ {
type: 'button', type: 'button',
btnName: '查询', btnName: '查询',
name: 'search', name: 'search',
color: 'primary', color: 'primary'
}, },
{ {
type: 'separate', type: 'separate'
}, },
{ {
type: this.$auth.hasPermi('monitoring:energy-limit:create') type: this.$auth.hasPermi('monitoring:energy-limit:create') ? 'button' : '',
? 'button'
: '',
btnName: '新增', btnName: '新增',
name: 'add', name: 'add',
color: 'success', color: 'success',
plain: true, plain: true
}, }
], ],
tableProps, tableProps,
tableBtn: [ tableBtn: [
this.$auth.hasPermi('monitoring:energy-limit:update') this.$auth.hasPermi('monitoring:energy-limit:update')
? { ? {
type: 'edit', type: 'edit',
btnName: '编辑', btnName: '编辑'
} }
: undefined, : undefined,
this.$auth.hasPermi('monitoring:energy-limit:delete') this.$auth.hasPermi('monitoring:energy-limit:delete')
? { ? {
type: 'delete', type: 'delete',
btnName: '删除', btnName: '删除'
} }
: undefined, : undefined
].filter((v) => v), ].filter((v) => v),
tableH: this.tableHeight(260), tableH: this.tableHeight(260),
// //
@ -154,7 +150,7 @@ export default {
// //
list: [], list: [],
// //
addOrEditTitle: '', addOrEditTitle: "",
// //
centervisible: false, centervisible: false,
// //
@ -162,117 +158,112 @@ export default {
pageNo: 1, pageNo: 1,
pageSize: 20, pageSize: 20,
energyTypeId: null, energyTypeId: null,
limitType: null, limitType: null
}, },
energyTypeList: [], energyTypeList: [],
typeList: [ typeList: [
{ label: '合并', value: '1' }, {label: '合并', value: '1'},
{ label: '详细', value: '2' }, {label: '详细', value: '2'}
], ],
objList: [], objList: []
}; };
}, },
created() { created() {
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
this.tableH = this.tableHeight(260); this.tableH = this.tableHeight(260)
}); })
this.getList(); this.getList();
this.getTypeList(); this.getTypeList()
// //
this.getObjTree(); this.getObjTree()
}, },
methods: { methods: {
getTypeList() { getTypeList() {
getEnergyTypeListAll().then((res) => { getEnergyTypeListAll().then((res) => {
this.formConfig[0].selectOptions = res.data || []; this.formConfig[0].selectOptions = res.data || []
this.energyTypeList = res.data || []; this.energyTypeList = res.data || []
}); })
}, },
buttonClick(val) { buttonClick(val) {
switch (val.btnName) { switch (val.btnName) {
case 'search': case 'search':
this.queryParams.pageNo = 1; this.queryParams.pageNo = 1;
this.queryParams.energyTypeId = val.energyTypeId; this.queryParams.energyTypeId = val.energyTypeId
this.queryParams.limitType = val.limitType; this.queryParams.limitType = val.limitType
this.getList(); this.getList()
break; break
default: default:
this.addOrEditTitle = '新增'; this.addOrEditTitle = '新增'
this.centervisible = true; this.centervisible = true
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.energyLimit.init(); this.$refs.energyLimit.init()
}); })
} }
}, },
/** 查询列表 */ /** 查询列表 */
getList() { getList() {
getEnergyLimitPage(this.queryParams).then((response) => { getEnergyLimitPage(this.queryParams).then(response => {
let arr = response.data.list || []; let arr = response.data.list || [];
arr && arr&&arr.map(item => {
arr.map((item) => { this.typeList.map(i => {
this.typeList.map((i) => {
if (item.type === i.value) { if (item.type === i.value) {
item.type = i.label; item.type = i.label
} }
}); })
if (item.minValue && item.maxValue) { if (item.minValue && item.maxValue) {
item.limitValue = item.minValue + '-' + item.maxValue; item.limitValue = item.minValue + '-' + item.maxValue
} else if (item.minValue) { } else if(item.minValue){
item.limitValue = '最小值' + item.minValue; item.limitValue = '最小值' + item.minValue
} else if (item.maxValue) { }else if(item.maxValue){
item.limitValue = '最大值' + item.maxValue; item.limitValue = '最大值' + item.maxValue
} else { } else {
item.limitValue = ''; item.limitValue = ''
} }
}); })
this.list = arr; this.list = arr
this.total = response.data.total; this.total = response.data.total;
}); });
}, },
handleClick(val) { handleClick(val) {
switch (val.type) { switch (val.type) {
case 'edit': case 'edit':
this.addOrEditTitle = '编辑'; this.addOrEditTitle = '编辑'
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.energyLimit.init(val.data.id); this.$refs.energyLimit.init(val.data.id)
}); })
this.centervisible = true; this.centervisible = true
break; break
default: default:
this.handleDelete(val.data); this.handleDelete(val.data)
} }
}, },
handleCancel() { handleCancel() {
this.$refs.energyLimit.formClear(); this.$refs.energyLimit.formClear()
this.centervisible = false; this.centervisible = false
this.addOrEditTitle = ''; this.addOrEditTitle = ''
}, },
handleConfirm() { handleConfirm() {
this.$refs.energyLimit.submitForm(); this.$refs.energyLimit.submitForm()
}, },
successSubmit() { successSubmit() {
this.handleCancel(); this.handleCancel()
this.getList(); this.getList()
}, },
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
this.$modal this.$modal.confirm('是否确认删除监控对象为"' + row.objName + '"的数据项?').then(function() {
.confirm('是否确认删除监控对象为"' + row.objName + '"的数据项?')
.then(function () {
return deleteEnergyLimit(row.id); return deleteEnergyLimit(row.id);
}) }).then(() => {
.then(() => {
this.queryParams.pageNo = 1; this.queryParams.pageNo = 1;
this.getList(); this.getList();
this.$modal.msgSuccess('删除成功'); this.$modal.msgSuccess("删除成功");
}) }).catch(() => {});
.catch(() => {});
}, },
getObjTree() { getObjTree() {
getTree().then((res) => { getTree().then(res => {
this.objList = res.data || []; this.objList = res.data || []
}); })
}, }
}, }
}; };
</script> </script>