MerchantList.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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/AXList';
  7. import PageHeaderLayout from '../../layouts/PageHeaderLayout';
  8. import Authorized from '../../utils/Authorized';
  9. import { renderStatus, renderCategory, addRowKey } from '../../utils/utils';
  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. handleDepositOperation = (item) => {
  67. this.props.dispatch(routerRedux.push({
  68. pathname: `/merchant/deposit/${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="admin" noMatch={null}>
  82. <Button
  83. size="small"
  84. className="editBtn"
  85. onClick={() => this.handleEditOperation(item)}
  86. >编辑
  87. </Button>
  88. <Button
  89. size="small"
  90. className="depositBtn"
  91. onClick={() => this.handleDepositOperation(item)}
  92. >充值
  93. </Button>
  94. </Authorized>
  95. <Button
  96. size="small"
  97. className="delBtn"
  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. width: '12%',
  130. }, {
  131. title: '商户名称',
  132. key: 2,
  133. dataIndex: 'name',
  134. width: '16%',
  135. }, {
  136. title: '商户类型',
  137. key: 3,
  138. dataIndex: 'domain',
  139. render: text => renderCategory(text),
  140. width: '11%',
  141. }, {
  142. title: '账户余额(¥)',
  143. key: 4,
  144. dataIndex: 'balance',
  145. width: '12%',
  146. }, {
  147. title: '状态',
  148. key: 5,
  149. dataIndex: 'status',
  150. render: text => renderStatus(text),
  151. width: '11%',
  152. }, {
  153. title: '更新时间',
  154. key: 6,
  155. dataIndex: 'gmtModified',
  156. render: text => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  157. width: '20%',
  158. }, {
  159. title: '操作',
  160. key: 7,
  161. dataIndex: 'operation',
  162. render: (_, record) => renderOperation(record),
  163. width: '18%',
  164. align: 'right',
  165. }];
  166. return (
  167. <PageHeaderLayout>
  168. <Card>
  169. <StandardTableList
  170. columns={columns}
  171. loading={loading}
  172. dataSource={addRowKey(list)}
  173. header={{
  174. basicSearch,
  175. onFilterClick: this.handleFilterOperation,
  176. onCreateClick: this.handleCreateOperation,
  177. }}
  178. footer={{
  179. pagination,
  180. batchActions,
  181. onBatchClick: this.handleBatchOperation,
  182. }}
  183. keepUIState={{ ...this.state.UIParams }}
  184. />
  185. </Card>
  186. </PageHeaderLayout>
  187. );
  188. }
  189. }