MerchantList.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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, Button, message } from 'antd';
  6. import { StandardTableList } from '../../components/RBList';
  7. import Authorized from '../../utils/Authorized';
  8. import { renderStatus, renderCategory, addRowKey } from '../../utils/utils';
  9. import styles from './MerchantList.less';
  10. const Message = message;
  11. @connect(({ loading, merchant }) => ({
  12. merchant,
  13. loading: loading.models.merchant,
  14. }))
  15. export default class MerchantListPage extends Component {
  16. constructor(props) {
  17. super(props);
  18. const { state } = props.location;
  19. this.state = {
  20. UIParams: (state || {}).UIParams, // 组件的状态参数
  21. Queryers: (state || {}).Queryers, // 查询的条件参数
  22. };
  23. }
  24. componentDidMount() {
  25. this.props.dispatch({
  26. type: 'merchant/fetchMerchantList',
  27. payload: { ...this.state.Queryers },
  28. });
  29. }
  30. handleCreateOperation = () => {
  31. this.props.dispatch(routerRedux.push({
  32. pathname: '/merchant/create',
  33. state: this.state,
  34. }));
  35. }
  36. handleDeleteOperation = (item) => {
  37. Modal.confirm({
  38. okText: '确定',
  39. cancelText: '取消',
  40. title: '你确定要删除这条商户记录吗?',
  41. onOk: () => {
  42. this.props.dispatch({
  43. type: 'merchant/deleteMerchantItem',
  44. payload: { id: item.id },
  45. states: this.state,
  46. });
  47. },
  48. });
  49. }
  50. handleEditOperation = (item) => {
  51. this.props.dispatch(routerRedux.push({
  52. pathname: `/merchant/edit/${item.id}`,
  53. state: this.state,
  54. }));
  55. }
  56. handleFilterOperation = (params, states) => {
  57. this.props.dispatch({
  58. type: 'merchant/fetchMerchantList',
  59. payload: params,
  60. });
  61. this.setState({
  62. UIParams: states,
  63. Queryers: params,
  64. });
  65. }
  66. handleDespoitOperation = (item) => {
  67. this.props.dispatch(routerRedux.push({
  68. pathname: `/merchant/despoit/${item.id}`,
  69. state: { ...this.state, currentItem: item },
  70. }));
  71. }
  72. handleBatchOperation = () => {
  73. Message.info('暂不支持批量操作!');
  74. }
  75. render() {
  76. const { loading, merchant } = this.props;
  77. const { list, totalSize, pageSize, pageNo } = merchant;
  78. const renderOperation = (item) => {
  79. return (
  80. <div>
  81. <Authorized authority="root" noMatch={null}>
  82. <Button
  83. size="small"
  84. className={styles.despoitBtn}
  85. onClick={() => this.handleDespoitOperation(item)}
  86. >充值
  87. </Button>
  88. </Authorized>
  89. <Button
  90. size="small"
  91. className={styles.editBtn}
  92. onClick={() => this.handleEditOperation(item)}
  93. >编辑
  94. </Button>
  95. <Button
  96. size="small"
  97. className={styles.deleteBtn}
  98. onClick={() => this.handleDeleteOperation(item)}
  99. >删除
  100. </Button>
  101. </div>
  102. );
  103. };
  104. const batchActions = [{
  105. key: 'delete',
  106. name: '批量删除',
  107. }, {
  108. key: 'recovery',
  109. name: '批量恢复',
  110. }];
  111. const basicSearch = {
  112. keys: [{
  113. name: '商户编号',
  114. field: 'code',
  115. }, {
  116. name: '商户名称',
  117. field: 'name',
  118. }],
  119. };
  120. const pagination = {
  121. pageNo,
  122. pageSize,
  123. totalSize,
  124. };
  125. const columns = [{
  126. title: '商户编号',
  127. key: 1,
  128. dataIndex: 'code',
  129. render: (text, record) => (
  130. <a
  131. className={styles.link}
  132. onClick={() => this.handleEditOperation(record)}
  133. >
  134. {text}
  135. </a>
  136. ),
  137. width: '12%',
  138. }, {
  139. title: '商户名称',
  140. key: 2,
  141. dataIndex: 'name',
  142. render: (text, record) => (
  143. <a
  144. className={styles.link}
  145. onClick={() => this.handleEditOperation(record)}
  146. >
  147. {text}
  148. </a>
  149. ),
  150. width: '16%',
  151. }, {
  152. title: '商户类型',
  153. key: 3,
  154. dataIndex: 'domain',
  155. render: text => renderCategory(text),
  156. width: '11%',
  157. }, {
  158. title: '账户余额(¥)',
  159. key: 4,
  160. dataIndex: 'balance',
  161. width: '12%',
  162. }, {
  163. title: '状态',
  164. key: 5,
  165. dataIndex: 'status',
  166. render: text => renderStatus(text),
  167. width: '11%',
  168. }, {
  169. title: '更新时间',
  170. key: 6,
  171. dataIndex: 'gmtModified',
  172. render: text => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  173. width: '20%',
  174. }, {
  175. title: '操作',
  176. key: 7,
  177. dataIndex: 'operation',
  178. render: (_, record) => renderOperation(record),
  179. width: '18%',
  180. }];
  181. return (
  182. <Card>
  183. <StandardTableList
  184. columns={columns}
  185. loading={loading}
  186. dataSource={addRowKey(list)}
  187. header={{
  188. basicSearch,
  189. onFilterClick: this.handleFilterOperation,
  190. onCreateClick: this.handleCreateOperation,
  191. }}
  192. footer={{
  193. pagination,
  194. batchActions,
  195. onBatchClick: this.handleBatchOperation,
  196. }}
  197. keepUIState={{ ...this.state.UIParams }}
  198. />
  199. </Card>
  200. );
  201. }
  202. }