data里面定义了

data:[],
        actionids:[],//选择的那个actionid
        num1:0,//没选择的计数
        num2:0,//选中的计数
        checkAllBig: [],
        checkAll:[],
        checkOne:[],
 获取所有数据:

this.data=res.data;
                     for(var i=0;i<this.data.length;i++){//遍历选择的内容
                         if(this.data[i].ischecked==1){
                                 this.checkAllBig.push(this.data[i].affairtypeid)
                             }
                         for(var j=0;j<this.data[i].eventtype.length;j++){
                             if(this.data[i].eventtype[j].ischecked==1){
                                 this.checkAll.push(this.data[i].eventtype[j].eventtypeid)
                             }
                             for(var k=0;k<this.data[i].eventtype[j].operation.length;k++){
                                 if(this.data[i].eventtype[j].operation[k].ischecked==1){
                                 this.checkOne.push(this.data[i].eventtype[j].operation[k].actionid);}
                             }
                         }
                     }

<div class="checkbox-table" v-for="(item,indexkey) in data">
                            <template>
        <el-checkbox  class="check1" v-model="checkAllBig"  :label="item.affairtypeid" @change="handleCheckedCitiesChange(1,indexkey)">{{item.affairtypename}}{{item.ischecked}}</el-checkbox>
                                 
                                 <div v-for="(list,index2) in item.eventtype" class="line-check" :key="list.eventtypeid">
                                      <el-checkbox   class="check2" @change="handleCheckedCitiesChange(2,indexkey,index2)"  v-model="checkAll" :label="list.eventtypeid"  v-bind:style="{ 'float':list.operation.length>0?'left':'none'}">{{list.eventtypename}}{{list.ischecked}}</el-checkbox>
                                      <el-checkbox-group v-model="checkOne" class="checkGroup" >
                                        <el-checkbox  v-for="(operate,index1) in list.operation" :label="operate.actionid"   :key="operate.actionid"  @change="handleCheckedCitiesChange(3,indexkey,index2,index1)">{{operate.actionname}}{{operate.ischecked}}</el-checkbox>
                                      </el-checkbox-group>
                                  </div>
                            </template>
                            </div>

