<template>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="exportExcel"> 导出</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 } 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 {  downloadByData, } from '/@/utils/file/download';
  import { IncrementList,IncrementExport } from '/@/api/order'

  export default defineComponent({
    components: { 
      BasicTable, 
      TableAction, 
      PageWrapper,
      TableImg,
      [Descriptions.name]: Descriptions,
      [Descriptions.Item.name]: Descriptions.Item,
    },
    setup() {
      const { t } = useI18n();
      const { createMessage,createConfirm } = useMessage();
      const columns: BasicColumn[] = [
        {
          title: '下单时间',
          dataIndex: 'createTime',
          width: 150,
          customRender: ({ record }) => {
            return (
              record.createTime &&
              h(Time, {
                value: record.createTime,
                mode: 'datetime',
              })
            );
          },
        },
        {
          title: '订单号',
          dataIndex: 'orderSn',
          ellipsis: false,
          width: 180,
        },
        {
          title: '用户名',
          dataIndex: 'userName',
          width: 80,
        },
        {
          title: '数量',
          dataIndex: 'count',
          width: 80,
        },
        {
          title: '交易号',
          dataIndex: 'number',
          width: 180,
        },
        {
          title: '订单金额',
          dataIndex: 'amount',
          width: 80,
        },
        {
          title: '支付方式',
          dataIndex: 'payType',
          // slots: { customRender: 'orderType' },
          width: 80,
        },
        {
          title: '订单状态',
          dataIndex: 'payStatus',
          // slots: { customRender: 'orderStatus' },
          width: 80,
        },
      ];
      const searchForm: Partial<FormProps> = {
        labelWidth: 100,
        schemas: [
          {
            field: 'sceneName',
            label: '下单时间',
            component: 'RangePicker',
            componentProps: {
              maxLength: 100,
            },
            colProps: {
              xl: 7,
              xxl: 7,
            },
          },{
            field: 'sceneName',
            label: '订单号',
            component: 'Input',
            componentProps: {
              maxLength: 100,
            },
            colProps: {
              xl: 6,
              xxl: 6,
            },
          },{
            field: 'sceneName',
            label: '手机号',
            component: 'Input',
            componentProps: {
              maxLength: 100,
            },
            colProps: {
              xl: 5,
              xxl: 5,
            },
          },{
            field: 'sceneName',
            label: '支付平台交易号',
            component: 'Input',
            componentProps: {
              maxLength: 100,
            },
            colProps: {
              xl: 6,
              xxl: 6,
            },
          },
        ],
      };
      const [registerTable] = useTable({
        api: IncrementList,
        title: '权益列表',
        // titleHelpMessage: ['已启用expandRowByClick', '已启用stopButtonPropagation'],
        columns: columns,
        useSearchForm: true,
        formConfig: searchForm,
        showTableSetting: true,
        rowKey: 'id',
        fetchSetting: {
          pageField: 'pageNum',
          sizeField: 'pageSize',
          listField: 'list',
          totalField: 'total',
        },
        canResize: false,
      });
      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', '确定当前标签下的订单记录?'),
          onOk: async () => {
            IncrementExport({}).then(res => {
              console.log('handlerowClick',res)
              downloadByData(res.data,'权益订单.xls')
            })
          },
        });
      }
      return {
        registerTable,
        handleDelete,
        handleOpen,
        exportExcel,
      };
    },
  });
</script>