import { getStoreLogList, getStoreTypeList,storeLogExport } from '@/services/stock';
import { queryDict, queryTable } from '@/utils/request';
import { PageContainer, ProTable } from '@ant-design/pro-components';
import { Button } from 'antd';
import { useRef } from 'react';

const StockLog = (props) => {
  const actionRef = useRef();
  const formRef = useRef()
  const onExport = () => {
    storeLogExport(formRef.current.getFieldsValue());
  };
  const columns = [
    {
      title: '名称',
      dataIndex: 'storeName',
    },
    {
      title: '分类',
      dataIndex: 'typeId',
      valueType: 'select',
      request: () => queryDict(getStoreTypeList)(),
    },
    {
      title: '操作',
      dataIndex: 'optType',
      valueEnum: {
        in: '入库',
        out: '出库',
        fix: '盘点',
      },
      search: false,
    },
    {
      title: '操作量',
      dataIndex: 'amount',
      search: false,
    },
    {
      title: '操作后库存',
      dataIndex: 'aftAmount',
      search: false,
    },
    {
      title: '操作时间',
      dataIndex: 'createDate',
      valueType: 'dateTime',
      search: false,
    },
  ];

  return (
    <PageContainer>
      <ProTable
        actionRef={actionRef}
        formRef={formRef}
        rowKey="id"
        toolBarRender={() => [
          <Button
            key="2"
            type="primary"
            onClick={() => {
              onExport();
            }}
          >
            导出
          </Button>,
        ]}
        // search={false}
        request={queryTable(getStoreLogList)}
        columns={columns}
      />
    </PageContainer>
  );
};

export default StockLog;
