<template>
  <draggable :list="list" animation="300" group="demoDragTree">
    <transition-group>
      <div v-for="item in list" :key="item.id" class="demo-drag-tree-item">
        <span><i class="el-icon-_tree"></i> {{ item.name }}</span>
        <div v-if="item.children&&item.children.length" class="demo-drag-tree-children">
          <drag-tree-item v-model="item.children"/>
        </div>
      </div>
    </transition-group>
  </draggable>
</template>

<script>
import draggable from 'vuedraggable'

export default {
  name: "DragTreeItem",
  components: {draggable},
  model: {
    prop: 'list',
    event: 'change'
  },
  props: {
    list: Array
  }
}
</script>

<style scoped>
.demo-drag-tree-item {
  padding: 10px 15px;
}

.demo-drag-tree-item:hover {
  cursor: move;
}

.demo-drag-tree-item.sortable-chosen {
  background-color: hsla(0, 0%, 60%, .1);
}

.demo-drag-tree-children {
  padding: 10px 0 0 10px;
}
</style>