page.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import Block from '@src/components/Block';
  5. import FilterLayout from '@src/layouts/FilterLayout';
  6. // import ActionLayout from '@src/layouts/ActionLayout';
  7. import TableLayout from '@src/layouts/TableLayout';
  8. import { getMap, formatDate, formatMoney, bindSearch } from '@src/services/Tools';
  9. import { asyncSMessage } from '@src/services/AsyncTools';
  10. import { ServiceParamMap, ServiceKey, ServiceSource } from '../../../../Constant';
  11. import { User } from '../../../stores/user';
  12. const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
  13. const ServiceSourceMap = getMap(ServiceSource, 'value', 'label');
  14. const ServiceParamList = getMap(Object.keys(ServiceParamMap).map(key => {
  15. return { list: ServiceParamMap[key], key };
  16. }), 'key', 'list');
  17. const ServiceParamRelation = getMap(Object.keys(ServiceParamMap).map(key => {
  18. return { map: getMap(ServiceParamMap[key], 'value', 'label'), key };
  19. }), 'key', 'map');
  20. export default class extends Page {
  21. init() {
  22. this.timeout = null;
  23. this.mobile = null;
  24. this.filterForm = [{
  25. key: 'userId',
  26. type: 'select',
  27. allowClear: true,
  28. name: '用户',
  29. select: [],
  30. number: true,
  31. placeholder: '请输入',
  32. }, {
  33. key: 'service',
  34. type: 'select',
  35. allowClear: true,
  36. name: '服务',
  37. select: ServiceKey,
  38. onChange: (value) => {
  39. this.filterForm[2].select = ServiceParamList[value] || [];
  40. },
  41. }];
  42. this.columns = [{
  43. title: '用户ID',
  44. dataIndex: 'userId',
  45. }, {
  46. title: '用户手机',
  47. dataIndex: 'user.mobile',
  48. }, {
  49. title: '用户姓名',
  50. dataIndex: 'user.nickname',
  51. }, {
  52. title: '开通服务',
  53. dataIndex: 'service',
  54. render: (text, record) => {
  55. return `${ServiceKeyMap[text]}${(ServiceParamRelation[record.service] || {})[text] || ''}`;
  56. },
  57. }, {
  58. title: '开通时间',
  59. dataIndex: 'time',
  60. render: (text, record) => {
  61. return `${record.startTime ? formatDate(record.startTime) : ''} - ${record.endTime ? formatDate(record.endTime) : ''}`;
  62. },
  63. }, {
  64. title: '开通方式',
  65. dataIndex: 'source',
  66. render: (text) => {
  67. return ServiceSourceMap[text] || '';
  68. },
  69. }, {
  70. title: '累计消费金额',
  71. dataIndex: 'user.totalMoney',
  72. render: (text) => {
  73. return formatMoney(text);
  74. },
  75. }, {
  76. title: '操作',
  77. dataIndex: 'handler',
  78. render: (text, record) => {
  79. return <div className="table-button">
  80. {record.isUsed > 0 && !record.isStop && (
  81. <a onClick={() => {
  82. this.stopAction(record.id);
  83. }}>停用</a>
  84. )}
  85. </div>;
  86. },
  87. },
  88. ];
  89. bindSearch(this.filterForm, 'userId', this, (search) => {
  90. return User.list(search);
  91. }, (row) => {
  92. return {
  93. title: `${row.nickname}(${row.mobile})`,
  94. value: row.id,
  95. };
  96. }, this.state.search.userId ? Number(this.state.search.userId) : [], null);
  97. }
  98. initData() {
  99. User.listService(this.state.search).then(result => {
  100. this.setTableData(result.list, result.total);
  101. });
  102. }
  103. stopAction(id) {
  104. return User.editService({ id, isStop: 1 }).then(() => {
  105. asyncSMessage('停用成功!');
  106. this.refresh();
  107. });
  108. }
  109. renderView() {
  110. return <Block flex>
  111. <FilterLayout
  112. show
  113. itemList={this.filterForm}
  114. data={this.state.search}
  115. onChange={data => {
  116. this.search(data);
  117. }} />
  118. <TableLayout
  119. columns={this.tableSort(this.columns)}
  120. list={this.state.list}
  121. pagination={this.state.page}
  122. loading={this.props.core.loading}
  123. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  124. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  125. selectedKeys={this.state.selectedKeys}
  126. />
  127. </Block>;
  128. }
  129. }