html部分
<template>
<div>
<div class="dialog">
<el-dialog :title="title" :visible.sync="dialogFormVisible" width="600px">
<el-form :model="form" :rules="rules" ref="ruleForm">
<el-form-item>
<el-cascader
v-model="monitorDevice"
:show-all-levels="false"
:options="options"
:props="{ value: 'id', label: 'deviceGroup', multiple: true, checkStrictly: true }"
@change="selectDevice"
filterable>
</el-cascader>
</el-form-item>
</el-form>
</el-dialog>
</div>
</template>
js部分
changeEquiement(e){
this.dialogFormVisible = true
this.title = '修改设备'
e.monitorIds.map(Number).forEach(el => {
let selectMonitorIds = [this.cascadeDisplay(this.options, el)]
this.monitorDevice.push(...selectMonitorIds )
})
},
// 处理级联数据回显
//object为数据源,等于options数据,value为数组项
cascadeDisplay (object, value) {
for (var key in object) {
if (object[key].id == value) return [object[key].id]
if (object[key].children && Object.keys(object[key].children).length > 0) {
var temp = this.cascadeDisplay(object[key].children, value)
if (temp) return [object[key].id, temp].flat()
}
}
},
addEquipment(){
let params = {}
params.id = this.selectId
params.monitorIds = this.monitorIds
addEquipment(params).then(res=>{
if (res.code == 200) {
this.dialogFormVisible = false
this.$message.success('新增成功')
this.getEquipment()
}
})
}