史上最菜鸡穿梭框

<template>
  <div class="transfer">
    <div class="left">
      <el-tree
        :data="data"
        show-checkbox
        node-key="id"
        :default-expanded-keys="[2, 3]"
        :default-checked-keys="[]"
        :props="defaultProps"
        @check="changeHandel"
      >
      </el-tree>
    </div>
    <div class="operateBox">
      <el-button @click="addFn">添加</el-button><el-button>删除</el-button>
    </div>
    <div class="right">
      <el-checkbox-group
        v-model="checkedCities"
        @change="handleCheckedCitiesChange"
      >
        <el-checkbox v-for="city in cities" :label="city" :key="city">{{
          city
        }}</el-checkbox>
      </el-checkbox-group>
    </div>
  </div>
</template>

<script>
let cityOptions = [];
export default {
  data() {
    return {
      arr: [],
      checkAll: false,
      checkedCities: [],
      cities: cityOptions,
      isIndeterminate: true,
      data: [
        {
          id: 1,
          label: "一级 1",
          children: [
            {
              id: 4,
              label: "上海",
            },
            {
              id: 5,
              label: "北京",
            },
          ],
        },
        {
          id: 2,
          label: "一级 2",
          children: [
            {
              id: 6,
              label: "广州",
            },
            {
              id: 7,
              label: "深圳",
            },
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  methods: {
    // 操作树形结构
    changeHandel(val, checkedKeys) {
      console.log(checkedKeys.checkedNodes);
      let newarr = [];
      checkedKeys.checkedNodes.forEach((item) => {
        //arr.push(item)
        if (!item.children) {
          newarr.push(item.label);
        }
      });
      console.log(newarr);
      this.arr = newarr;
      this.checkedCities = this.arr;
    },
    // 操作多选框
    handleCheckAllChange(val) {
      this.checkedCities = val ? cityOptions : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.cities.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.cities.length;

      console.log(value);
    },
    // 操作左框穿梭右框
    addFn() {
      //   cityOptions = this.arr;
      //   console.log(cityOptions);
      //   this.checkedCities = this.arr;
      this.arr.forEach((item) => {
        cityOptions.push(item);
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.transfer {
  display: flex;
  justify-content: space-between;
  width: 700px;
  height: 500px;
  background-color: green;
  .left {
    width: 40%;
    height: 100%;
    background-color: red;
  }
  .operateBox {
    flex: 1;
    background-color: #ccc;
    display: flex;
    flex-direction: column;
    .el-button {
      margin: 0;
    }
  }
  .right {
    width: 40%;
    height: 100%;
    background-color: blue;
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值