import { DropboxOutlined, PlusOutlined, DownloadOutlined } from '@ant-design/icons';
import { Button, message, Select, Input, Drawer, Popconfirm } from 'antd';
import React, { useState, useRef, useEffect } from 'react';
import { PageContainer, FooterToolbar } from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import api from './service';

const Manage = () => {
  // 获取店铺分类、商品名称信息
  const [Selectparams, setparams] = useState([]);
  /**导出 */
  function handleExport() {
    api.GetFlowExport(Selectparams).then((res) => {
      let url = URL.createObjectURL(new Blob([res]));
      let filename = '订单流水.xlsx';
      let a = document.createElement('a');
      a.href = url;
      a.download = filename;
      a.click();
      URL.revokeObjectURL(url);
    });
  }
  /** 国际化配置 */

  const columns = [
    {
      title: '主键',
      dataIndex: 'id',
      tip: '规则名称是唯一的 key',
      hideInSearch: true,
      hideInTable: true,
    },
    {
      title: '订单时间',
      dataIndex: 'order_CreateTime',
      valueType: 'dateRange',
      hideInTable: true,
      search: {
        transform: (value) => {
          return {
            order_CreateTime: value[0],
            order_EndTime: value[1],
          };
        },
      },
    },
    {
      title: '账单类型',
      dataIndex: 'ExType',
      hideInTable: true,
      valueEnum: {
        0: { text: '退款订单' },
        1: { text: '支付订单' },
      },
    },

    {
      title: '微信订单时间',
      dataIndex: 'orderTime',
      valueType: 'dateTime',
      hideInSearch: true,
    },
    {
      title: '微信金额',
      dataIndex: 'realMoney',
      hideInSearch: true,
      renderText: (val) => `${val}¥`,
    },

    {
      title: '三方订单号',
      dataIndex: 'tradeNo',
      hideInSearch: true,
    },

    {
      title: '支付单号',
      dataIndex: 'transactionId',
      hideInSearch: true,
    },
    {
      title: '平台金额',
      dataIndex: 'orderRealMoney',
      hideInSearch: true,
      renderText: (val) => `${val}¥`,
    },
    {
      title: '平台订单时间',
      valueType: 'dateTime',
      dataIndex: 'createdAt',
      hideInSearch: true,
    },
    {
      title: '金额异常',
      dataIndex: 'moneyEx',
      hideInSearch: true,
    },
    {
      title: '订单时间异常',
      dataIndex: 'orderTimeEx',
      hideInSearch: true,
    },
    {
      title: '订单异常',
      dataIndex: 'orderEx',
      hideInSearch: true,
    },
  ];

  return (
    <PageContainer>
      <ProTable
        headerTitle="异常订单数据"
        rowKey="id"
        search={{
          labelWidth: 120,
        }}
        toolBarRender={() => [
          <Button type="primary" key="create" onClick={() => handleExport()}>
            <DownloadOutlined /> 导出
          </Button>,
        ]}
        columns={columns}
        //数据绑定
        request={async (params, sorter, filter) => {
          setparams(params);
          const msg = await api.orderList(params);
          return {
            data: msg.data.data,
            success: true,
            total: msg.data.total,
          };
        }}
      ></ProTable>
    </PageContainer>
  );
};

export default Manage;
