projects/mesxc-zjl #301

Merged
juzi merged 2 commits from projects/mesxc-zjl into projects/mesxc-test 2024-04-02 16:56:21 +08:00
20 changed files with 3816 additions and 3422 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.1.49:48082'
# VUE_APP_BASE_API = 'http://192.168.1.8:48082'
# VUE_APP_BASE_API = 'http://192.168.4.159:48080'
VUE_APP_BASE_API = 'http://192.168.4.173: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.78:48082'
# VUE_APP_BASE_API = 'http://192.168.1.47:48082'

View File

@ -35,3 +35,21 @@ export function getQoq(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,3 +68,4 @@ export function exportEnergyTypeExcel(query) {
responseType: 'blob'
})
}

View File

@ -97,6 +97,8 @@ export const DICT_TYPE = {
TABLE_NAME: 'table_name',
METHOD: 'method',
PUSH: 'push',
ENERGY_TYPE: 'energy_type',
// ============== ORDER - 订单模块 =============
ORDER_STATUS: 'order_status',
@ -117,7 +119,7 @@ export const DICT_TYPE = {
// ============== GROUP - 班组模块 =============
WORK_SHOP: 'workshop',
// ============== GROUP - 质量模块 =============
// ============== GROUP - 质量模块 =============
MATERIAL_GRADE: 'material_grade'
}

View File

@ -1,148 +1,149 @@
<template>
<div
id="analysischartBar"
style="width: 100%"
:style="{ height: chartHeight + 'px' }"
></div>
<div
id="analysischartBar"
style="width: 100%"
:style="{ height: chartHeight + 'px' }"></div>
</template>
<script>
import * as echarts from 'echarts'
import resize from '@/utils/chartMixins/resize'
import * as echarts from 'echarts';
import resize from '@/utils/chartMixins/resize';
export default {
name: "BarChart",
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('analysischartBar')
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: 'bar',
barMaxWidth: 20,
label: {
show: true,
position: 'top'
},
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: 'shadow'
},
formatter: function(params) {
return (
params[0].axisValue +
`<br>` +
params.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 seriesNameStr = `<span style="display:inline-block;">${item.seriesName}</span>`
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>`
return `<span style="display:flex; justify-content:space-between; margin-bottom: 2px">
name: 'BarChart',
mixins: [resize],
data() {
return {
chartDom: '',
chart: '',
chartHeight: this.tableHeight(250) / 2,
};
},
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(250) / 2;
});
},
methods: {
getChart() {
if (
this.chart !== null &&
this.chart !== '' &&
this.chart !== undefined
) {
this.chart.dispose(); // Dom
}
this.chartDom = document.getElementById('analysischartBar');
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: 'bar',
barMaxWidth: 20,
label: {
show: true,
position: 'top',
},
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);
}
var option = {
color: ['#FFDC94', '#8EF0AB', '#63BDFF', '#288AFF', '#7164FF'],
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
formatter: function (params) {
return (
params[0].axisValue +
`<br>` +
params
.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 seriesNameStr = `<span style="display:inline-block;">${item.seriesName}</span>`;
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>`;
return `<span style="display:flex; justify-content:space-between; margin-bottom: 2px">
<span>${str}${seriesNameStr}</span>
<span>${valueStr}</span>
</span>`
}).join(``)
)
}
},
grid: {
left: '4%',
right: '1%',
bottom: '1%',
containLabel: true
},
legend: {
data: legendData,
right: '1%',
icon: 'rect',
itemHeight: 8,
itemWidth: 8
},
xAxis: {
type: 'category',
data: xData,
axisLabel: {
rotate: "45"
}
},
yAxis: {
type: 'value'
},
series: yData
};
</span>`;
})
.join(``)
);
},
},
grid: {
left: '4%',
right: '1%',
bottom: '1%',
containLabel: true,
},
legend: {
data: legendData,
right: '1%',
icon: 'rect',
itemHeight: 8,
itemWidth: 8,
},
xAxis: {
type: 'category',
data: xData,
axisLabel: {
rotate: '45',
},
},
yAxis: {
type: 'value',
},
series: yData,
};
option && this.chart.setOption(option);
}
}
}
option && this.chart.setOption(option);
},
},
};
</script>

View File

