直接上代码
<div>
<div class="JuesCheack">
<el-collapse accordion>
<el-collapse-item v-for="(item,index) in newTreeList" :key="index">
<template slot="title">
<el-checkbox-group
v-for="(betun,betunindex) in item.treeResponse" v-model="betun.chenPost" style="width: 150px;margin-right: 30px;"
@change="handleCheckedCitiesChange(betun.name,index,betunindex)">
<el-checkbox >{
{ betun.name }}</el-checkbox>
</el-checkbox-group>
</template>
<div v-for="(be,indexe) in item.treeResponse[0].subList" :key="indexe" class="chenBeks">
<el-checkbox-group v-model="be.chenPost" style="width: 150px;margin-right: 30px;" @change="handleCheckZi(index,indexe,item.cheackList)">
<el-checkbox :label="be.name" >{
{ be.name }}</el-checkbox>
</el-checkbox-group>
<el-checkbox-group v-for="(set,setpodindex) in be.subList" :index="setpodindex" v-model="set.chenPost" @change="leCheckZi(index,indexe,setpodindex)">
<el-checkbox :label="set.id" :key="set.id">{
{ set.name }}</el-checkbox>
</el-checkbox-group>
</div>
</el-collapse-item>
</el-collapse>
</div>
</div>
在data里{
permissions:[]
newTreeList:[]
}
在
methods:{
handleCheckedCitiesChange(cheach, index, index2) {
if (cheach != '全选') {
// 点击案件中心让 被询问人,案件管理,宣教记录选中
if (this.newTreeList[index].treeResponse[index2].chenPost) {
for (let i = 0; i < this.newTreeList[index].treeResponse[index2].subList.length; i++) {
this.newTreeList[index].treeResponse[index2].subList[i].chenPost = true
// 往数组添加选中的id值
this.permissions.push(this.newTreeList[index].treeResponse[index2].subList[i].id)
// 用来全选清楚重复的数据
for (let e = 0; e < this.permissions.length; e++) {
for (let j = e + 1; j < this.permissions.length; j++) {
if (this.permissions[e] === this.permissions[j]) {
this.permissions.splice(j, 1)
}
}
}
console.log(this.permissions)
}
} else {
// 点击取消选中,
for (let i = 0; i < this.newTreeList[index].treeResponse[index2].subList.length; i++) {
this.newTreeList[index].treeResponse[index2].subList[i].chenPost = false
}
// 过滤掉选中的id值
this.permissions = this.permissions.filter(item => !this.newTreeList[index].treeResponse[index2].subList.some(ele => ele.id === item))
console.log(this.permissions)
}
} else {
// 点击和案件中心同级的 全部按钮 控制下列进行全部选择和反选
if (this.newTreeList[index].treeResponse[index2].chenPost) {
for (let i = 0; i < this.newTreeList[index].treeResponse[0].subList.length; i++) {
for (let k = 0; k < this.newTreeList[index].treeResponse[0].subList[i].subList.length; k++) {
if (this.newTreeList[index].treeResponse[0].subList[i].subList[k].name != '全选') {
this.permissions.push(this.newTreeList[index].treeResponse[0].subList[i].subList[k].id)
// 用来全选清楚重复的数据
for (let e = 0; e < this.permissions.length; e++) {
for (let j = e + 1; j < this.permissions.length; j++) {
if (this.permissions[e] === this.permissions[j]) {
this.permissions.splice(j, 1)
}
}
}
console.log(this.permissions)
}
this.newTreeList[index].treeResponse[0].subList[i].subList[k].chenPost = true
}
}
} else {
for (let i = 0; i < this.newTreeList[index].treeResponse[0].subList.length; i++) {
for (let k = 0; k < this.newTreeList[index].treeResponse[0].subList[i].subList.length; k++) {
this.newTreeList[index].treeResponse[0].subList[i].subList[k].chenPost = false
this.permissions = this.permissions.filter(item => !this.newTreeList[index].treeResponse[0].subList[i].subList.some(ele => ele.id ===