page.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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, asyncForm } from '@src/services/AsyncTools';
  10. import { ServiceParamMap, ServiceKey, ServiceSource, MobileArea } 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.actionList = [{
  25. key: 'add',
  26. type: 'primary',
  27. name: '创建',
  28. }];
  29. this.formF = null;
  30. this.itemList = [{
  31. key: 'id',
  32. type: 'hidden',
  33. }, {
  34. key: 'area',
  35. type: 'select',
  36. name: '国际码',
  37. select: MobileArea,
  38. }, {
  39. key: 'mobile',
  40. type: 'input',
  41. name: '手机号',
  42. placeholder: '请输入',
  43. option: {
  44. normalize: (value) => {
  45. if (this.mobile === value) return value;
  46. if (this.timeout) {
  47. clearTimeout(this.timeout);
  48. this.timeout = null;
  49. }
  50. this.timeout = setTimeout(() => {
  51. User.validMobile({ area: this.formF.getFieldValue(), mobile: value }).then(result => {
  52. this.mobile = value;
  53. this.itemList[1].suffix = !result ? '已注册' : '未注册';
  54. this.formF.setFieldsValue({ load: true });
  55. });
  56. }, 1500);
  57. return value;
  58. },
  59. },
  60. }, {
  61. key: 'service',
  62. type: 'select',
  63. name: '开通服务',
  64. select: ServiceKey,
  65. placeholder: '请选择',
  66. onChange: (value) => {
  67. this.itemList[3].select = ServiceParamList[value] || [];
  68. this.formF.setFieldsValue({ param: '' });
  69. },
  70. }, {
  71. key: 'param',
  72. type: 'select',
  73. name: '服务参数',
  74. select: [],
  75. }, {
  76. key: 'source',
  77. type: 'select',
  78. name: '开通方式',
  79. select: ServiceSource,
  80. placeholder: '请选择',
  81. }];
  82. this.filterForm = [{
  83. key: 'userId',
  84. type: 'select',
  85. allowClear: true,
  86. name: '用户',
  87. select: [],
  88. number: true,
  89. placeholder: '请输入',
  90. }, {
  91. key: 'service',
  92. type: 'select',
  93. allowClear: true,
  94. name: '服务',
  95. select: ServiceKey,
  96. onChange: (value) => {
  97. this.filterForm[2].select = ServiceParamList[value] || [];
  98. },
  99. }, {
  100. key: 'param',
  101. type: 'select',
  102. name: '参数',
  103. select: [],
  104. allowClear: true,
  105. notFound: null,
  106. }];
  107. this.columns = [{
  108. title: '用户ID',
  109. dataIndex: 'userId',
  110. }, {
  111. title: '用户手机',
  112. dataIndex: 'user.mobile',
  113. }, {
  114. title: '用户姓名',
  115. dataIndex: 'user.nickname',
  116. }, {
  117. title: '开通服务',
  118. dataIndex: 'service',
  119. render: (text, record) => {
  120. return `${ServiceKeyMap[text]}${(ServiceParamRelation[record.service] || {})[text] || ''}`;
  121. },
  122. }, {
  123. title: '开通时间',
  124. dataIndex: 'time',
  125. render: (text, record) => {
  126. return `${record.startTime ? formatDate(record.startTime) : ''} - ${record.endTime ? formatDate(record.endTime) : ''}`;
  127. },
  128. }, {
  129. title: '开通方式',
  130. dataIndex: 'source',
  131. render: (text) => {
  132. return ServiceSourceMap[text] || '';
  133. },
  134. }, {
  135. title: '累计消费金额',
  136. dataIndex: 'user.totalMoney',
  137. render: (text) => {
  138. return formatMoney(text);
  139. },
  140. }, {
  141. title: '操作',
  142. dataIndex: 'handler',
  143. render: (text, record) => {
  144. return <div className="table-button">
  145. {record.isUsed > 0 && !record.isStop && (
  146. <a onClick={() => {
  147. this.stopAction(record.id);
  148. }}>停用</a>
  149. )}
  150. </div>;
  151. },
  152. },
  153. ];
  154. bindSearch(this.filterForm, 'userId', this, (search) => {
  155. return User.list(search);
  156. }, (row) => {
  157. return {
  158. title: `${row.nickname}(${row.mobile})`,
  159. value: row.id,
  160. };
  161. }, this.state.search.userId ? Number(this.state.search.userId) : [], null);
  162. }
  163. initData() {
  164. User.listService(this.state.search).then(result => {
  165. this.setTableData(result.list, result.total);
  166. });
  167. }
  168. addAction() {
  169. this.itemList[1].disabled = false;
  170. asyncForm('新建', this.itemList, {}, data => {
  171. return User.addService(data).then(() => {
  172. asyncSMessage('添加成功!');
  173. this.refresh();
  174. });
  175. }).then(component => {
  176. this.formF = component;
  177. });
  178. }
  179. // editAction(row) {
  180. // this.itemList[1].disabled = true;
  181. // asyncForm('编辑', this.itemList, row, data => {
  182. // return User.editService(data).then(() => {
  183. // asyncSMessage('编辑成功!');
  184. // this.refresh();
  185. // });
  186. // }).then(component => {
  187. // this.formF = component;
  188. // });
  189. // }
  190. stopAction(id) {
  191. return User.editService({ id, isStop: 1 }).then(() => {
  192. asyncSMessage('停用成功!');
  193. this.refresh();
  194. });
  195. }
  196. renderView() {
  197. return <Block flex>
  198. <FilterLayout
  199. show
  200. itemList={this.filterForm}
  201. data={this.state.search}
  202. onChange={data => {
  203. this.search(data);
  204. }} />
  205. <ActionLayout
  206. itemList={this.actionList}
  207. selectedKeys={this.state.selectedKeys}
  208. onAction={key => this.onAction(key)}
  209. />
  210. <TableLayout
  211. columns={this.columns}
  212. list={this.state.list}
  213. pagination={this.state.page}
  214. loading={this.props.core.loading}
  215. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  216. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  217. selectedKeys={this.state.selectedKeys}
  218. />
  219. </Block>;
  220. }
  221. }