<template>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="exportExcel" v-if="getCheckPerm('rights-order-export')"> 导出</a-button>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            stopButtonPropagation
            :actions="[
              {
                label: '删除',
                //icon: 'ic:outline-delete-outline',
                onClick: handleDelete.bind(null, record),
              },
            ]"
            :dropDownActions="[
              {
                label: '启用',
                popConfirm: {
                  title: '是否启用？',
                  confirm: handleOpen.bind(null, record),
                },
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
</template>
<script lang="ts">
  import { defineComponent, h, ref } from 'vue';
  import { BasicTable, useTable, TableAction, BasicColumn, TableImg, FormProps } from '/@/components/Table';
  import { PageWrapper } from '/@/components/Page';
  import { Time } from '/@/components/Time';
  import { Descriptions } from 'ant-design-vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { equityColumns,equitySearchForm } from '../account/details/data'
  import {  downloadByData, } from '/@/utils/file/download';
  import { IncrementList,IncrementExport } from '/@/api/order'
  import { usePermissionStore } from '/@/store/modules/permission';

  export default defineComponent({
    components: { 
      BasicTable, 
      TableAction, 
      PageWrapper,
      TableImg,
      [Descriptions.name]: Descriptions,
      [Descriptions.Item.name]: Descriptions.Item,
    },
    setup() {
      const { t } = useI18n();
      const isSearch = ref(false)
      const { createMessage,createConfirm } = useMessage();
      const permissionStore = usePermissionStore();
      const { getCheckPerm } = permissionStore;
      const [registerTable] = useTable({
        api: IncrementList,
        title: '权益列表',
        // titleHelpMessage: ['已启用expandRowByClick', '已启用stopButtonPropagation'],
        columns: equityColumns,
        useSearchForm: true,
        showIndexColumn:false,
        formConfig: equitySearchForm,
        showTableSetting: true,
        rowKey: 'id',
        beforeFetch:(T)=>{
          const {ctivated,tradeNum,userName,orderSn} = T
          if(ctivated||tradeNum||userName||orderSn){
            isSearch.value = true
          }else{
            isSearch.value = false
          }
          if(T.ctivated){
            T.startTime = T.ctivated[0]
            T.endTime = T.ctivated[1]
          }
          console.log('beforeFetch',T)
          return T
        },
        fetchSetting: {
          pageField: 'pageNum',
          sizeField: 'pageSize',
          listField: 'list',
          totalField: 'total',
        },
        canResize: true,
      });
      function handleDelete(record: Recordable) {
        console.log('点击了删除', record);
      }
      function handleOpen(record: Recordable) {
        console.log('点击了启用', record);
      }
      function exportExcel() {
        createConfirm({
          iconType: 'warning',
          title: () => h('span', '温馨提示'),
          content: () => h('span', isSearch.value?'确认导出搜索结果？':'确认导出全部?'),
          onOk: async () => {
            IncrementExport()
          },
        });
      }
      return {
        registerTable,
        handleDelete,
        handleOpen,
        exportExcel,
        getCheckPerm,
      };
    },
  });
</script>