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-10-11 14:30:18 +08:00
|
|
|
<el-row>
|
|
|
|
<el-col :span="12">
|
2023-12-05 14:30:32 +08:00
|
|
|
<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'>
|
2023-10-11 14:30:18 +08:00
|
|
|
<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>
|
2023-12-05 14:30:32 +08:00
|
|
|
<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%;">
|
2023-10-11 14:30:18 +08:00
|
|
|
<el-option
|
2023-12-05 14:30:32 +08:00
|
|
|
v-for="item in getDictDatas(DICT_TYPE.TABLE_NAME)"
|
|
|
|
:key="item.value"
|
|
|
|
:label="item.label"
|
|
|
|
:value="item.value">
|
2023-10-11 14:30:18 +08:00
|
|
|
</el-option>
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
|
|
|
</el-col>
|
2023-11-22 16:58:32 +08:00
|
|
|
<el-col :span="12">
|
2023-12-05 14:30:32 +08:00
|
|
|
<el-form-item label="监控能源类型" prop="energyTypeId">
|
|
|
|
<el-select v-model="form.energyTypeId" placeholder="请选择" style="width: 100%;" filterable @change="toggleType">
|
2023-11-22 16:58:32 +08:00
|
|
|
<el-option
|
2023-12-05 14:30:32 +08:00
|
|
|
v-for="item in this.energyTypeList"
|
|
|
|
:key="item.id"
|
|
|
|
:label="item.name"
|
|
|
|
:value="item.id">
|
2023-11-22 16:58:32 +08:00
|
|
|
</el-option>
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
|
|
|
</el-col>
|
2023-12-05 14:30:32 +08:00
|
|
|
<el-col :span="12" v-if='form.method == 1'>
|
2023-10-11 14:30:18 +08:00
|
|
|
<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>
|
2023-12-05 14:30:32 +08:00
|
|
|
<el-col :span="12" v-if='form.method == 1'>
|
2023-10-11 14:30:18 +08:00
|
|
|
<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>
|
2023-12-05 14:30:32 +08:00
|
|
|
<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>
|
2023-10-11 14:30:18 +08:00
|
|
|
</el-row>
|
2023-08-21 11:12:23 +08:00
|
|
|
</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-12-05 14:30:32 +08:00
|
|
|
method: '1',
|
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: '',
|
2023-11-07 15:49:07 +08:00
|
|
|
minValue: null,
|
|
|
|
maxValue: null
|
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-12-05 14:30:32 +08:00
|
|
|
method: [{ required: true, message: '抄表方式不能为空', trigger: 'change' }],
|
|
|
|
objectId: [{ required: true, message: '监控对象不能为空', trigger: 'change' }],
|
2023-08-25 16:27:46 +08:00
|
|
|
energyTypeId: [{ required: true, message: '能源类型不能为空', trigger: 'change' }],
|
2023-11-07 15:49:07 +08:00
|
|
|
type: [{ required: true, message: '监控模式不能为空', trigger: 'change' }],
|
|
|
|
limitType: [{ 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-12-05 14:30:32 +08:00
|
|
|
this.form.method = this.form.method ? this.form.method + '' : ''
|
2023-09-22 11:06:43 +08:00
|
|
|
this.form.limitType = this.form.limitType ? this.form.limitType + '' : ''
|
2023-08-25 16:27:46 +08:00
|
|
|
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-12-05 14:30:32 +08:00
|
|
|
// 切换方式
|
|
|
|
changeMethod() {
|
|
|
|
if(this.form.method === '2'){
|
|
|
|
this.form.limitType = "2"
|
|
|
|
}else{
|
|
|
|
this.form.limitType = ''
|
|
|
|
}
|
|
|
|
},
|
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-11-07 15:49:07 +08:00
|
|
|
if (this.form.minValue && this.form.maxValue) {
|
|
|
|
if (this.form.minValue > this.form.maxValue) {
|
|
|
|
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-11-07 15:49:07 +08:00
|
|
|
this.form.type = ''
|
|
|
|
this.form.plcParamId = ''
|
|
|
|
this.form.minValue = null
|
|
|
|
this.form.maxValue = null
|
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>
|