咏竹莉
where there is a will,there is a way

 

 

<el-checkbox class="selectAll" :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
<el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
   <el-checkbox v-for="item in rooms" :label="item.space_id" :key="item.space_id">{{item.name}}</el-checkbox>
</el-checkbox-group>


<script>
  export default {
    data(){
  return {
 checkAll: false,
             checkedCities: [],
             rooms: [],
             spaceIds: [], // 选择房间id
             isIndeterminate: true
         }
},
    methods: {
 
  handleCheckAllChange(val) {
            let checked = this.rooms.map((item) => {
               return item.space_id;
            });
            this.checkedCities = val ? checked : [];
            this.isIndeterminate = false;
            this.spaceIds = this.checkedCities;
          },
          handleCheckedCitiesChange(value) {
            this.spaceIds = value;
            let checkedCount = value.length;
            this.checkAll = checkedCount === this.rooms.length;
            this.isIndeterminate =
            checkedCount > 0 && checkedCount < this.rooms.length;
         },
      }
  }  

</script>


 

posted on 2022-08-03 10:38  咏竹莉  阅读(259)  评论(0编辑  收藏  举报