zoukankan      html  css  js  c++  java
  • element 三级复选框

    <template>
        <div>
            
            <div>
            <el-table
              :data="tableData"
              border
              style=" 100%"
              ref="multipleTable"
              >
              <el-table-column
                prop=""
                label="3"
                width="180">
                    <template slot-scope="scope">
                        <el-checkbox :indeterminate="scope.row.first.isIndeterminate" v-model="scope.row.first.checkAll" 
                        @change="handleCheckAllFirstChange(scope.row.first.checkAll,scope)">
                            {{scope.row.first.sheng}}
                        </el-checkbox>
                    </template>    
              </el-table-column>
              <el-table-column
                label="1"
                width="180">
                    <template slot-scope="scope">
                        <el-checkbox :indeterminate="scope.row.second.isIndeterminate" v-model="scope.row.second.checkAll" 
                        @change="handleCheckSecondAllChange(scope.row.second.checkAll,scope)">
                            {{scope.row.second.name}}
                        </el-checkbox>
                    </template>    
              </el-table-column>
              <el-table-column
                label="2"
                width="">
                <template slot-scope="scope">
                    <div>
                        <el-checkbox-group v-model="scope.row.second.checkedCities" 
                        @change="handleCheckedCitiesChange(scope.row.second.checkedCities,scope)">
                              <el-checkbox v-for="city in scope.row.second.date" :label="city" :key="city">
                                {{city}}
                              </el-checkbox>
                        </el-checkbox-group>
                    </div>
                </template>
              </el-table-column>
              <el-table-column
                label="操作">
                <template slot-scope="scope">
                    <el-button @click="aaa(scope)">提交</el-button>
                </template>
              </el-table-column>
            </el-table>
            </div>
            
        </div>
    
        
    </template>
    
    <script>
         const cityOptions = ['上海', '北京', '广州', '深圳'];
          export default {
            data() {
              return {
                checkAll: false,
                checkedCities: ['上海', '北京'],
                cities: cityOptions,
                isIndeterminate: true,
                // ==================================
                tableData: [
                {
                    first:{ sheng:'省', checkAll:false, isIndeterminate: true, },
                    second:{
                        date: ['上海', '北京', '广州', '深圳'],
                        name: '市',
                        address: '上海市普陀区金沙江路 1518 弄',
                        checkedCities:['上海', '北京',],
                        checkAll: false,
                        isIndeterminate: true,
                    }
                },
                {
                  first:{ sheng:'省1', checkAll:false, isIndeterminate: true, },
                  second:{
                    date: ['上海1', '北京1', '广州1', '深圳1'],
                    name: '市1',
                    address: '上海市普陀区金沙江路 1518 弄',
                    checkedCities:[],
                    checkAll: false,
                    isIndeterminate: true,  
                  }
                },
                {
                  first:{ sheng:'省1', checkAll:false, isIndeterminate: true,},
                  second:{
                    date: ['上海2', '北京2', '广州2', '深圳2'],
                    name: '市2',
                    address: '上海市普陀区金沙江路 1518 弄',
                    checkedCities:['北京2', '深圳2'],
                    checkAll: false,
                    isIndeterminate: true,    
                 }
                }],
              }
            },
            created() {
                for(let i=0;i<this.tableData.length;i++){
                    if(this.tableData[i].second.checkedCities.length == 0){
                        this.tableData[i].second.isIndeterminate = false;
                        this.tableData[i].first.isIndeterminate = false;
                    }
                }
            },
            methods: {
                // 一级复选框
              handleCheckAllFirstChange(val,scope) {
                if(val){
                    scope.row.second.checkAll = true;
                    scope.row.second.isIndeterminate = false;
                    scope.row.second.checkedCities = val ?  scope.row.second.date : [];
                }else{
                    scope.row.second.checkAll = false;
                    scope.row.second.checkedCities = val ?  scope.row.second.date : [];
                }            
                scope.row.first.isIndeterminate = false;
              },
              // 二级复选框
              handleCheckSecondAllChange(val,scope) {
                scope.row.first.checkAll = val;
                if(!val){
                    scope.row.first.isIndeterminate = false;
                }else{
                    scope.row.first.checkAll = true;
                    scope.row.first.isIndeterminate = false;
                }
                scope.row.second.checkedCities = val ?  scope.row.second.date : [];
                scope.row.second.isIndeterminate = false;
              },
              // 三级复选框
              handleCheckedCitiesChange(value,scope) {
                let checkedCount = value.length;
                scope.row.first.checkAll = scope.row.second.checkAll = checkedCount === scope.row.second.date.length;
                scope.row.first.isIndeterminate = scope.row.second.isIndeterminate = checkedCount > 0 && checkedCount < scope.row.second.date.length;
              },
              aaa(scope){
                  console.log(scope.row)
                  console.log(scope.row.second.checkedCities)
              }    
            }
          };
    </script>
    
    
    
    <style>
        .haha{
            display: flex;
            
        }
    </style>
            
             
            
  • 相关阅读:
    Entity Framework Core 2.0 新特性
    asp.net core部署时自定义监听端口,提高部署的灵活性
    asp.net core使用jexus部署在linux无法正确 获取远程ip的解决办法
    使用xshell连接服务器,数字键盘无法使用解决办法
    使用Jexus 5.8.2在Centos下部署运行Asp.net core
    【DevOps】DevOps成功的八大炫酷工具
    【Network】Calico, Flannel, Weave and Docker Overlay Network 各种网络模型之间的区别
    【Network】UDP 大包怎么发? MTU怎么设置?
    【Network】高性能 UDP 应该怎么做?
    【Network】golang 容器项目 flannel/UDP相关资料
  • 原文地址:https://www.cnblogs.com/wo1ow1ow1/p/12851285.html
Copyright © 2011-2022 走看看