import {Modal } from 'antd';
import React, { useState} from 'react';
import ProTable from '@ant-design/pro-table';
import { GetGoods } from '../service';
const CreateForm = (props) => {

  const [selectedRowsState, setSelectedRows] = useState([]);
  const columns = [
    {
      title: '商品id',
      dataIndex: 'goodsId',
      tip: '规则名称是唯一的 key',
      hideInSearch: true,
      hideInTable: true,
    },
    {
      title: '商品名称',
      dataIndex: 'goodsName',
    },
  ];
  return (
    <Modal
      width={700}
      bodyStyle={{ padding: '32px 40px 48px' }}
      destroyOnClose
      title="选择商品"
      visible={props.modalVisible}
      onCancel={() => props.onCancel()}
      onOk={() => props.onSubmit(selectedRowsState)}
      maskClosable={false}
    >
      <ProTable
        headerTitle="商品信息"
        rowKey="goodsId"
        pagination={{ defaultPageSize: 5000 }}
        search={false}
        toolBarRender={false}
        params={{
          DeviceId:props.values,
        }}
        //数据绑定
        request={async (params) => {
          var Data = [];
          var total = 0;
          await GetGoods(params).then((r) => {
            Data = r.data;
            total = 1;
          });
          return {
            data: Data,
            success: true,
            total: total,
          };
        }}
        columns={columns}
        rowSelection={{
          onChange: (_, selectedRows) => setSelectedRows(selectedRows),
        }}
      />
    </Modal>
  );
};

export default CreateForm;
