page.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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, asyncDelConfirm } from '@src/services/AsyncTools';
  10. import { ServiceParamMap, ServiceKey, MobileArea, RecordSource, ProductTypeMain } 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 RecordSourceMap = getMap(RecordSource, '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.timeout = null;
  25. this.mobile = null;
  26. this.actionList = [{
  27. key: 'addService',
  28. type: 'primary',
  29. name: '添加服务',
  30. }, {
  31. key: 'addData',
  32. type: 'primary',
  33. name: '添加资料',
  34. }];
  35. this.formF = null;
  36. this.serviceList = [{
  37. key: 'id',
  38. type: 'hidden',
  39. }, {
  40. key: 'area',
  41. type: 'select',
  42. name: '国际码',
  43. select: MobileArea,
  44. }, {
  45. key: 'mobile',
  46. type: 'input',
  47. name: '手机号',
  48. placeholder: '请输入',
  49. option: {
  50. normalize: (value) => {
  51. if (this.mobile === value) return value;
  52. if (this.timeout) {
  53. clearTimeout(this.timeout);
  54. this.timeout = null;
  55. }
  56. this.timeout = setTimeout(() => {
  57. User.validMobile({ area: this.formF.getFieldValue(), mobile: value }).then(result => {
  58. this.mobile = value;
  59. this.serviceList[1].suffix = !result ? '已注册' : '未注册';
  60. this.formF.setFieldsValue({ load: true });
  61. });
  62. }, 1500);
  63. return value;
  64. },
  65. },
  66. }, {
  67. key: 'service',
  68. type: 'select',
  69. name: '开通服务',
  70. select: ServiceKey,
  71. placeholder: '请选择',
  72. onChange: (value) => {
  73. this.serviceList[4].select = ServiceParamList[value] || [];
  74. this.serviceList[4].disabled = !this.serviceList[4].select.length;
  75. this.formF.setFieldsValue({ param: '' });
  76. },
  77. }, {
  78. key: 'param',
  79. type: 'select',
  80. name: '服务参数',
  81. select: [],
  82. }];
  83. this.dataList = [{
  84. key: 'id',
  85. type: 'hidden',
  86. }, {
  87. key: 'area',
  88. type: 'select',
  89. name: '国际码',
  90. select: MobileArea,
  91. }, {
  92. key: 'mobile',
  93. type: 'input',
  94. name: '手机号',
  95. placeholder: '请输入',
  96. option: {
  97. normalize: (value) => {
  98. if (this.mobile === value) return value;
  99. if (this.timeout) {
  100. clearTimeout(this.timeout);
  101. this.timeout = null;
  102. }
  103. this.timeout = setTimeout(() => {
  104. User.validMobile({ area: this.formF.getFieldValue(), mobile: value }).then(result => {
  105. this.mobile = value;
  106. this.dataList[1].suffix = !result ? '已注册' : '未注册';
  107. this.formF.setFieldsValue({ load: true });
  108. });
  109. }, 1500);
  110. return value;
  111. },
  112. },
  113. }, {
  114. key: 'dataId',
  115. type: 'select',
  116. name: '开通资料',
  117. select: [],
  118. placeholder: '请选择',
  119. }];
  120. this.filterF = null;
  121. this.filterForm = [{
  122. key: 'userId',
  123. type: 'select',
  124. allowClear: true,
  125. name: '用户',
  126. select: [],
  127. number: true,
  128. placeholder: '请输入',
  129. }, {
  130. key: 'productType',
  131. type: 'select',
  132. allowClear: true,
  133. name: '种类',
  134. select: ProductTypeMain,
  135. onChange: (value) => {
  136. // 根据服务
  137. this.changeSearch(this.filterForm, this.filterF, value, null);
  138. this.filterF.setFieldsValue({ productId: null, service: null });
  139. },
  140. }, {
  141. key: 'productId',
  142. type: 'select',
  143. allowClear: true,
  144. name: '具体名称',
  145. number: true,
  146. select: [],
  147. }, {
  148. key: 'service',
  149. type: 'select',
  150. allowClear: true,
  151. name: '服务',
  152. select: ServiceKey,
  153. }, {
  154. key: 'source',
  155. type: 'select',
  156. allowClear: true,
  157. name: '开通方式',
  158. select: RecordSource,
  159. }];
  160. this.columns = [{
  161. title: '用户ID',
  162. dataIndex: 'userId',
  163. }, {
  164. title: '用户手机',
  165. dataIndex: 'user.mobile',
  166. }, {
  167. title: '用户姓名',
  168. dataIndex: 'user.nickname',
  169. }, {
  170. title: '种类',
  171. dataIndex: 'productType',
  172. render: (text) => {
  173. return `${ProductTypeMainMap[text]}`;
  174. },
  175. }, {
  176. title: '权限',
  177. dataIndex: 'service',
  178. render: (text, record) => {
  179. if (record.productType === 'course') {
  180. return (record.course || {}).title;
  181. }
  182. if (record.productType === 'data') {
  183. return (record.data || {}).title;
  184. }
  185. if (record.productType === 'service') {
  186. return `${ServiceKeyMap[text]}${record.param ? (ServiceParamRelation[record.service] || {})[record.param] || '' : ''}`;
  187. }
  188. return '';
  189. },
  190. }, {
  191. title: '开通时间',
  192. dataIndex: 'time',
  193. render: (text, record) => {
  194. return `${record.startTime ? formatDate(record.startTime) : ''} - ${record.endTime ? formatDate(record.endTime) : ''} `;
  195. },
  196. }, {
  197. title: '开通方式',
  198. dataIndex: 'source',
  199. render: (text) => {
  200. return RecordSourceMap[text] || '';
  201. },
  202. }, {
  203. title: '累计消费金额',
  204. dataIndex: 'user.totalMoney',
  205. render: (text) => {
  206. return formatMoney(text);
  207. },
  208. }, {
  209. title: '操作',
  210. dataIndex: 'handler',
  211. render: (text, record) => {
  212. return <div className="table-button">
  213. {record.isUsed > 0 && !record.isStop && (
  214. <a onClick={() => {
  215. this.stopAction(record.id);
  216. }}>停用</a>
  217. )}
  218. </div>;
  219. },
  220. }];
  221. bindSearch(this.filterForm, 'userId', this, (search) => {
  222. return User.list(search);
  223. }, (row) => {
  224. return {
  225. title: `${row.nickname} (${row.mobile})`,
  226. value: row.id,
  227. };
  228. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  229. this.changeSearch(this.filterForm, this, this.state.search.productType, this.state.search.productId);
  230. }
  231. initFilter() {
  232. }
  233. changeSearch(list, component, key, value) {
  234. if (key === 'service') {
  235. list[2].disabled = true;
  236. list[3].disabled = false;
  237. } else if (key === 'course' || key === 'data') {
  238. list[2].disabled = false;
  239. list[3].disabled = true;
  240. bindSearch(list, 'productId', component, (search) => {
  241. if (key === 'course') {
  242. return Course.list(search);
  243. }
  244. return Course.listData(search);
  245. }, (row) => {
  246. return {
  247. title: row.title,
  248. value: row.id,
  249. };
  250. }, value ? Number(value) : null, null);
  251. } else {
  252. list[2].disabled = true;
  253. list[3].disabled = true;
  254. }
  255. }
  256. initData() {
  257. User.listRecord(Object.assign({ needPackage: false }, this.state.search)).then(result => {
  258. this.setTableData(result.list, result.total);
  259. });
  260. }
  261. addServiceAction() {
  262. asyncForm('新建服务', this.serviceList, {}, data => {
  263. return User.addService(data).then(() => {
  264. asyncSMessage('添加成功!');
  265. this.refresh();
  266. });
  267. }).then(component => {
  268. this.formF = component;
  269. });
  270. }
  271. addDataAction() {
  272. asyncForm('新建资料', this.dataList, {}, data => {
  273. return User.addData(data).then(() => {
  274. asyncSMessage('添加成功!');
  275. this.refresh();
  276. });
  277. }).then(component => {
  278. this.formF = component;
  279. bindSearch(this.dataList, 'dataId', component, (search) => {
  280. return Course.listData(search);
  281. }, (row) => {
  282. return {
  283. title: row.title,
  284. value: row.id,
  285. };
  286. }, null, null);
  287. });
  288. }
  289. stopAction(id) {
  290. asyncDelConfirm('停用确认', '是否停用选中记录?', () => {
  291. return User.stopRecord({ id }).then(() => {
  292. asyncSMessage('停用成功!');
  293. this.refresh();
  294. });
  295. });
  296. }
  297. renderView() {
  298. return <Block flex>
  299. <FilterLayout
  300. show
  301. ref={(ref) => { if (!this.filterF) { this.filterF = ref; } }}
  302. itemList={this.filterForm}
  303. data={this.state.search}
  304. onChange={data => {
  305. this.search(data);
  306. }} />
  307. <ActionLayout
  308. itemList={this.actionList}
  309. selectedKeys={this.state.selectedKeys}
  310. onAction={key => this.onAction(key)}
  311. />
  312. <TableLayout
  313. columns={this.tableSort(this.columns)}
  314. list={this.state.list}
  315. pagination={this.state.page}
  316. loading={this.props.core.loading}
  317. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  318. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  319. selectedKeys={this.state.selectedKeys}
  320. />
  321. </Block>;
  322. }
  323. }