<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('agent-deal') && 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 { agentAuditList, agentAuditHandle } from '/@/api/operate'
  import { useI18n } from '/@/hooks/web/useI18n';
  import addMessgeModal from './components/agent/addModal.vue'
  import { useModal } from '/@/components/Modal';
  import { agentSchema, refundTimeTableData } from './data';
  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 [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: agentAuditList,
        // title: '',
        rowKey: 'id',
        fetchSetting: {
          pageField: 'pageNum',
          sizeField: 'pageSize',
          listField: 'list',
          totalField: 'total',
        },
        searchInfo: { handleState:state },
        columns: agentSchema,
        formConfig: searchForm,
        useSearchForm: true,
        dataSource: refundTimeTableData,
        showTableSetting: true,
        showIndexColumn: false,
        // pagination: { pageSize: 20 },
        beforeFetch:(params)=>{
          return {
            ...params,
            startTime: params.payTime && params.payTime[0],
            endTime: params.payTime && params.payTime[1],
          }
        },
        // scroll: { y: 300 },
        actionColumn: {
          width: 100,
          title: '操作',
          // ifShow:state.value == 1,
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
      });
      function changeTable(val: string) {
        state.value = val;
        reload();
      }
      async function handleWithdraw(record: Recordable) {
        openModal(true,record)
      }
      return {
        registerTimeTable,
        handleWithdraw,
        changeTable,
        state,
        reload,
        register,
        openModal,
        getCheckPerm,
      };
    },
  });
</script>
