page.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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, ProductTypeMain, RecordBuySource } from '../../../../Constant';
  11. import { User } from '../../../stores/user';
  12. import { Course } from '../../../stores/course';
  13. const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
  14. const ProductTypeMainMap = getMap(ProductTypeMain, 'value', 'label');
  15. const RecordBuySourceMap = getMap(RecordBuySource, 'value', 'label');
  16. // const ServiceParamList = getMap(Object.keys(ServiceParamMap).map(key => {
  17. // return { list: ServiceParamMap[key], key };
  18. // }), 'key', 'list');
  19. const ServiceParamRelation = getMap(Object.keys(ServiceParamMap).map(key => {
  20. return { map: getMap(ServiceParamMap[key], 'value', 'label'), key };
  21. }), 'key', 'map');
  22. export default class extends Page {
  23. init() {
  24. this.filterF = null;
  25. this.filterForm = [{
  26. key: 'userId',
  27. type: 'select',
  28. allowClear: true,
  29. name: '用户',
  30. select: [],
  31. number: true,
  32. placeholder: '请输入',
  33. }, {
  34. key: 'productType',
  35. type: 'select',
  36. allowClear: true,
  37. name: '种类',
  38. select: ProductTypeMain,
  39. onChange: (value) => {
  40. // 根据服务
  41. this.changeSearch(this.filterForm, this, value, null);
  42. },
  43. }, {
  44. key: 'productId',
  45. type: 'select',
  46. allowClear: true,
  47. name: '具体名称',
  48. number: true,
  49. select: [],
  50. }, {
  51. key: 'service',
  52. type: 'select',
  53. allowClear: true,
  54. name: '服务',
  55. select: ServiceKey,
  56. }, {
  57. key: 'source',
  58. type: 'select',
  59. allowClear: true,
  60. name: '开通方式',
  61. select: RecordBuySource,
  62. }, {
  63. key: 'orderId',
  64. type: 'input',
  65. allowClear: true,
  66. name: '订单id',
  67. }];
  68. this.columns = [{
  69. title: '用户ID',
  70. dataIndex: 'userId',
  71. }, {
  72. title: '用户手机',
  73. dataIndex: 'user.mobile',
  74. }, {
  75. title: '用户姓名',
  76. dataIndex: 'user.nickname',
  77. }, {
  78. title: '种类',
  79. dataIndex: 'productType',
  80. render: (text) => {
  81. return `${ProductTypeMainMap[text]}`;
  82. },
  83. }, {
  84. title: '权限',
  85. dataIndex: 'service',
  86. render: (text, record) => {
  87. if (record.productType === 'course') {
  88. return (record.course || {}).title;
  89. }
  90. if (record.productType === 'data') {
  91. return (record.data || {}).title;
  92. }
  93. if (record.productType === 'service') {
  94. return `${ServiceKeyMap[text]}${record.param ? (ServiceParamRelation[record.service] || {})[record.param] || '' : ''}`;
  95. }
  96. return '';
  97. },
  98. }, {
  99. title: '开通时间',
  100. dataIndex: 'time',
  101. render: (text, record) => {
  102. return `${record.startTime ? formatDate(record.startTime, 'YYYY-MM-DD HH:mm:ss') : ''} - ${record.endTime ? formatDate(record.endTime, 'YYYY-MM-DD HH:mm:ss') : ''}`;
  103. },
  104. }, {
  105. title: '开通方式',
  106. dataIndex: 'source',
  107. render: (text) => {
  108. return RecordBuySourceMap[text] || '';
  109. },
  110. }, {
  111. title: '购买金额',
  112. dataIndex: 'money',
  113. render: (text, record) => {
  114. return `${formatMoney(text)}${text !== record.originMoney ? `(${formatMoney(record.originMoney)})` : ''}`;
  115. },
  116. }, {
  117. title: '购买时间',
  118. dataIndex: 'createTime',
  119. render: (text) => {
  120. return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
  121. },
  122. }];
  123. bindSearch(this.filterForm, 'userId', this, (search) => {
  124. return User.list(search);
  125. }, (row) => {
  126. return {
  127. title: `${row.nickname}(${row.mobile})`,
  128. value: row.id,
  129. };
  130. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  131. this.changeSearch(this.filterForm, this, this.state.search.productType, this.state.search.productId);
  132. }
  133. changeSearch(list, component, key, value) {
  134. if (key === 'service') {
  135. list[2].disabled = true;
  136. list[3].disabled = false;
  137. } else if (key === 'course' || key === 'data') {
  138. list[2].disabled = false;
  139. list[3].disabled = true;
  140. bindSearch(list, 'productId', component, (search) => {
  141. if (key === 'course') {
  142. return Course.list(search);
  143. }
  144. return Course.listData(search);
  145. }, (row) => {
  146. return {
  147. title: row.title,
  148. value: row.id,
  149. };
  150. }, value ? Number(value) : null, null);
  151. } else {
  152. list[2].disabled = true;
  153. list[3].disabled = true;
  154. }
  155. component.setState({ load: false });
  156. }
  157. initData() {
  158. User.listRecord(Object.assign({ needMoney: true, needPackage: false }, this.state.search)).then(result => {
  159. this.setTableData(result.list, result.total);
  160. });
  161. }
  162. renderView() {
  163. return <Block flex>
  164. <FilterLayout
  165. show
  166. ref={(ref) => { this.filterF = ref; }}
  167. itemList={this.filterForm}
  168. data={this.state.search}
  169. onChange={data => {
  170. data.page = 1;
  171. this.search(data);
  172. }} />
  173. <TableLayout
  174. columns={this.tableSort(this.columns)}
  175. list={this.state.list}
  176. pagination={this.state.page}
  177. loading={this.props.core.loading}
  178. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  179. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  180. selectedKeys={this.state.selectedKeys}
  181. />
  182. </Block>;
  183. }
  184. }