index.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React, { PureComponent } from 'react';
  2. import queryString from 'query-string';
  3. import { connect } from 'dva';
  4. import { routerRedux } from 'dva/router';
  5. import { Card } from 'antd';
  6. import TableList from './table';
  7. import Search from './search';
  8. import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
  9. @connect(state => ({ mproduct: state.mproduct }))
  10. export default class MerchantProductList extends PureComponent {
  11. render() {
  12. const { location, dispatch, mproduct } = this.props;
  13. location.query = queryString.parse(location.search);
  14. const { query, pathname } = location;
  15. const { field, keyword, ...filters } = query;
  16. const { list, listLoading, pagination } = mproduct;
  17. // 把携带的参数中空值项删除
  18. Object.keys(filters).map((key) => { filters[key] ? null : delete filters[key]; });
  19. // 如果搜索内容不为空则添加进filters中
  20. if (field && keyword) {
  21. filters.field = field;
  22. filters.keyword = keyword;
  23. }
  24. const searchProps = {
  25. field,
  26. keyword,
  27. onSearch: (payload) => {
  28. if (!payload.keyword.length) {
  29. delete payload.field;
  30. delete payload.keyword;
  31. }
  32. dispatch(routerRedux.push({
  33. pathname,
  34. search: queryString.stringify({
  35. ...payload,
  36. }),
  37. }));
  38. },
  39. };
  40. const listProps = {
  41. pagination,
  42. location,
  43. dataSource: list,
  44. loading: listLoading,
  45. curStatus: filters.status,
  46. onChange: (page, filterArgs) => {
  47. const getValue = obj => Object.keys(obj).map(key => obj[key]).join(',');
  48. const tableFilters = Object.keys(filterArgs).reduce((obj, key) => {
  49. const newObj = { ...obj };
  50. newObj[key] = getValue(filterArgs[key]);
  51. return newObj;
  52. }, {});
  53. const data = { ...filters, ...tableFilters };
  54. Object.keys(data).map(key => (data[key] ? null : delete data[key]));
  55. dispatch(routerRedux.push({
  56. pathname,
  57. search: queryString.stringify({
  58. ...data,
  59. pageNo: page.current,
  60. pageSize: page.pageSize,
  61. }),
  62. }));
  63. },
  64. onViewItem: (item) => {
  65. dispatch(
  66. routerRedux.push({
  67. pathname: '/products/view',
  68. search: queryString.stringify({
  69. merchantId: item.merchantId,
  70. pid: item.pid,
  71. }),
  72. state: filters,
  73. })
  74. );
  75. },
  76. };
  77. return (
  78. <PageHeaderLayout>
  79. <Card>
  80. <Search {...searchProps} />
  81. <TableList {...listProps} />
  82. </Card>
  83. </PageHeaderLayout>
  84. );
  85. }
  86. }