<template>
  <BasicModal
    v-bind="$attrs"
    @register="chooseModalPegister"
    title="数据对象选择"
    width="1000px"
    @fullscreen="onFullscreen"
    @ok="submit"
  >
    <BasicTable @register="pageChooseTableRegister">
      <template #toolbar>
        <a-button type="primary" class="my-4" @click="openPageImportModal">
          {{ '导入' }}
        </a-button>
      </template>
    </BasicTable>
  </BasicModal>
  <PageTableImportModal @register="pageTableImportModalRegister" @importdata="fun_importdata" />
</template>
<script lang="ts" setup>
  import { defineEmits } from 'vue';
  import { BasicModal, useModal } from '@/components/Modal';
  import { BasicTable, useTable } from '@/components/Table';
  import { useMessage } from '@/hooks/web/useMessage';
  import { function_Get_LoadCodeTablePage } from '@/api/demo/formScheme';
  import { getTableChooseColumns } from './pageStepData';
  import PageTableImportModal from './pageTableImportModal.vue';

  const emit = defineEmits(['choosedata']);
  const { createMessage } = useMessage();

  const [chooseModalPegister, { closeModal }] = useModal();
  // 导入弹窗
  const [pageTableImportModalRegister, { openModal: openPageImportModal }] = useModal();
  // 数据对象选择表格
  const [pageChooseTableRegister, { getSelectRows, reload, clearSelectedRowKeys }] = useTable({
    canResize: true,
    api: pageTableChooseModal,
    columns: getTableChooseColumns(),
    rowKey: 'id',
    showTableSetting: true,
    // 使用搜索表单
    // useSearchForm: true,
    rowSelection: {
      type: 'checkbox',
    },
  });
  // 数据对象表格参数api
  async function pageTableChooseModal() {
    var query = {
      page: 1,
      limit: 10,
      dbCode: 'lrsystemdb',
    };
    return await function_Get_LoadCodeTablePage(query);
  }
  // 表格数据提交
  async function submit() {
    let rows = getSelectRows();
    emit('choosedata', rows);
    clearSelectedRowKeys();
    reload();
    closeModal();
  }

  async function fun_importdata() {
    createMessage.success('表格导入成功！');
    clearSelectedRowKeys();
    reload();
  }
</script>