@ -1,126 +0,0 @@
<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,96 +1,129 @@
<template>
<div class="app-container contrastAnalysisBox" id="contrastAnalysisBox">
<!-- 搜索工作栏 -->
<search-area :isFold="isFold" @submit="getList"/>
<el-tabs v-model="activeName" @tab-click="switchChart" v-show='chartData.length'>
<el-tab-pane label="柱状图" name="bar">
<bar-chart ref="analysisBarChart" :chartData="chartData" :timeDim="timeDim" />
</el-tab-pane>
<el-tab-pane label="折线图" name="line">
<line-chart ref="analysisLineChart" :chartData="chartData" :timeDim="timeDim"/>
</el-tab-pane>
</el-tabs>
<!-- 没有数据 -->
<div class="no-data-bg" v-show='!chartData.length'></div>
</div>
<div
class="app-container contrastAnalysisBox"
id="contrastAnalysisBox">
<!-- 搜索工作栏 -->
<search-area
:isFold="isFold"
@submit="getList"
@export="exportExl" />
<div v-show="chartData.length">
<bar-chart
ref="analysisBarChart"
:chartData="chartData"
:timeDim="timeDim" />
<base-table
:table-props="tableProps"
:table-data="list"
:max-height="tableH"
class="contrast-out-table" />
</div>
<!-- 没有数据 -->
<div
class="no-data-bg"
v-show="!chartData.length"></div>
</div>
</template>
<script>
import { getCompare } from "@/api/analysis/energyAnalysis"
import SearchArea from "./components/searchArea"
import BarChart from "./components/barChart"
import LineChart from "./components/lineChart"
import { getCompare } from '@/api/analysis/energyAnalysis';
import SearchArea from './components/searchArea';
import BarChart from './components/barChart';
import tableHeightMixin from '@/mixins/lb/tableHeightMixin';
import FileSaver from 'file-saver';
import * as XLSX from 'xlsx/xlsx.mjs';
// import moment from 'moment'
export default {
name: 'ContrastAnalysis',
components: { SearchArea, BarChart, LineChart },
data() {
return {
isFold: false,
activeName: 'bar',
chartData: [],
timeDim: ''
}
},
mounted() {
window.addEventListener('resize', () => {
this.tableH = this.tableHeight(260)
this.isFold = this.searchBarWidth('contrastAnalysisBox', 1437)
// console.log(document.getElementById("contrastAnalysisBox").offsetWidth)
})
this.isFold = this.searchBarWidth('contrastAnalysisBox', 1437)
},
methods: {
getList(params) {
this.timeDim = params.timeDim
getCompare({ ...params }).then((res) => {
console.log(res)
if (res.code === 0) {
this.chartData = res.data || []
} else {
this.chartData = []
}
})
},
switchChart() {
if (this.activeName === 'bar') {
this.$nextTick((res) => {
this.$refs.analysisBarChart.getChart()
})
} else {
this.$nextTick((res) => {
this.$refs.analysisLineChart.getChart()
})
}
}
}
}
name: 'ContrastAnalysis',
components: { SearchArea, BarChart },
mixins: [tableHeightMixin],
data() {
return {
isFold: false,
chartData: [],
timeDim: '',
tableProps: [],
list: [],
tableH: this.tableHeight(250) / 2,
};
},
mounted() {
window.addEventListener('resize', () => {
this.isFold = this.searchBarWidth('contrastAnalysisBox', 1437);
// console.log(document.getElementById("contrastAnalysisBox").offsetWidth)
});
this.isFold = this.searchBarWidth('contrastAnalysisBox', 1437);
},
methods: {
_setTableHeight() {
this.tableH = this.tableHeight(250) / 2;
},
getList(params) {
this.timeDim = params.timeDim;
getCompare({ ...params }).then((res) => {
if (res.code === 0) {
this.getTableList(res.data || []);
this.chartData = res.data || [];
} else {
this.chartData = [];
}
});
},
getTableList(arr) {
this.tableProps = [];
this.list = [];
let tempX = [];
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 {
this.$modal.msgWarning('暂无数据导出');
}
},
},
};
</script>
<style lang='scss'>
.contrastAnalysisBox {
.el-tabs__nav::after {
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);
}
.contrast-out-table {
margin-top: 20px;
}
}
</style>

View File

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

View File

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

View File

@ -1,103 +1,102 @@
<template>
<div
id="analysischartLine"
style="width: 100%"
:style="{ height: chartHeight + 'px' }"
></div>
<div
id="analysischartLine"
style="width: 100%"
:style="{ height: chartHeight + 'px' }"></div>
</template>
<script>
import * as echarts from 'echarts'
import resize from '@/utils/chartMixins/resize'
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 xData = []
let yData = []
for (let i = 0; i < this.chartData.length; i++) {
let time = ""
if (this.timeDim === '3') {
let year = this.chartData[i].time.slice(0,4)
let weak = this.chartData[i].time.slice(4,6)
time = year+' 第 '+weak+' 周'
} else {
time = this.chartData[i].time
}
xData.push(time)
yData.push(this.chartData[i].useNum)
}
name: 'LineChart',
mixins: [resize],
data() {
return {
chartDom: '',
chart: '',
chartHeight: this.tableHeight(214) - 100,
};
},
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 xData = [];
let yData = [];
for (let i = 0; i < this.chartData.length; i++) {
let time = '';
if (this.timeDim === '3') {
let year = this.chartData[i].time.slice(0, 4);
let weak = this.chartData[i].time.slice(4, 6);
time = year + ' 第 ' + weak + ' 周';
} else {
time = this.chartData[i].time;
}
xData.push(time);
yData.push(this.chartData[i].useNum);
}
var option = {
color:['#288AFF'],
// tooltip: {
// trigger: 'axis'
// },
grid: {
left: '4%',
right: '1%',
bottom: '1%',
containLabel: true
},
xAxis: {
type: 'category',
data: xData,
axisLabel: {
rotate: "45"
}
},
yAxis: {
type: 'value'
},
series: [
{
data: yData,
type: 'line'
}
]
};
var option = {
color: ['#288AFF'],
// tooltip: {
// trigger: 'axis'
// },
grid: {
left: '4%',
right: '1%',
bottom: '1%',
containLabel: true,
},
xAxis: {
type: 'category',
data: xData,
axisLabel: {
rotate: '45',
},
},
yAxis: {
type: 'value',
},
series: [
{
data: yData,
type: 'line',
},
],
};
option && this.chart.setOption(option);
}
}
}
option && this.chart.setOption(option);
},
},
};
</script>

