<template>
  <a-button type="primary" @click="showModal">查看历史信息</a-button>
  <a-modal width="80%" v-model:visible="visible" title="历史信息" :footer="null">
    <BasicTable :columns="columns" :dataSource="data" :pagination="false" />
  </a-modal>
</template>
<script setup lang="ts">
  import { ref } from 'vue';
  import { BasicTable } from '@/components/Table';
  import { subTableStore } from '@/store/modules/subTable';
  import { getFormDataHistory } from '@/api/demo/formScheme';

  const subTableDataStore = subTableStore();
  const data = ref([]);
  const columns = ref([]);
  const props = defineProps({
    dataTable: String,
    fieldArr: Object,
  });
  const visible = ref(false);
  const showModal = () => {
    visible.value = true;
    let querys = {
      table: props.dataTable,
      field: props.fieldArr,
      pkey: subTableDataStore.getInstance.pkey,
      pkeyValue: !subTableDataStore.getInstance.parentPkeyValue
        ? subTableDataStore.getInstance.pkeyValue
        : subTableDataStore.getInstance.parentPkeyValue,
      schemeId: subTableDataStore.getInstance.schemeId,
    };
    getFormDataHistory(querys).then((res) => {
      data.value = res.item2;
      columns.value = res.item1;
    });
  };
</script>
