CampusList.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. import React, { Component } from 'react';
  2. import moment from 'moment';
  3. import { connect } from 'dva';
  4. import { routerRedux } from 'dva/router';
  5. import { Card, Modal, Form, Button, message } from 'antd';
  6. import { StandardTableList } from '../../components/RBList';
  7. import RBRemoteSelect from '../../components/RBRemoteSelect';
  8. import PageHeaderLayout from '../../layouts/PageHeaderLayout';
  9. import { addRowKey } from '../../utils/utils';
  10. import styles from './CampusList.less';
  11. const Message = message;
  12. const formItemLayout = {
  13. labelCol: {
  14. xs: { span: 24 },
  15. sm: { span: 7 },
  16. },
  17. wrapperCol: {
  18. xs: { span: 24 },
  19. sm: { span: 15 },
  20. md: { span: 13 },
  21. },
  22. };
  23. function merchantDataFormatter(data) {
  24. return data.map((item) => {
  25. return {
  26. text: item.name,
  27. value: item.id,
  28. };
  29. });
  30. }
  31. @Form.create()
  32. @connect(({ loading, campus, merchant }) => ({
  33. campus,
  34. merchant,
  35. fetching: loading.models.merchant,
  36. loading: loading.models.campus,
  37. }))
  38. export default class CampusListPage extends Component {
  39. constructor(props) {
  40. super(props);
  41. const { state } = props.location;
  42. this.state = {
  43. UIParams: (state || {}).UIParams, // 组件的状态参数
  44. Queryers: (state || {}).Queryers, // 查询的条件参数
  45. filterModalDestroy: true,
  46. };
  47. }
  48. componentDidMount() {
  49. this.props.dispatch({
  50. type: 'campus/fetchCampusList',
  51. payload: { ...this.state.Queryers },
  52. });
  53. }
  54. handleCreateOperation = () => {
  55. this.props.dispatch(routerRedux.push({
  56. pathname: '/campus/create',
  57. state: this.state,
  58. }));
  59. }
  60. handleEditOperation = (item) => {
  61. this.props.dispatch(routerRedux.push({
  62. pathname: `/campus/edit/${item.id}`,
  63. state: this.state,
  64. }));
  65. }
  66. handleFilterOperation = (params, states) => {
  67. this.props.dispatch({
  68. type: 'campus/fetchCampusList',
  69. payload: params,
  70. });
  71. this.setState({
  72. UIParams: states,
  73. Queryers: params,
  74. });
  75. }
  76. handleModalFilterOperation = () => {
  77. const { getFieldValue } = this.props.form;
  78. const value = getFieldValue('merchantId');
  79. this.props.dispatch({
  80. type: 'campus/fetchCampusList',
  81. payload: {
  82. ...this.state.Queryers,
  83. merchantId: value[0],
  84. },
  85. });
  86. this.handleFilterModalDestroy();
  87. }
  88. handleBatchOperation = () => {
  89. Message.info('暂不支持批量操作!');
  90. }
  91. handleFilterModalShow = () => {
  92. this.setState({ filterModalDestroy: false });
  93. }
  94. handleFilterModalDestroy = () => {
  95. this.setState({ filterModalDestroy: true });
  96. }
  97. handleRemoteSelectSearch = (value) => {
  98. this.props.dispatch({
  99. type: 'merchant/fetchMerchantList',
  100. payload: {
  101. pageSize: 50,
  102. name: value,
  103. },
  104. });
  105. }
  106. render() {
  107. const { loading, fetching, form, campus, merchant } = this.props;
  108. const { list, totalSize, pageSize, pageNo } = campus;
  109. const { getFieldDecorator } = form;
  110. const renderOperation = (item) => {
  111. return (
  112. <div>
  113. <Button
  114. size="small"
  115. className={styles.editBtn}
  116. onClick={() => this.handleEditOperation(item)}
  117. >编辑
  118. </Button>
  119. </div>
  120. );
  121. };
  122. const batchActions = [{
  123. key: 'delete',
  124. name: '批量删除',
  125. }, {
  126. key: 'recovery',
  127. name: '批量恢复',
  128. }];
  129. const basicSearch = {
  130. keys: [{
  131. name: '校区编号',
  132. field: 'code',
  133. }, {
  134. name: '校区名称',
  135. field: 'name',
  136. }],
  137. };
  138. const pagination = {
  139. pageNo,
  140. pageSize,
  141. totalSize,
  142. };
  143. const columns = [{
  144. title: '校区编号',
  145. key: 1,
  146. dataIndex: 'code',
  147. render: (text, record) => (
  148. <a
  149. className={styles.link}
  150. onClick={() => this.handleEditOperation(record)}
  151. >
  152. {text}
  153. </a>
  154. ),
  155. width: '12%',
  156. }, {
  157. title: '校区名称',
  158. key: 2,
  159. dataIndex: 'name',
  160. render: (text, record) => (
  161. <a
  162. className={styles.link}
  163. onClick={() => this.handleEditOperation(record)}
  164. >
  165. {text}
  166. </a>
  167. ),
  168. width: '34%',
  169. }, {
  170. title: '所属渠道',
  171. key: 3,
  172. dataIndex: 'merchantName',
  173. width: '10%',
  174. }, {
  175. title: '校区联系人',
  176. key: 4,
  177. dataIndex: 'contactName',
  178. width: '10%',
  179. }, {
  180. title: '联系电话',
  181. key: 5,
  182. dataIndex: 'mobile',
  183. width: '12%',
  184. }, {
  185. title: '更新时间',
  186. key: 6,
  187. dataIndex: 'gmtModified',
  188. render: text => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  189. width: '16%',
  190. }, {
  191. title: '操作',
  192. key: 7,
  193. dataIndex: 'operation',
  194. render: (_, record) => renderOperation(record),
  195. width: '6%',
  196. }];
  197. return (
  198. <PageHeaderLayout>
  199. <Card>
  200. <StandardTableList
  201. columns={columns}
  202. loading={loading}
  203. dataSource={addRowKey(list)}
  204. header={{
  205. basicSearch,
  206. onAdvanceFilterClick: this.handleFilterModalShow,
  207. onFilterClick: this.handleFilterOperation,
  208. onCreateClick: this.handleCreateOperation,
  209. }}
  210. footer={{
  211. pagination,
  212. batchActions,
  213. onBatchClick: this.handleBatchOperation,
  214. }}
  215. keepUIState={{ ...this.state.UIParams }}
  216. showStatusSelect={false}
  217. />
  218. {!this.state.filterModalDestroy && (
  219. <Modal
  220. width={600}
  221. visible
  222. title="高级筛选"
  223. okText="筛选"
  224. cancelText="取消"
  225. maskClosable={false}
  226. onCancel={this.handleFilterModalDestroy}
  227. onOk={this.handleModalFilterOperation}
  228. >
  229. <Form>
  230. <Form.Item label="所属商户" {...formItemLayout}>
  231. {getFieldDecorator('merchantId', {
  232. initialValue: [],
  233. })(
  234. <RBRemoteSelect
  235. fetching={fetching}
  236. dataSource={merchantDataFormatter(merchant.list)}
  237. onSearch={this.handleRemoteSelectSearch}
  238. />
  239. )}
  240. </Form.Item>
  241. </Form>
  242. </Modal>
  243. )}
  244. </Card>
  245. </PageHeaderLayout>
  246. );
  247. }
  248. }