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 api from '@/api/reportService';

export default () => {
    const actionRef = useRef<ActionType>();
    const columns: ProColumns<ReportType.MaterialReport>[] = [
        {
            title: 'materialId',
            dataIndex: 'materialId',
            hideInSearch: true,
            hideInTable:true,
            align: 'center',
        },
        {
            title: '原料名称',
            dataIndex: 'materialName',
            align: 'center',
        },
        {
            title: '生产重量(kg)',
            dataIndex: 'count',
            hideInSearch: true,
            align: 'center',

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

      }
    ]

    return (
        <ProTable<ReportType.MaterialReport>
        columns={columns}
        actionRef={actionRef}
        cardBordered
        request={async (params = {}) => {
          const jsonData: any = {
            pageIndex: params.current || 1,
            pageSize: params.pageSize || 10,
            endTime:params.dateTime?params.dateTime[1]:undefined,
            startTime:params.dateTime?params.dateTime[0]:undefined,
            materialName:params.materialName
          };
          const response = await api.PagedMaterialList(jsonData);
          if (response.statusCode === 200) {
            return {
              data: response.data.items,
              success: true,
              total: 1,
            };
          } 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>,
        // ]}
      />
    );

};