修改checkbox(复选框)默认的样式/复选框的全选全不选

修改 checkbox(复选框) 默认的颜色

https://blog.csdn.net/weixin_44037153/article/details/107405594

复选框的全选全不选(单级)

https://www.cnblogs.com/sgs123/p/10436516.html

复选框的全选全不选(多层级)

效果图

请添加图片描述

代码

<template>
  <div class="deliverySetting">
    <div class="deliverySetting-table">
      <div class="table-body" v-for="(item,index) in distable" :key="index">
        <div class="selection">
          <p>
            <el-checkbox
              v-model="item.selected"
              @change="handcheck(index,item.itemId,$event)"
              :key="index"
            ></el-checkbox>
          </p>
        </div>
        <div class="width185">
          <p>{
    
    {
    
     item.itemName }}</p>
        </div>
        <div class="width265">
          <el-checkbox
            v-for="country in item.country"
            v-model="country.selected"
            @change="handcheckall(index,country.id,item.itemId,$event)"
            :key="country.id"
          >{
    
    {
    
    country.file}}</el-checkbox>
        </div>
        <div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
    
    
  name: "deliverySetting",
  components: {
    
    },
  props: {
    
    },
  data() {
    
    
    return {
    
    
      distable: [
        {
    
    
          itemName: "1区",
          selected: false,
          itemId: 1,
          country: [
            {
    
     id: "1", file: "奥地利", selected: false },
            {
    
     id: "2", file: "芬兰", selected: false },
            {
    
     id: "3", file: "意大利", selected: false },
            {
    
     id: "4", file: "葡萄牙", selected: false },
            {
    
     id: "9", file: "西班牙", selected: false },
            {
    
     id: "10", file: "瑞典", selected: false }
          ]
        },
        {
    
    
          itemName: "2区",
          selected: false,
          itemId: 2,
          country: [
            {
    
     id: "5", file: "丹麦", selected: false },
            {
    
     id: "6", file: "法国", selected: false }
          ]
        },
        {
    
    
          itemName: "3区",
          selected: false,
          itemId: 3,
          country: [
            {
    
     id: "7", file: "德国", selected: false },
            {
    
     id: "8", file: "瑞士", selected: false }
          ]
        }
      ]
    };
  },
  methods: {
    
    
    handcheck(index, topId, e) {
    
    
      //内部check
      this.distable[index].selected = e; //二级勾选后,子级全部勾选或者取消
      var childname = this.distable[index].country;
      if (childname)
        for (var i = 0, len = childname.length; i < len; i++)
          childname[i].selected = e;
    },
    handcheckall(index1, sonId, topId, e) {
    
    
      //外部check
      var childname = this.distable[index1].country;
      var tickCount = 0,
        unTickCount = 0,
        len = childname.length;
      for (var i = 0; i < len; i++) {
    
    
        if (sonId == childname[i].id) childname[i].selected = e;
        if (childname[i].selected == true) tickCount++;
        if (childname[i].selected == false) unTickCount++;
      }
      if (tickCount == len) {
    
    
        //三级级全勾选
        this.distable[index1].selected = true;
      } else if (unTickCount == len) {
    
    
        //三级级全不勾选
        this.distable[index1].selected = false;
      } else {
    
    
        this.distable[index1].selected = false;
      }
    }
  }
};
</script>
<style lang="scss">
.deliverySetting {
    
    
  padding: 20px 0;
  position: relative;
  .el-table {
    
    
    thead {
    
    
      tr {
    
    
        th {
    
    
          font-size: 14px;
        }
      }
    }
    tbody {
    
    
      tr {
    
    
        td {
    
    
          vertical-align: baseline;
          p {
    
    
            line-height: 30px;
          }
          .el-checkbox-group {
    
    
            display: flex;
            flex-direction: column;
            label {
    
    
              line-height: 30px;
              margin-left: 0;
            }
          }
        }
      }
    }
  }
  .deliverySetting-table {
    
    
    font-size: 14px;
    color: #333;
    .table-head,
    .table-body {
    
    
      display: flex;
      padding: 10px 0;
      .selection {
    
    
        width: 45px;
        text-align: center;
        line-height: 36px;
      }
      .width185 {
    
    
        width: 30px;
      }
      // .width265 {
    
    
      //   width: 265px;
      // }
    }
    .table-head {
    
    
      height: 36px;
      align-items: center;
      background-color: #e7f2ff;
    }
    .table-body {
    
    
      border-bottom: 1px solid #e4e4e4;
      color: #666;
      &:hover {
    
    
        background-color: #f5f7fa;
      }
      .width265 {
    
    
        display: flex;
        flex-direction: column;
        label {
    
    
          line-height: 30px;
          margin-left: 0;
          color: #666;
        }
      }
      p {
    
    
        line-height: 30px;
      }
    }
  }
  .deliverySetting-btn {
    
    
    /*width: 100%;*/
    height: 59px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    position: absolute;
    top: -55px;
    right: -16px;
    z-index: 100;
    .tabs-btn {
    
    
      min-width: 90px;
      height: 34px;
      line-height: 32px;
      padding: 0 10px;
      color: #2387f7;
      border: solid 1px #4fa2ff;
      background-color: #e7f2ff;
      cursor: pointer;
      &:nth-of-type(2) {
    
    
        margin: 0 15px;
      }
      input {
    
    
        border: none;
        background: transparent;
        color: inherit;
        cursor: inherit;
        outline: none;
        margin: 0;
        padding: 0;
      }
      &:hover {
    
    
        color: #fff;
        background-color: #2387f7;
      }
    }
  }
  .setDistributorDailog {
    
    
    .el-input {
    
    
      width: 270px;
    }
  }
}
</style>

参考链接1

参考2

猜你喜欢

转载自blog.csdn.net/m0_53912016/article/details/120268449