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. 织梦自定义表单导出为excel功能

    1.首先在后台修改/dede/templets/diy_main.htm <a href="../plus/diy.php?action=daochu&diyid={dede: ...

  2. scrapy 配置文件指定如何导出数据

    1.导出文件路径 FEED_URI = 'export_data/%(name)s.data' 2.导出数据格式 FEED_FORMAT = 'csv' 3.导出文件编码 FEED_EXPORT_EN ...

  3. Docker报错:“WARNING: IPv4 forwarding is disabled. Networking will not work.”解决。

    问题阐述 一次停电之后,服务器停机,然后ip莫名被占用,修改新的ip之后,ssh能够连接上去,但是web服务访问不了,数据库访问不了,除了22端口,其它服务端口都不能telnet. 防火前.IPtab ...

  4. Vultr CentOS下后台跑node

    在Mac或者Windows下简直易如反掌.几行命令搞定的事情,但因为使用的是远程SSH连接纯命令行处理,所以需要记录下来怎么弄. 比如, 1. 怎么在什么都没有的CentOS里下载Node安装包? 2 ...

  5. SpringBoot 集成mongodb(2)多数据源配置

    github:https://github.com/xiaozhuanfeng/mongoProj 现MongoDB有两个数据库: pom.xml: <!-- mongodb 配置 --> ...

  6. gradle implementation runtimeOnly 和api 区别

    implementation  不对外开发,只是本项目依赖. runtimeOnly 运行时才依赖 api 可以传递依赖,别的项目也可以依赖api的jar包.

  7. git.ZC_命令积累

    1.删除文件 git rm 想要删除的文件的名字及其后缀 git commit -m "对本次提交的描述信息" git push 删除文件夹,执行命令: git rm 想要删除的文 ...

  8. BZOJ 1085(IDA*)

    题面 传送门 分析 首先,直接搜索肯定会TLE 很容易想到用迭代加深的方法,限定搜索深度 但是,这样仍然不够,需要用启发式的方法优化 我们设计一个估价函数f(x)=g(x)+h(x)f(x)=g(x) ...

  9. Lpl and Energy-saving Lamps

    During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Drag ...

  10. 说说 HTTP 和 HTTPS 区别??

    HTTP 协议传输的数据都是未加密的,也就是明文的,因此使用 HTTP 协议传输隐私信息非常不安全,为了保证这些隐私数据能加密传输,于是网景公司设计了 SSL(Secure Sockets Layer ...