import { useEffect, useRef, useState } from 'react';
import { Button, Space } from 'antd';
import { ProTable } from '@ant-design/pro-components';
import type {
    ActionType, ProColumns,
    EditableFormInstance,
    ProFormInstance,
} from '@ant-design/pro-components';
import ReportService from '@/api/reportService';

export default () => {
    const actionRef = useRef<ActionType>();
    const columns: ProColumns<ReportType.ProductReport>[] = [
        {
            title: 'productId',
            dataIndex: 'productId',
            hideInSearch: true,
            hideInTable:true,
            align: 'center',
        },
        {
            title: '成品名称',
            dataIndex: 'productName',
            align: 'center',
        },
        {
            title: '生产数量',
            dataIndex: 'count',
            hideInSearch: true,
            align: 'center',

        },
        {
            title: '生产时间',
            dataIndex: 'dateTime',
            valueType: 'dateRange',
            hideInTable:true,
            align: 'center',

        }

    ]

    return (
        <ProTable<ReportType.ProductReport>
        key="myTable"
        columns={columns}
        actionRef={actionRef}
        cardBordered
        request={async (params = {}) => {
          const jsonData: ReportType.ReportInput = {
            pageIndex: params.current || 1,
            pageSize: params.pageSize || 10,
            endTime:params.dateTime?params.dateTime[1]:undefined,
            startTime:params.dateTime?params.dateTime[0]:undefined,
            productName:params.productName||""
          };
     
          
          const response = await ReportService.PagedList(jsonData);
          if (response.statusCode === 200) {
            return {
              data: response.data.items,
              success: true,
              total: response.total,
            };
          } else {
            return {
              data: [],
              success: false,
              total: 0,
            };
          }
        }}
        rowKey="productId"
        pagination={{
          pageSize: 10,
          showSizeChanger:false
        }}
        dateFormatter="string"
        // headerTitle="列表"
        // toolBarRender={() => [
        //   <Button
        //     key="button"
        //     type="primary"
        //     onClick={() => {
        //     }}
        //   >
        //     新建工单
        //   </Button>,
        // ]}
      />
    );

};