直接上代码
<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 === item))
console.log(this.permissions)
}
}
}
}
},
handleCheckZi(index, index2, item) {
if (this.newTreeList[index].treeResponse[0].subList[index2].chenPost == true) {
// 添加单个点击的选中的id
this.permissions.push(this.newTreeList[index].treeResponse[0].subList[index2].id)
console.log(this.permissions)
} else {
// 过滤单个点击的选中的id
this.permissions = this.permissions.filter(item => (this.newTreeList[index].treeResponse[0].subList[index2].id != item))
console.log(this.permissions)
}
// 点击被询问人,案件管理,宣教记录。让案件中心选中和不选中
for (let e = 0; e < this.newTreeList[index].treeResponse[0].subList.length; e++) {
console.log(this.newTreeList[index].treeResponse[0].subList[e])
if (this.newTreeList[index].treeResponse[0].subList[e].chenPost == false) {
this.newTreeList[index].treeResponse[0].chenPost = false
return
}
this.newTreeList[index].treeResponse[0].chenPost = true
}
},
leCheckZi(index, index2, index3) {
if (this.newTreeList[index].treeResponse[0].subList[index2].subList[index3].name == '全选') {
let butnch = true
for (let v = 0; v < this.newTreeList[index].treeResponse[0].subList.length; v++) {
console.log(this.newTreeList[index].treeResponse[0].subList[v].subList[0])
if (this.newTreeList[index].treeResponse[0].subList[v].subList[0].chenPost == false) {
butnch = false
break
} else {
butnch = true
}
}
this.newTreeList[index].treeResponse[1].chenPost = butnch
if (this.newTreeList[index].treeResponse[0].subList[index2].subList[0].chenPost) {
for (let j = 0; j < this.newTreeList[index].treeResponse[0].subList[index2].subList.length; j++) {
// console.log(this.newTreeList[index].treeResponse[0].subList[index2].subList[j])
if (this.newTreeList[index].treeResponse[0].subList[index2].subList[j].name != '全选') {
this.permissions.push(this.newTreeList[index].treeResponse[0].subList[index2].subList[j].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[index2].subList[j].chenPost = true
}
} else {
for (let j = 0; j < this.newTreeList[index].treeResponse[0].subList[index2].subList.length; j++) {
this.newTreeList[index].treeResponse[0].subList[index2].subList[j].chenPost = false
this.permissions = this.permissions.filter(item => !this.newTreeList[index].treeResponse[0].subList[index2].subList.some(ele => ele.id === item))
console.log(this.permissions)
}
}
} else {
if (this.newTreeList[index].treeResponse[0].subList[index2].subList[index3].chenPost == true) {
this.permissions.push(this.newTreeList[index].treeResponse[0].subList[index2].subList[index3].id)
console.log(this.permissions)
} else {
this.permissions = this.permissions.filter(item => (this.newTreeList[index].treeResponse[0].subList[index2].subList[index3].id != item))
console.log(this.permissions)
}
let chensj = true
for (let a = 0; a < this.newTreeList[index].treeResponse[0].subList[index2].subList.length; a++) {
console.log(this.newTreeList[index].treeResponse[0].subList[index2].subList[a])
if (this.newTreeList[index].treeResponse[0].subList[index2].subList[a].name != '全选') {
if (this.newTreeList[index].treeResponse[0].subList[index2].subList[a].chenPost == false) {
chensj = false
break
} else {
chensj = true
}
}
}
this.newTreeList[index].treeResponse[0].subList[index2].subList[0].chenPost = chensj
}
},
}
数据格式
{
"code":"S000",
"msg":"成功",
"data":{
"list":[
{
"treeResponse":[
{
"id":2,
"name":"案件中心",
"code":"11000000",
"chenPost":false,
"subList":[
{
"id":14,
"name":"被询问人登记",
"code":"11010000",
"chenPost":false,
"subList":[
{
"id":-1,
"name":"全选",
"code":null,
"chenPost":false,
"subList":null
},
{
"id":17,
"name":"新增",
"code":"11010200",
"chenPost":false,
"subList":[
]
},
{
"id":18,
"name":"详情",
"code":"11010300",
"chenPost":false,
"subList":[
]
},
{
"id":19,
"name":"删除",
"code":"11010400",
"chenPost":false,
"subList":[
]
},
{
"id":20,
"name":"编辑",
"code":"11010500",
"chenPost":false,
"subList":[
]
}
]
},
{
"id":26,
"name":"案件管理",
"code":"11020000",
"chenPost":false,
"subList":[
{
"id":-1,
"name":"全选",
"code":null,
"chenPost":false,
"subList":null
},
{
"id":29,
"name":"新增",
"code":"11020200",
"chenPost":false,
"subList":[
]
},
{
"id":30,
"name":"详情",
"code":"11020300",
"chenPost":false,
"subList":[
]
},
{
"id":31,
"name":"删除",
"code":"11020400",
"chenPost":false,
"subList":[
]
}
]
},
{
"id":47,
"name":"宣教记录",
"code":"11030000",
"chenPost":false,
"subList":[
{
"id":-1,
"name":"全选",
"code":null,
"chenPost":false,
"subList":null
},
{
"id":50,
"name":"新增",
"code":"11030200",
"chenPost":false,
"subList":[
]
},
{
"id":51,
"name":"详情",
"code":"11030300",
"chenPost":false,
"subList":[
]
},
{
"id":52,
"name":"删除",
"code":"11030400",
"chenPost":false,
"subList":[
]
},
{
"id":53,
"name":"编辑",
"code":"11030500",
"chenPost":false,
"subList":[
]
}
]
}
]
},
{
"id":null,
"name":"全选",
"code":null,
"chenPost":false,
"subList":null
}
]
},
{
"treeResponse":[
{
"id":3,
"name":"询问中心",
"code":"12000000",
"chenPost":false,
"subList":[
{
"id":126,
"name":"笔录模板制作",
"code":"12010000",
"chenPost":false,
"subList":[
{
"id":-1,
"name":"全选",
"code":null,
"chenPost":false,
"subList":null
},
{
"id":127,
"name":"列表",
"code":"12010100",
"chenPost":false,
"subList":[
]
},
{
"id":128,
"name":"新增",
"code":"12010200",
"chenPost":false,
"subList":[
]
},
{
"id":129,
"name":"删除",
"code":"12010300",
"chenPost":false,
"subList":[
]
},
{
"id":130,
"name":"编辑",
"code":"12010400",
"chenPost":false,
"subList":[
]
}
]
},
{
"id":132,
"name":"权力义务告知书数据",
"code":"12020000",
"chenPost":false,
"subList":[
{
"id":-1,
"name":"全选",
"code":null,
"chenPost":false,
"subList":null
},
{
"id":133,
"name":"列表",
"code":"12020100",
"chenPost":false,
"subList":[
]
},
{
"id":134,
"name":"新增",
"code":"12020200",
"chenPost":false,
"subList":[
]
},
{
"id":135,
"name":"删除",
"code":"12020300",
"chenPost":false,
"subList":[
]
},
{
"id":136,
"name":"编辑",
"code":"12020400",
"chenPost":false,
"subList":[
]
}
]
}
]
},
{
"id":null,
"name":"全选",
"code":null,
"chenPost":false,
"subList":null
}
]
},
{
"treeResponse":[
{
"id":4,
"name":"集体议案",
"code":"13000000",
"chenPost":false,
"subList":[
]
},
{
"id":null,
"name":"全选",
"code":null,
"chenPost":false,
"subList":null
}
]
},
{
"treeResponse":[
{
"id":5,
"name":"听证",
"code":"14000000",
"chenPost":false,
"subList":[
]
},
{
"id":null,
"name":"全选",
"code":null,
"chenPost":false,
"subList":null
}
]
},
{
"treeResponse":[
{
"id":6,
"name":"组织架构",
"code":"15000000",
"chenPost":false,
"subList":[
]
},
{
"id":null,
"name":"全选",
"code":null,
"chenPost":false,
"subList":null
}
]
},
{
"treeResponse":[
{
"id":7,
"name":"装备中心",
"code":"16000000",
"chenPost":false,
"subList":[
]
},
{
"id":null,
"name":"全选",
"code":null,
"chenPost":false,
"subList":null
}
]
},
{
"treeResponse":[
{
"id":8,
"name":"设备管理",
"code":"17000000",
"chenPost":false,
"subList":[
]
},
{
"id":null,
"name":"全选",
"code":null,
"chenPost":false,
"subList":null
}
]
}
]
}
}