index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import React, { PureComponent } from 'react';
  2. import PropTypes from 'prop-types';
  3. import queryString from 'query-string';
  4. import { connect } from 'dva';
  5. import { routerRedux } from 'dva/router';
  6. import { Card } from 'antd';
  7. import TableList from './table';
  8. import Search from './search';
  9. import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
  10. import { Codes } from '../../../utils/config';
  11. @connect(state => ({
  12. order: state.order,
  13. }))
  14. export default class Order extends PureComponent {
  15. static propTypes = {
  16. order: PropTypes.object,
  17. location: PropTypes.object,
  18. dispatch: PropTypes.func,
  19. };
  20. render() {
  21. const { location, dispatch, order } = this.props;
  22. location.query = queryString.parse(location.search);
  23. const { query, pathname } = location;
  24. const { field, keyword, ...filters } = query;
  25. const { list, listLoading, pagination, currentItem, itemLoading, modalVisible, modalType } = order;
  26. // 把携带的参数中空值项删除
  27. Object.keys(filters).map((key) => { filters[key] ? null : delete filters[key]; });
  28. // 如果搜索内容不为空则添加进filters中
  29. if (field && keyword) {
  30. filters.field = field;
  31. filters.keyword = keyword;
  32. }
  33. const searchProps = {
  34. field,
  35. keyword,
  36. onSearch: (payload) => {
  37. if (!payload.keyword.length) {
  38. delete payload.field;
  39. delete payload.keyword;
  40. }
  41. dispatch(routerRedux.push({
  42. pathname,
  43. search: queryString.stringify({
  44. ...payload,
  45. }),
  46. }));
  47. },
  48. onAdd: () => {
  49. dispatch(
  50. routerRedux.push({
  51. pathname: '/order/add',
  52. state: filters,
  53. })
  54. );
  55. },
  56. };
  57. const listProps = {
  58. pagination,
  59. location,
  60. dataSource: list,
  61. loading: listLoading,
  62. timeBegin: filters.timeBegin,
  63. timeEnd: filters.timeEnd,
  64. curStatus: filters.status,
  65. onChange: (pagination, filterArgs) => {
  66. const getValue = obj => Object.keys(obj).map(key => obj[key]).join(',');
  67. const tableFilters = Object.keys(filterArgs).reduce((obj, key) => {
  68. const newObj = { ...obj };
  69. newObj[key] = getValue(filterArgs[key]);
  70. return newObj;
  71. }, {});
  72. const data = { ...filters, ...tableFilters };
  73. Object.keys(data).map(key => (data[key] ? null : delete data[key]));
  74. dispatch(routerRedux.push({
  75. pathname,
  76. search: queryString.stringify({
  77. ...data,
  78. pageNo: pagination.current,
  79. pageSize: pagination.pageSize,
  80. }),
  81. }));
  82. },
  83. onViewItem: (item) => {
  84. dispatch(
  85. routerRedux.push({
  86. pathname: `/order/profile/${item.id}`,
  87. state: filters,
  88. })
  89. );
  90. },
  91. onEditItem: (item) => {
  92. dispatch(
  93. routerRedux.push({
  94. pathname: `/order/edit/${item.id}`,
  95. state: filters,
  96. })
  97. );
  98. },
  99. onDeleteItem: (id) => {
  100. dispatch({
  101. type: 'order/delete',
  102. payload: id,
  103. callback: () => {
  104. dispatch(
  105. routerRedux.push({
  106. pathname,
  107. search: queryString.stringify(filters),
  108. })
  109. );
  110. },
  111. });
  112. },
  113. onRecoverItem: (payload) => {
  114. dispatch({
  115. type: 'order/recover',
  116. payload,
  117. callback: () => {
  118. dispatch(
  119. routerRedux.push({
  120. pathname,
  121. search: queryString.stringify(filters),
  122. })
  123. );
  124. },
  125. });
  126. },
  127. };
  128. return (
  129. <PageHeaderLayout>
  130. <Card>
  131. <Search {...searchProps} />
  132. <TableList {...listProps} />
  133. </Card>
  134. </PageHeaderLayout>
  135. );
  136. }
  137. }