page.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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, 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. if (value === 'service') {
  138. this.filterForm[2].disabled = true;
  139. this.filterForm[3].disabled = false;
  140. this.filterForm[3].select = ServiceParamList[value] || [];
  141. } else {
  142. this.filterForm[2].disabled = false;
  143. this.filterForm[3].disabled = true;
  144. bindSearch(this.filterForm, 'productId', this.filterF, (search) => {
  145. if (value === 'course') {
  146. return Course.list(search);
  147. }
  148. return Course.listData(search);
  149. }, (row) => {
  150. return {
  151. title: row.title,
  152. key: row.id,
  153. };
  154. }, null, null);
  155. }
  156. },
  157. }, {
  158. key: 'productId',
  159. type: 'select',
  160. allowClear: true,
  161. name: '具体名称',
  162. select: [],
  163. }, {
  164. key: 'service',
  165. type: 'select',
  166. allowClear: true,
  167. name: '服务',
  168. select: ServiceKey,
  169. }, {
  170. key: 'source',
  171. type: 'select',
  172. allowClear: true,
  173. name: '开通方式',
  174. select: RecordSource,
  175. }];
  176. this.columns = [{
  177. title: '用户ID',
  178. dataIndex: 'userId',
  179. }, {
  180. title: '用户手机',
  181. dataIndex: 'user.mobile',
  182. }, {
  183. title: '用户姓名',
  184. dataIndex: 'user.nickname',
  185. }, {
  186. title: '种类',
  187. dataIndex: 'productType',
  188. render: (text) => {
  189. return `${ProductTypeMainMap[text]}`;
  190. },
  191. }, {
  192. title: '权限',
  193. dataIndex: 'service',
  194. render: (text, record) => {
  195. if (record.productType === 'course') {
  196. return (record.course || {}).title;
  197. }
  198. if (record.productType === 'data') {
  199. return (record.data || {}).title;
  200. }
  201. if (record.productType === 'service') {
  202. return `${ServiceKeyMap[text]}${(ServiceParamRelation[record.service] || {})[text] || ''}`;
  203. }
  204. return '';
  205. },
  206. }, {
  207. title: '开通时间',
  208. dataIndex: 'time',
  209. render: (text, record) => {
  210. return `${record.startTime ? formatDate(record.startTime) : ''} - ${record.endTime ? formatDate(record.endTime) : ''}`;
  211. },
  212. }, {
  213. title: '开通方式',
  214. dataIndex: 'source',
  215. render: (text) => {
  216. return RecordSourceMap[text] || '';
  217. },
  218. }, {
  219. title: '累计消费金额',
  220. dataIndex: 'user.totalMoney',
  221. render: (text) => {
  222. return formatMoney(text);
  223. },
  224. }, {
  225. title: '操作',
  226. dataIndex: 'handler',
  227. render: (text, record) => {
  228. return <div className="table-button">
  229. {record.isUsed > 0 && !record.isStop && (
  230. <a onClick={() => {
  231. this.stopAction(record.id);
  232. }}>停用</a>
  233. )}
  234. </div>;
  235. },
  236. },
  237. ];
  238. bindSearch(this.filterForm, 'userId', this, (search) => {
  239. return User.list(search);
  240. }, (row) => {
  241. return {
  242. title: `${row.nickname}(${row.mobile})`,
  243. value: row.id,
  244. };
  245. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  246. if (this.state.search.productId) {
  247. bindSearch(this.filterForm, 'productId', this.filterF, (search) => {
  248. if (this.state.search.productType === 'course') {
  249. return Course.list(search);
  250. }
  251. return Course.listData(search);
  252. }, (row) => {
  253. return {
  254. title: row.title,
  255. key: row.id,
  256. };
  257. }, Number(this.state.search.productId), null);
  258. this.filterForm[3].disabled = true;
  259. } else if (this.state.search.service) {
  260. this.filterForm[2].disabled = true;
  261. } else {
  262. this.filterForm[2].disabled = true;
  263. this.filterForm[3].disabled = true;
  264. }
  265. }
  266. initData() {
  267. User.listRecord(Object.assign({ needPackage: false }, this.state.search)).then(result => {
  268. this.setTableData(result.list, result.total);
  269. });
  270. }
  271. addServiceAction() {
  272. asyncForm('新建服务', this.serviceList, {}, data => {
  273. return User.addService(data).then(() => {
  274. asyncSMessage('添加成功!');
  275. this.refresh();
  276. });
  277. }).then(component => {
  278. this.formF = component;
  279. });
  280. }
  281. addDataAction() {
  282. asyncForm('新建资料', this.dataList, {}, data => {
  283. return User.addData(data).then(() => {
  284. asyncSMessage('添加成功!');
  285. this.refresh();
  286. });
  287. }).then(component => {
  288. this.formF = component;
  289. bindSearch(this.dataList, 'dataId', component, (search) => {
  290. return Course.listData(search);
  291. }, (row) => {
  292. return {
  293. title: row.title,
  294. value: row.id,
  295. };
  296. }, null, null);
  297. });
  298. }
  299. stopAction(id) {
  300. return User.stopRecord({ id }).then(() => {
  301. asyncSMessage('停用成功!');
  302. this.refresh();
  303. });
  304. }
  305. renderView() {
  306. return <Block flex>
  307. <FilterLayout
  308. show
  309. ref={(ref) => { this.filterF = ref; }}
  310. itemList={this.filterForm}
  311. data={this.state.search}
  312. onChange={data => {
  313. this.search(data);
  314. }} />
  315. <ActionLayout
  316. itemList={this.actionList}
  317. selectedKeys={this.state.selectedKeys}
  318. onAction={key => this.onAction(key)}
  319. />
  320. <TableLayout
  321. columns={this.tableSort(this.columns)}
  322. list={this.state.list}
  323. pagination={this.state.page}
  324. loading={this.props.core.loading}
  325. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  326. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  327. selectedKeys={this.state.selectedKeys}
  328. />
  329. </Block>;
  330. }
  331. }