page.js 9.8 KB

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