View File

@ -1,94 +1,113 @@
<template>
<div class="app-container trendAnalysisBox" id="trendAnalysisBox">
<!-- 搜索工作栏 -->
<search-area :isFold="isFold" @submit="getList"/>
<el-tabs v-model="activeName" @tab-click="switchChart" v-show='chartData.length'>
<el-tab-pane label="柱状图" name="bar">
<bar-chart ref="analysisBarChart" :chartData="chartData" :timeDim="timeDim"/>
</el-tab-pane>
<el-tab-pane label="折线图" name="line">
<line-chart ref="analysisLineChart" :chartData="chartData" :timeDim="timeDim"/>
</el-tab-pane>
</el-tabs>
<!-- 没有数据 -->
<div class="no-data-bg" v-show='!chartData.length'></div>
</div>
<div
class="app-container trendAnalysisBox"
id="trendAnalysisBox">
<!-- 搜索工作栏 -->
<search-area
:isFold="isFold"
@submit="getList"
@export="exportExl" />
<div v-show="chartData.length">
<base-table
:table-props="tableProps"
:table-data="list"
class="trend-out-table" />
<line-chart
ref="analysisLineChart"
:chartData="chartData"
:timeDim="timeDim" />
</div>
<!-- 没有数据 -->
<div
class="no-data-bg"
v-show="!chartData.length"></div>
</div>
</template>
<script>
import { getEnergyTrend } from "@/api/analysis/energyAnalysis"
import SearchArea from "./components/searchArea"
import BarChart from "./components/barChart"
import LineChart from "./components/lineChart"
import { getEnergyTrend, exportTrend } from '@/api/analysis/energyAnalysis';
import SearchArea from './components/searchArea';
import LineChart from './components/lineChart';
// import moment from 'moment'
export default {
name: 'TrendAnalysis',
components: { SearchArea, BarChart, LineChart },
data() {
return {
isFold: false,
activeName: 'bar',
chartData: [],
timeDim: ''
}
},
mounted() {
window.addEventListener('resize', () => {
this.tableH = this.tableHeight(260)
this.isFold = this.searchBarWidth('trendAnalysisBox', 1263)
})
this.isFold = this.searchBarWidth('trendAnalysisBox', 1263)
},
methods: {
getList(params) {
this.timeDim = params.timeDim
getEnergyTrend({ ...params }).then((res) => {
if (res.code === 0) {
this.chartData = res.data
} else {
this.chartData = []
}
})
},
switchChart() {
if (this.activeName === 'bar') {
this.$nextTick((res) => {
this.$refs.analysisBarChart.getChart()
})
} else {
this.$nextTick((res) => {
this.$refs.analysisLineChart.getChart()
})
}
}
}
}
name: 'TrendAnalysis',
components: { SearchArea, LineChart },
data() {
return {
isFold: false,
chartData: [],
timeDim: '',
tableProps: [],
list: [],
};
},
mounted() {
window.addEventListener('resize', () => {
this.tableH = this.tableHeight(260);
this.isFold = this.searchBarWidth('trendAnalysisBox', 1480);
});
this.isFold = this.searchBarWidth('trendAnalysisBox', 1480);
},
methods: {
getList(params) {
this.timeDim = params.timeDim;
getEnergyTrend({ ...params }).then((res) => {
if (res.code === 0) {
this.getTableList(res.data || []);
this.chartData = res.data || [];
} else {
this.chartData = [];
}
});
},
getTableList(arr) {
this.tableProps = [];
this.list = [];
let tempX = [];
let listObj = { useNum: '消耗量' }; //
for (let i = 0; i < arr.length; i++) {
let obj = {};
obj.prop = arr[i].time;
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>
<style lang='scss'>
.trendAnalysisBox {
.el-tabs__nav::after {
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);
}
.trend-out-table {
margin-bottom: 15px;
}
}
</style>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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