2023-08-21 11:12:23 +08:00
|
|
|
<template>
|
2023-09-20 16:57:20 +08:00
|
|
|
<el-form ref="form" :rules="rules" label-width="110px" :model="form">
|
2023-08-21 11:12:23 +08:00
|
|
|
<el-form-item label="监控对象" prop="objectId">
|
2023-08-25 16:27:46 +08:00
|
|
|
<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>
|
2023-08-21 11:12:23 +08:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="能源类型" prop="energyTypeId">
|
2023-09-20 16:57:20 +08:00
|
|
|
<el-select v-model="form.energyTypeId" placeholder="请选择" style="width: 100%;" @change="toggleType">
|
2023-08-21 11:12:23 +08:00
|
|
|
<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-form-item label="监控模式" prop="type">
|
|
|
|
<el-select v-model="form.type" placeholder="请选择" style="width: 100%;" @change="typeChange">
|
2023-08-25 16:27:46 +08:00
|
|
|
<el-option label="合并" :value= "1" ></el-option>
|
|
|
|
<el-option label="详细" :value= "2" ></el-option>
|
2023-08-21 11:12:23 +08:00
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
2023-09-20 16:57:20 +08:00
|
|
|
<el-form-item label="监控详细参数" prop="type" v-if="form.type === 2">
|
2023-09-05 15:45:59 +08:00
|
|
|
<el-select v-model="form.plcParamId" placeholder="请选择" style="width: 100%;" @change="selectDetail">
|
2023-08-21 11:12:23 +08:00
|
|
|
<el-option
|
2023-09-05 15:45:59 +08:00
|
|
|
v-for="item in detailList"
|
|
|
|
:key="item.id"
|
|
|
|
:label="item.name"
|
|
|
|
:value="item.id">
|
2023-08-21 11:12:23 +08:00
|
|
|
</el-option>
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
2023-08-25 16:27:46 +08:00
|
|
|
<el-form-item label="指标类型" prop="limitType">
|
|
|
|
<el-select v-model="form.limitType" placeholder="请选择" style="width: 100%;">
|
|
|
|
<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-form-item label="消耗量阈值" prop="limitValue">
|
2023-09-18 14:49:03 +08:00
|
|
|
<el-input-number v-model="form.limitValue" :min="0" :max="10000000000000000" style="width: 100%;"></el-input-number>
|
2023-08-21 11:12:23 +08:00
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
</template>
|
|
|
|
<script>
|
2023-09-05 15:45:59 +08:00
|
|
|
import { getEnergyLimit, updateEnergyLimit, createEnergyLimit, getEnergyParamList } from '@/api/monitoring/energyLimit'
|
2023-08-21 11:12:23 +08:00
|
|
|
export default {
|
|
|
|
name: 'energyLimitAdd',
|
|
|
|
props: {
|
|
|
|
energyTypeList: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
default: () => {
|
|
|
|
return []
|
|
|
|
}
|
2023-08-25 16:27:46 +08:00
|
|
|
},
|
|
|
|
objList: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
2023-08-21 11:12:23 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
form: {
|
|
|
|
id: '',
|
2023-08-25 16:27:46 +08:00
|
|
|
objectId: '',
|
2023-09-05 15:45:59 +08:00
|
|
|
objectType: '',
|
|
|
|
energyTypeId: '',
|
2023-08-25 16:27:46 +08:00
|
|
|
type: '',
|
|
|
|
plcParamId: '',
|
|
|
|
limitType: '',
|
|
|
|
limitValue: ''
|
2023-08-21 11:12:23 +08:00
|
|
|
},
|
2023-08-25 16:27:46 +08:00
|
|
|
objIds: [],// 回显数组
|
2023-08-21 11:12:23 +08:00
|
|
|
isEdit: false, //是否是编辑
|
|
|
|
rules: {
|
2023-08-25 16:27:46 +08:00
|
|
|
objectId: [{ required: true, message: '对象不能为空', trigger: 'change' }],
|
|
|
|
energyTypeId: [{ required: true, message: '能源类型不能为空', trigger: 'change' }],
|
|
|
|
type: [{ required: true, message: '监控模式不能为空', trigger: 'change' }]
|
2023-09-05 15:45:59 +08:00
|
|
|
},
|
|
|
|
detailList: []
|
2023-08-21 11:12:23 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
init(id) {
|
|
|
|
if (id) {
|
|
|
|
this.isEdit = true
|
|
|
|
this.form.id = id
|
2023-08-25 16:27:46 +08:00
|
|
|
getEnergyLimit( id ).then((res) => {
|
2023-08-21 11:12:23 +08:00
|
|
|
if (res.code === 0) {
|
|
|
|
this.form = res.data
|
2023-09-05 15:45:59 +08:00
|
|
|
this.form.plcParamId = res.data.plcParamId || ''
|
2023-08-25 16:27:46 +08:00
|
|
|
this.form.limitType = this.form.limitType + ''
|
|
|
|
this.objIds = this.changeDetSelect(this.form.objectId, this.objList)
|
2023-09-05 15:45:59 +08:00
|
|
|
if (this.form.type === 2) {
|
|
|
|
this.getDetailList()
|
|
|
|
}
|
2023-08-21 11:12:23 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.isEdit = false
|
|
|
|
this.form.id = ''
|
|
|
|
}
|
|
|
|
},
|
2023-09-05 15:45:59 +08:00
|
|
|
// 监控详细参数
|
|
|
|
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)
|
2023-08-25 16:27:46 +08:00
|
|
|
this.form.plcParamId = ''
|
2023-09-05 15:45:59 +08:00
|
|
|
if (val === 2) {
|
2023-09-20 16:57:20 +08:00
|
|
|
if (this.form.objectId && this.form.energyTypeId) {
|
|
|
|
this.getDetailList()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleType() {
|
|
|
|
if (this.form.energyTypeId && this.form.type) {
|
2023-09-05 15:45:59 +08:00
|
|
|
this.getDetailList()
|
2023-09-20 16:57:20 +08:00
|
|
|
this.form.plcParamId = ''
|
2023-09-05 15:45:59 +08:00
|
|
|
}
|
2023-08-25 16:27:46 +08:00
|
|
|
},
|
|
|
|
// 递归处理分类回显问题
|
|
|
|
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
|
2023-09-20 16:57:20 +08:00
|
|
|
if (this.form.energyTypeId && this.form.type) {
|
|
|
|
this.getDetailList()
|
|
|
|
this.form.plcParamId = ''
|
|
|
|
}
|
2023-08-21 11:12:23 +08:00
|
|
|
},
|
2023-09-05 15:45:59 +08:00
|
|
|
selectDetail() {
|
|
|
|
this.$forceUpdate()
|
|
|
|
},
|
2023-08-21 11:12:23 +08:00
|
|
|
submitForm() {
|
|
|
|
this.$refs['form'].validate((valid) => {
|
|
|
|
if (valid) {
|
2023-09-05 15:45:59 +08:00
|
|
|
if (this.form.type === 2 && !this.form.plcParamId) {
|
|
|
|
this.$modal.msgError("监控模式为详细时,详细参数为必填");
|
|
|
|
return false
|
|
|
|
}
|
2023-08-25 16:27:46 +08:00
|
|
|
// this.form.limitType = Number(this.form.limitType)
|
2023-08-21 11:12:23 +08:00
|
|
|
if (this.isEdit) {
|
|
|
|
// 编辑
|
2023-08-25 16:27:46 +08:00
|
|
|
updateEnergyLimit({...this.form}).then((res) => {
|
2023-08-21 11:12:23 +08:00
|
|
|
if (res.code === 0) {
|
|
|
|
this.$modal.msgSuccess("操作成功");
|
|
|
|
this.$emit('successSubmit')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
2023-08-25 16:27:46 +08:00
|
|
|
createEnergyLimit({...this.form}).then((res) => {
|
2023-08-21 11:12:23 +08:00
|
|
|
if (res.code === 0) {
|
|
|
|
this.$modal.msgSuccess("操作成功");
|
|
|
|
this.$emit('successSubmit')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
formClear() {
|
|
|
|
this.$refs.form.resetFields()
|
2023-09-05 15:45:59 +08:00
|
|
|
this.objIds = ''
|
|
|
|
this.detailList = []
|
2023-08-21 11:12:23 +08:00
|
|
|
this.isEdit = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2023-08-25 16:27:46 +08:00
|
|
|
<style>
|
|
|
|
.cascaderParent .el-cascader-panel .el-scrollbar:first-child .el-radio {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
</style>
|