<template>
  <PageWrapper  contentBackground>
    <template #footer>
      <a-tabs v-model:activeKey="state" @change="changeTable">
        <a-tab-pane :key="0" tab="待处理" />
        <a-tab-pane :key="1" tab="已处理" />
      </a-tabs>
    </template>

    <div class="desc-wrap-BasicTable">
      <BasicTable @register="registerTimeTable" >
        <template #action="{ record }">
          <TableAction
            stopButtonPropagation
            :actions="[
              {
                label: '发送',
                icon: 'icon-park-outline:door-handle',
                ifShow: getCheckPerm('apply-send') && record.state == 0,
                onClick: handleWithdraw.bind(null, record),
              },
            ]"
          />
      </template>
      </BasicTable>
    </div>
    <addMessgeModal @register="register" @update="reload" />
  </PageWrapper>
</template>
<script lang="ts">
  import { defineComponent, ref } from 'vue';
  import { BasicTable, useTable, TableAction, FormProps } from '/@/components/Table';
  import { PageWrapper } from '/@/components/Page';
  import { Divider, Card, Empty, Descriptions, Steps, Tabs } from 'ant-design-vue';
  import { intercomMessageList, intercomMessageHandle } from '/@/api/operate'
  import { sceneApplyList } from '/@/api/operate'
  import { useI18n } from '/@/hooks/web/useI18n';
  import addMessgeModal from './components/scene/addModal.vue'
  import { useModal } from '/@/components/Modal';
  import { DMegaSchema, refundTimeTableData } from './data';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { usePermissionStore } from '/@/store/modules/permission';
  export default defineComponent({
    components: {
      BasicTable,
      PageWrapper,
      TableAction,
      addMessgeModal,
      [Divider.name]: Divider,
      [Card.name]: Card,
      Empty,
      [Descriptions.name]: Descriptions,
      [Descriptions.Item.name]: Descriptions.Item,
      [Steps.name]: Steps,
      [Steps.Step.name]: Steps.Step,
      [Tabs.name]: Tabs,
      [Tabs.TabPane.name]: Tabs.TabPane,
    },
    setup() {
      const { t } = useI18n();
      const { createConfirm, createMessage } = useMessage();
      const [register, { openModal }] = useModal();
      const permissionStore = usePermissionStore();
      const { getCheckPerm } = permissionStore;
      const state = ref<number>(0); //未处理，0已处理（默认1）
      const searchForm: Partial<FormProps> = {
        labelWidth: 100,
        autoSubmitOnEnter:true,
        schemas: [
          {
            field: 'payTime',
            label: '提交时间',
            component: 'RangePicker',
            componentProps: {
              maxLength: 100,
              format: 'YYYY-MM-DD',
              valueFormat:'YYYY-MM-DD',
              showTime: true,
            },
            colProps: {
              xl: 11,
              xxl: 11,
            },
          },
          {
            field: 'companyName',
            label: '公司名称',
            component: 'Input',
            colProps: {
              xl: 6,
              xxl: 6,
            },
          },
        ],
      };
      const [registerTimeTable,{reload}] = useTable({
        api: sceneApplyList,
        title: '申请列表',
        rowKey: 'id',
        fetchSetting: {
          pageField: 'pageNum',
          sizeField: 'pageSize',
          listField: 'list',
          totalField: 'total',
        },
        searchInfo: { handleState:state },
        columns: DMegaSchema,
        formConfig: searchForm,
        useSearchForm: true,
        dataSource: refundTimeTableData,
        showTableSetting: true,
        showIndexColumn: false,
        // pagination: { pageSize: 20 },
        // scroll: { y: 300 },
        beforeFetch:(params)=>{
          return {
            ...params,
            startTime: params.payTime && params.payTime[0],
            endTime: params.payTime && params.payTime[1],
          }
        },
        actionColumn: {
          width: 100,
          title: '操作',
          ifShow:state.value == 0,
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
      });
      function changeTable(val: string) {
        state.value = val;
        reload();
      }
      async function handleWithdraw(record: Recordable) {
        // createConfirm({
        //   iconType: 'info',
        //   title: '发送邮件',
        //   content: `此操作将对${record.applicationName}进行删除, 是否继续?`,
        //   onOk: async () => {
        //     await buryPointDlt({ id: record.id });
        //     reload();
        //     createMessage.success(t('common.optSuccess'));
        //   },
        // });
        openModal(true,record)
      }
      return {
        registerTimeTable,
        handleWithdraw,
        changeTable,
        state,
        reload,
        register,
        openModal,
        getCheckPerm,
      };
    },
  });
</script>