handleCheckedCitiesChange(type,a=0,b=0,c=0) {//多选框
if(type==1){//最高级全选
this.actionids=[];
if(this.data[a].ischecked==1){
this.data[a].ischecked=0;
for(var i=0;i<this.data[a].eventtype.length;i++){
this.checkAll=this.checkAll.map(res=>{
if(res!=this.data[a].eventtype[i].eventtypeid){return res}
});
for(var j=0;j<this.data[a].eventtype[i].operation.length;j++){
this.checkOne=this.checkOne.map(res=>{
if(res!=this.data[a].eventtype[i].operation[j].actionid){return res;}
});
}
}
}else{
this.data[a].ischecked=1;
for(var i=0;i<this.data[a].eventtype.length;i++){
this.checkAll.push(this.data[a].eventtype[i].eventtypeid);
for(var j=0;j<this.data[a].eventtype[i].operation.length;j++){
this.checkOne.push(this.data[a].eventtype[i].operation[j].actionid);
this.actionids.push(this.data[a].eventtype[i].operation[j].actionid)
}
}

}

this.api(this.data[a].ischecked);//调用接口把选择的传过去

}else if(type ==2){//第二级全选
this.actionids=[];
this.data[a].eventtype[b].ischecked=this.data[a].eventtype[b].ischecked==1?0:1;

for(var i=0;i<this.data[a].eventtype[b].operation.length;i++){
if(this.data[a].eventtype[b].ischecked==1){
this.checkOne.push(this.data[a].eventtype[b].operation[i].actionid);
this.$set(this.data[a].eventtype[b].operation[i],"ischecked",1);
} else{
this.$set( this.data[a].eventtype[b].operation[i],"ischecked",0);
this.checkOne=this.checkOne.map(res=>{
if( res!=this.data[a].eventtype[b].operation[i].actionid){return res;}
})
}

this.actionids.push(this.data[a].eventtype[b].operation[i].actionid);

}

this.api(this.data[a].eventtype[b].ischecked);

}else{//单选
var num1=0;
var num2=0;
var len=this.data[a].eventtype[b].operation.length;//单选框长度

this.data[a].eventtype[b].operation[c].ischecked=this.data[a].eventtype[b].operation[c].ischecked==1?0:1;
for(var i=0;i<len;i++){
if(this.data[a].eventtype[b].operation[i].ischecked==1){
num2++;//选中计数
}
else{
num1++;//没选计数
}
}

if(num1==len){
this.checkAll=this.checkAll.map(res=>{
if(res!=this.data[a].eventtype[b].eventtypeid){return res;}
});
this.data[a].eventtype[b].ischecked=0;
}
if(num2==len){
this.checkAll.push(this.data[a].eventtype[b].eventtypeid)
this.data[a].eventtype[b].ischecked=1;
this.$set(this.data[a].eventtype[b],"ischecked",1);
}

this.actionids=this.data[a].eventtype[b].operation[c].actionid;

this.api(this.data[a].eventtype[b].operation[c].ischecked)
}

api(ischecked){//权限选择接口
let para={
roleid:this.roleid,
ischecked:ischecked,
actionid:this.actionids.toString(),
}
addRolePower(para).then((res)=>{//取消权限
this.$notify({
message:res.msg,
type: 'success'
});
})
},

引用自夏天想

element-ui 里面el-checkbox多选框,实现全选单选的更多相关文章

  1. js做全选,用一个checkbox复选框做多个checkbox复选框的全选按钮,有一个复选框未被选择时,全选按钮的checked就为false

    用一个checkbox复选框做多个checkbox复选框的全选按钮,有一个复选框未被选择时,全选按钮的checked就为false,当所有checkbox都被选中时,全选按钮也被选中. 详解: 有两种 ...

  2. Vue复选框的全选

    <!DOCTYPE html><html>    <head>        <meta charset="utf-8">      ...

  3. js实现复选框的全选、全不选、反选

    js中实现复选框的全选,全不选以及反选,分为两种情况: (1)选中“请选择”前面的复选框实现全选,不选中“请选择”前面的复选框实现全不选 <!DOCTYPE html PUBLIC " ...

  4. JQ实现复选框的全选反选不选

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 【jQuery】复选框的全选、反选,推断哪些复选框被选中

    本文与<[JavaScript]复选框的全选.反选.推断哪些复选框被选中>(点击打开链接)为姊妹篇,把里面内容再与jQuery框架中实现一次,相同做到例如以下的效果: 布局还是相同的布局, ...

  6. js实现复选框的全选、全不选和反选

    js实现复选框的全选.全不选和反选 主要是用遍历的方法查找元素,然后通过改变checked的属性来选择,为true则是选中状态,为false则是未选状态 实现代码 <!DOCTYPE html& ...

  7. 【JavaScript】实现复选框的全选、全部不选、反选

    以较为简洁的程序实现复选框的全选.全部不选.反选 操作. 并且将可变的部分设置为JS的参数,以实现代码复用. 全选和全不选 第一个参数为复选框名称,第二个参数为是全选还是全部不选. function ...

  8. 一天搞定jQuery(三)——使用jQuery完成复选框的全选和全不选

    还记得之前我使用JavaScript来实现复选框的全选和全不选效果吗?如果读者初次翻阅本文,可记得看看教你一天玩转JavaScript(七)——使用JavaScript完成复选框的全选和全不选的效果! ...

  9. jQuery学习(五)——使用JQ完成复选框的全选和全不选

    1.在系统后台进行人员管理时,进行批量删除,使用jq完成全选和全不选 步骤分析: 第一步:引入jquery文件 第二步:书写页面加载函数 第三步:为上面的复选框绑定单击事件 第四步:将下面所有的复选框 ...

  10. jQuery实现复选框的全选、反选、并且根据复选框的<checked属性>控制多个对应div的显示/隐藏

    <!doctype html><html> <head> <meta charset="utf-8"> <title>j ...

随机推荐

  1. MySQL的性能指标计算和优化方法

    MySQL的性能指标计算和优化方法1 QPS计算(每秒查询数) 针对MyISAM引擎为主的DB mysql> show global status like 'questions';+----- ...

  2. AtomicBoolean 源码分析

    AtomicBoolean AtomicBoolean 能解决什么问题?什么时候使用 AtomicBoolean? 可原子更新的 boolean 值 1)原子性:在Java中,对基本数据类型变量的读取 ...

  3. @TableLogic表逻辑处理注解(逻辑删除)

    在字段上加上这个注解再执行BaseMapper的删除方法时,删除方法会变成修改 例: 实体类:    @TableLogic private Integer del;   service层: 调用Ba ...

  4. mac, ios 模拟器

    genymotion  最好的android 硬件模拟器. 可多开,可gps定位,可模拟重力系统,可模拟磁场系统,模拟器海拔高度. 甚至可以模拟sd卡. 直接就等于真机. virtualbox 最好的 ...

  5. [转载]OpenSSL身份认证 RSA、ECC、SM2

    一.生成证书openSSL生成RSA证书1 生成自签CA 生成CA密钥genrsa -aes256 -passout pass:123456 -out ca_rsa_private.pem 20481 ...

  6. 您配置文件中的设置 (空密码的 root) 与 MySQL 默认管理员账户对应...的解决办法

    您配置文件中的设置 (空密码的 root) 与 MySQL 默认管理员账户对应.……解决办法很简单:1.修改root@localhost权限的密码. 打开wamp的phpmyadmin,进入它的管理界 ...

  7. 【ABAP系列】SAP ABAP 优化LOOP循环的一点点建议

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 优化LOOP循 ...

  8. pyAudioAnalysis-audioFeatureExtraction 错误纠正

    1. TypeError: mfccInitFilterBanks() takes 2 positional arguments but 7 were given The issue In the f ...

  9. .net日志的用法

    public class Logs { private static Logger logger = LogManager.GetCurrentClassLogger(); //初始化日志类 /// ...

  10. win

    /*-------------------------------------------------------------- HelloMsg.c -- Displays "Hello, ...