<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!--插槽:table标题-->
      <template #tableTitle>
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
   
    <!-- 审核历史区域 -->
    <ShlsModal @register="registerModalShls"></ShlsModal>
   
    <!-- 生态部门退回区域 -->
    <StThModal @register="registerModalStTh"  @success="handleSuccess"></StThModal>
    
  </div>
</template>

<script lang="ts" name="directory-gzml-gzml" setup>
  import { ref, h } from 'vue';
  import { BasicTable, TableAction } from '/@/components/Table';
  import { useModal } from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { sjcolumns, sjsearchFormSchema } from './data';
  import { provinceAuditsPageList } from './api';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useRouter } from 'vue-router';
  import { Modal } from 'ant-design-vue';
  import ShlsModal from './modules/ShlsModal.vue'
  import StThModal from './modules/StThModal.vue'
  import { useUserStore } from '/@/store/modules/user';
  const userStore: any = useUserStore();
  const { createMessage } = useMessage();
  let router = useRouter();
  let year = new Date().getFullYear();
  let month = new Date().getMonth();

  // Emits声明
  const emit = defineEmits(['success']);
const getNd = () => {
  let nd = 2025;
  if (month < 3) {
    nd = year -1
  } else {
    nd = year;
  }
  return nd +'';
}
const getJd = () => {
  let jd = '04';
  if (month < 3) {
    jd = '04';
  } else if (month < 6) {
    jd = '01';
  } else if (month < 9) {
    jd = '02';
  } else{
    jd = '03';
  }
  return jd;
}
  //注册model
  const [registerModal, { openModal }] = useModal();
  const [registerModalShls, { openModal: openModalShls }] = useModal();
  const [registerModalStTh, { openModal: openModalStTh }] = useModal();
  //注册table数据
  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '审核数据',
      api: provinceAuditsPageList,
      columns:sjcolumns,
      canResize: false,
      clickToRowSelect: true,
      beforeFetch(params) {
        params.jd = getNd()+getJd();
      }, 
      //定义rowSelection的类型，默认是checkbox多选，可以设置成radio单选
      rowKey: 'id',
      minHeight: 400,
      rowSelection: { type: 'radio' },
      formConfig: {
        labelWidth: 120,
        schemas: sjsearchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: false,
      },
      showIndexColumn: true,
      actionColumn: {
        width: 120,
      },
    },
  });
  const open = ref(false);
  const noChange = ref<boolean>(false);
  const selectdclx = ref<number>(1);
  const flg = ref(1);
  const visible = ref<boolean>(false);
  const bgvisible = ref<boolean>(false);
  const [registerTable, { reload }, { rowSelection, selectedRows, selectedRowKeys }] = tableContext;

  //成功回调
  function handleSuccess() {
    selectedRows.value = [];
    selectedRowKeys.value = [];
    reload();
    emit("success")
  }
 
  /**
   * 审核历史
   */
  function handleShls(record) {
    // if (selectedRowKeys.value.length == 0) {
    //   createMessage.info('请选择需要处理的内容，每次只能选中一条');
    //   return;
    // }
    openModalShls(true, {
      isUpdate: false,
      showFooter: true,
      record: record
    });
  }
 
  /**
   * 退回
   */
  function handleBack(record: Recordable) {
    openModalStTh(true, {
      record,
      isUpdate: true,
      showFooter: true,
    });
  }
  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: '审核历史',
        onClick: handleShls.bind(null, record),
        auth: 'yztsjshj:th',
      },
      {
        label: '退回',
        onClick: handleBack.bind(null, record),
        auth: 'yztsjshj:th',
        ifShow: record.cityStatus == "2"
      },
    ];
  }

</script>
<style>
.ant-table {
  min-height: 300px;
}
</style>
