page.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. if (value === 'service') {
  42. this.filterForm[2].disabled = true;
  43. this.filterForm[3].disabled = false;
  44. this.filterForm[3].select = ServiceParamList[value] || [];
  45. } else {
  46. this.filterForm[2].disabled = false;
  47. this.filterForm[3].disabled = true;
  48. bindSearch(this.filterForm, 'productId', this.filterF, (search) => {
  49. if (value === 'course') {
  50. return Course.list(search);
  51. }
  52. return Course.listData(search);
  53. }, (row) => {
  54. return {
  55. title: row.title,
  56. key: row.id,
  57. };
  58. }, null, null);
  59. }
  60. },
  61. }, {
  62. key: 'productId',
  63. type: 'select',
  64. allowClear: true,
  65. name: '具体名称',
  66. select: [],
  67. }, {
  68. key: 'service',
  69. type: 'select',
  70. allowClear: true,
  71. name: '服务',
  72. select: ServiceKey,
  73. }, {
  74. key: 'source',
  75. type: 'select',
  76. allowClear: true,
  77. name: '开通方式',
  78. select: RecordBuySource,
  79. }, {
  80. key: 'orderId',
  81. type: 'input',
  82. allowClear: true,
  83. name: '订单id',
  84. }];
  85. this.columns = [{
  86. title: '用户ID',
  87. dataIndex: 'userId',
  88. }, {
  89. title: '用户手机',
  90. dataIndex: 'user.mobile',
  91. }, {
  92. title: '用户姓名',
  93. dataIndex: 'user.nickname',
  94. }, {
  95. title: '种类',
  96. dataIndex: 'productType',
  97. render: (text) => {
  98. return `${ProductTypeMainMap[text]}`;
  99. },
  100. }, {
  101. title: '权限',
  102. dataIndex: 'service',
  103. render: (text, record) => {
  104. if (record.productType === 'course') {
  105. return (record.course || {}).title;
  106. }
  107. if (record.productType === 'data') {
  108. return (record.data || {}).title;
  109. }
  110. if (record.productType === 'service') {
  111. return `${ServiceKeyMap[text]}${(ServiceParamRelation[record.service] || {})[text] || ''}`;
  112. }
  113. return '';
  114. },
  115. }, {
  116. title: '开通时间',
  117. dataIndex: 'time',
  118. render: (text, record) => {
  119. return `${record.startTime ? formatDate(record.startTime) : ''} - ${record.endTime ? formatDate(record.endTime) : ''}`;
  120. },
  121. }, {
  122. title: '开通方式',
  123. dataIndex: 'source',
  124. render: (text) => {
  125. return RecordBuySourceMap[text] || '';
  126. },
  127. }, {
  128. title: '购买金额',
  129. dataIndex: 'money',
  130. render: (text, record) => {
  131. return `${formatMoney(text)}${text !== record.originMoney ? `(${formatMoney(record.originMoney)})` : ''}`;
  132. },
  133. }, {
  134. title: '购买时间',
  135. dataIndex: 'createTime',
  136. render: (text) => {
  137. return formatDate(text);
  138. },
  139. }];
  140. bindSearch(this.filterForm, 'userId', this, (search) => {
  141. return User.list(search);
  142. }, (row) => {
  143. return {
  144. title: `${row.nickname}(${row.mobile})`,
  145. value: row.id,
  146. };
  147. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  148. if (this.state.search.productId) {
  149. bindSearch(this.filterForm, 'productId', this.filterF, (search) => {
  150. if (this.state.search.productType === 'course') {
  151. return Course.list(search);
  152. }
  153. return Course.listData(search);
  154. }, (row) => {
  155. return {
  156. title: row.title,
  157. key: row.id,
  158. };
  159. }, Number(this.state.search.productId), null);
  160. this.filterForm[3].disabled = true;
  161. } else if (this.state.search.service) {
  162. this.filterForm[2].disabled = true;
  163. } else {
  164. this.filterForm[2].disabled = true;
  165. this.filterForm[3].disabled = true;
  166. }
  167. }
  168. initData() {
  169. User.listRecord(Object.assign({ needMoney: true, needPackage: false }, this.state.search)).then(result => {
  170. this.setTableData(result.list, result.total);
  171. });
  172. }
  173. renderView() {
  174. return <Block flex>
  175. <FilterLayout
  176. show
  177. itemList={this.filterForm}
  178. data={this.state.search}
  179. onChange={data => {
  180. this.search(data);
  181. }} />
  182. <TableLayout
  183. columns={this.tableSort(this.columns)}
  184. list={this.state.list}
  185. pagination={this.state.page}
  186. loading={this.props.core.loading}
  187. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  188. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  189. selectedKeys={this.state.selectedKeys}
  190. />
  191. </Block>;
  192. }
  193. }