import React, { Component } from "react"; import { withRouter, RouteComponentProps } from "react-router-dom"; import { Table, Statistic, message, Pagination } from "antd"; import MainLayout from "@/layout"; import ImgPreview from "@/components/ImgPreview"; import { PaginationProps } from "antd/lib/pagination"; import { Product } from "@/api/service/ProductService"; import Query from "./query"; import Api from "@/api"; import "./index.scss"; import { HTTP_STATUS } from "@/shared/common/constants"; type P = RouteComponentProps & {}; type S = { dataSource: Product[]; pagination: PaginationProps; queryParams: any; total: number; loading: boolean; }; const InitPage = { pageIndex: 1, pageSize: 10 }; class List extends Component
{ state = { dataSource: [], pagination: {}, total: 0, queryParams: {}, loading: false }; componentDidMount() { this.initData(); } initData = () => { this.queryList({ ...InitPage }); }; queryList = async params => { this.setState({ loading: true }); try { const res = await Api.product.queryProductPage(params); if (HTTP_STATUS.SUCCESSS === res.code) { const total = res.data.total; const current = res.data.current; this.setState({ dataSource: res.data.data || [], total, loading: false, pagination: { total, current, pageSize: params.pageSize, onChange: (pageIndex, pageSize) => { this.queryList( Object.assign({}, params, { pageIndex, pageSize }) ); }, onShowSizeChange: (pageIndex, pageSize) => { this.queryList( Object.assign({}, params, { pageIndex, pageSize }) ); } }, queryParams: params }); } else { message.error(res.message); this.setState({ loading: false }); } } catch (error) { this.setState({ loading: false }); } }; handleSubmit = values => { this.queryList(Object.assign({}, InitPage, values)); }; handleDetails = record => { const { id } = record; this.props.history.push(`/purchase/details/${id}`); }; getTableProps = () => { const { dataSource, pagination, total, loading } = this.state; const columns = [ { title: "商品", dataIndex: "", key: "name", render: (record: Product) => { console.log({ record }); return (
{record.name} {record.id}