<template>
  <BasicModal
    v-bind="$attrs"
    @ok="handleOk"
    @register="registerModal"
    title="数据表选择"
    width="800px"
  >
    <BasicTable @register="pageImportTableRegister" />
  </BasicModal>
</template>
<script lang="ts" setup>
  import { defineEmits } from 'vue';
  import { BasicModal, useModal } from '@/components/Modal';
  import { BasicTable, useTable } from '@/components/Table';
  import { getTableImportColumns } from './pageStepData';
  import { function_Get_GetTableList, function_Post_ImportTable } from '@/api/demo/formScheme';

  const emit = defineEmits(['importdata']);

  const [registerModal, { closeModal }] = useModal();

  const [pageImportTableRegister, { getSelectRows }] = useTable({
    canResize: true,
    // resizeHeightOffset: 300,
    api: function_Get_GetTableList,
    columns: getTableImportColumns(),
    defSort: {
      page: 10,
      limit: 1,
    },
    rowKey: 'name',
    // useSearchForm: true,
    clickToRowSelect: true,
    rowSelection: {
      type: 'checkbox',
    },
  });

  async function handleOk() {
    const selectData = getSelectRows();

    let tableList = [];
    selectData.forEach((element) => {
      tableList.push(element);
    });
    let query = {
      codeTableStr: 'lrsystemdb',
      tableList: tableList,
    };

    await function_Post_ImportTable(query);
    emit('importdata');
    closeModal();
  }
</script>
