<template>
  <div>
    <w-tree-grid
      ref="treeGrid"
      title="机构树"
      :nodes="nodes"
      label-key="titleI18nKey"
      label-i18n
      label-empty="--------------------"
      :actions="actions"
      tick-strategy="leaf"
    />
    <q-btn label="ok" @click="ok"></q-btn>
  </div>
</template>
<script setup lang="ts">
import { ref, toRaw, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { Environment, axios, BackendTools } from '@/platform';

const { t } = useI18n();

const treeGrid = ref();
const nodes = ref([]);
const selected = [];
const ticked = [];
const expanded = [];
const actions = [
  {
    name: 'refresh',
    label: '刷新',
  },
  {
    name: 'expandAll',
    label: '全部展开',
  },
  {
    name: 'selectAll',
    label: '全部选择',
  },
  {
    name: 'save',
    label: '保存',
  },
];

onMounted(() => {
  axios.get(Environment.apiContextPath('/api/system/menu?pageable=false')).then((response) => {
    treeGrid.value.setNodes(response.data.content);
  });
});

const ok = () => {
  console.log(treeGrid.value.getCascadeParentIds(treeGrid.value.getSelected()));
  console.log(treeGrid.value.getCascadeChildrenIds(treeGrid.value.getSelected()));
  console.log(treeGrid.value.getSelectedNode(treeGrid.value.getSelected()));
};
</script>
