1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import React, { PureComponent } from 'react';
- import queryString from 'query-string';
- import { connect } from 'dva';
- import { routerRedux } from 'dva/router';
- import { Card } from 'antd';
- import TableList from './table';
- import Search from './search';
- import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
- @connect(state => ({ mproduct: state.mproduct }))
- export default class MerchantProductList extends PureComponent {
- render() {
- const { location, dispatch, mproduct } = this.props;
- location.query = queryString.parse(location.search);
- const { query, pathname } = location;
- const { field, keyword, ...filters } = query;
- const { list, listLoading, pagination } = mproduct;
- // 把携带的参数中空值项删除
- Object.keys(filters).map((key) => { filters[key] ? null : delete filters[key]; });
- // 如果搜索内容不为空则添加进filters中
- if (field && keyword) {
- filters.field = field;
- filters.keyword = keyword;
- }
- const searchProps = {
- field,
- keyword,
- onSearch: (payload) => {
- if (!payload.keyword.length) {
- delete payload.field;
- delete payload.keyword;
- }
- dispatch(routerRedux.push({
- pathname,
- search: queryString.stringify({
- ...payload,
- }),
- }));
- },
- };
- const listProps = {
- pagination,
- location,
- dataSource: list,
- loading: listLoading,
- curStatus: filters.status,
- onChange: (page, filterArgs) => {
- const getValue = obj => Object.keys(obj).map(key => obj[key]).join(',');
- const tableFilters = Object.keys(filterArgs).reduce((obj, key) => {
- const newObj = { ...obj };
- newObj[key] = getValue(filterArgs[key]);
- return newObj;
- }, {});
- const data = { ...filters, ...tableFilters };
- Object.keys(data).map(key => (data[key] ? null : delete data[key]));
- dispatch(routerRedux.push({
- pathname,
- search: queryString.stringify({
- ...data,
- pageNo: page.current,
- pageSize: page.pageSize,
- }),
- }));
- },
- onViewItem: (item) => {
- dispatch(
- routerRedux.push({
- pathname: '/products/view',
- search: queryString.stringify({
- merchantId: item.merchantId,
- pid: item.pid,
- }),
- state: filters,
- })
- );
- },
- };
- return (
- <PageHeaderLayout>
- <Card>
- <Search {...searchProps} />
- <TableList {...listProps} />
- </Card>
- </PageHeaderLayout>
- );
- }
- }
|