<template>
  <div class="demo-tree-select-basic">
    <div class="demo-box">
      <ui-tree-select
        v-model="value"
        :keymap="{
          value: 'id',
          children: 'nodes',
        }"
        :tree-data="treeData"
        filterable
        placeholder="请选择数据"
        tree-default-expand-all
        show-all-levels
        @change="change"
        clearable>
      </ui-tree-select>
    </div>

    <div class="demo-box">
      <ui-tree-select
        v-model="value2"
        :keymap="{
          value: 'id',
          children: 'nodes',
        }"
        :tree-data="treeData2"
        :support-value-empty-string="false"
        filterable
        placeholder="空字符串将会被忽略!"
        tree-default-expand-all
        clearable>
      </ui-tree-select>
    </div>

    <div class="demo-box">
      <ui-tree-select
        v-model="value"
        :keymap="{
          value: 'id',
          children: 'nodes',
        }"
        :tree-data="treeData"
        filterable
        tree-default-expand-all
        disabled>
      </ui-tree-select>
    </div>
  </div>
</template>

<script>
import { TreeSelect } from "amumu-ui"
export default {
  components: {
    "ui-tree-select": TreeSelect,
  },
  data() {
    return {
      value: "",
      value2: "",
      treeData: [
        {
          id: "",
          label: "全部(空字符串)",
        },
        {
          id: "1",
          label: "一级 1",
          nodes: [
            {
              id: "4",
              label: "二级 1-1",
              nodes: [
                {
                  id: "9",
                  label: "三级 1-1-1",
                },
                {
                  id: "10",
                  label: "三级 1-1-2",
                },
              ],
            },
          ],
        },
        {
          id: "2",
          label: "一级 2",
          nodes: [
            {
              id: "5",
              label: "二级 2-1",
            },
            {
              id: "6",
              label: "二级 2-2",
            },
          ],
        },
        {
          id: "3",
          label: "一级 3",
          nodes: [
            {
              id: "7",
              label: "二级 3-1",
            },
            {
              id: "8",
              label: "二级 3-2",
            },
          ],
        },
      ],
      treeData2: [
        {
          id: "1",
          label: "一级 1",
          nodes: [
            {
              id: "4",
              label: "二级 1-1",
              nodes: [
                {
                  id: "9",
                  label: "三级 1-1-1",
                },
                {
                  id: "10",
                  label: "三级 1-1-2",
                },
              ],
            },
          ],
        },
        {
          id: "2",
          label: "一级 2",
          nodes: [
            {
              id: "5",
              label: "二级 2-1",
            },
            {
              id: "6",
              label: "二级 2-2",
            },
          ],
        },
        {
          id: "3",
          label: "一级 3",
          nodes: [
            {
              id: "7",
              label: "二级 3-1",
            },
            {
              id: "8",
              label: "二级 3-2",
            },
          ],
        },
      ],
    }
  },
  methods: {
    change(v, node) {
      console.log(v, node)
    }
  }
}
</script>

<style lang="scss">
.demo-tree-select-basic {
}
</style>
