page.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import Block from '@src/components/Block';
  6. import FilterLayout from '@src/layouts/FilterLayout';
  7. import ActionLayout from '@src/layouts/ActionLayout';
  8. import TableLayout from '@src/layouts/TableLayout';
  9. import { getMap, formatDate } from '@src/services/Tools';
  10. import { asyncSMessage, asyncForm } from '@src/services/AsyncTools';
  11. import { SwitchSelect, PassSelect, InputSelect, MobileArea } from '../../../../Constant';
  12. import { User } from '../../../stores/user';
  13. const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
  14. const PassSelectMap = getMap(PassSelect, 'value', 'label');
  15. const InputSelectMap = getMap(InputSelect, 'value', 'label');
  16. export default class extends Page {
  17. constructor(props) {
  18. super(props);
  19. this.filterF = null;
  20. }
  21. init() {
  22. this.actionList = [{
  23. key: 'add',
  24. type: 'primary',
  25. name: '创建',
  26. }];
  27. this.itemList = [{
  28. key: 'id',
  29. type: 'hidden',
  30. }, {
  31. key: 'area',
  32. type: 'select',
  33. name: '国际码',
  34. select: MobileArea,
  35. required: true,
  36. }, {
  37. key: 'mobile',
  38. type: 'input',
  39. name: '手机号',
  40. placeholder: '请输入',
  41. required: true,
  42. option: {
  43. normalize: (value) => {
  44. if (!value) return 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('area'), mobile: value }).then(result => {
  52. this.mobile = value;
  53. this.itemList[2].suffix = !result ? '已注册' : '未注册';
  54. this.formF.setFieldsValue({ load: true });
  55. });
  56. }, 1500);
  57. return value;
  58. },
  59. },
  60. }, {
  61. key: 'nickname',
  62. type: 'input',
  63. name: '昵称',
  64. }, {
  65. key: 'email',
  66. type: 'input',
  67. name: '邮箱',
  68. }];
  69. this.filterForm = [{
  70. key: 'keyword',
  71. type: 'input',
  72. name: 'ID/手机号',
  73. placeholder: '请输入',
  74. }, {
  75. key: 'real',
  76. type: 'select',
  77. allowClear: true,
  78. name: '实名认证',
  79. select: PassSelect,
  80. placeholder: '请选择',
  81. number: true,
  82. }, {
  83. key: 'wechat',
  84. type: 'select',
  85. allowClear: true,
  86. name: '绑定微信',
  87. select: SwitchSelect,
  88. placeholder: '请选择',
  89. number: true,
  90. }, {
  91. key: 'prepare',
  92. type: 'select',
  93. allowClear: true,
  94. name: '备考信息',
  95. select: InputSelect,
  96. placeholder: '请选择',
  97. number: true,
  98. }, {
  99. key: 'time',
  100. type: 'daterange',
  101. name: '注册时间',
  102. }];
  103. this.columns = [{
  104. title: 'ID',
  105. dataIndex: 'id',
  106. }, {
  107. title: '手机号',
  108. dataIndex: 'mobile',
  109. }, {
  110. title: '昵称',
  111. dataIndex: 'nickname',
  112. }, {
  113. title: '注册时间',
  114. sorter: true,
  115. dataIndex: 'createTime',
  116. render: (text) => {
  117. return formatDate(text, 'YYYY-MM-DD');
  118. },
  119. }, {
  120. title: '实名认证',
  121. dataIndex: 'realStatus',
  122. render: (text) => {
  123. return PassSelectMap[text ? 1 : 0];
  124. },
  125. }, {
  126. title: '绑定微信',
  127. dataIndex: 'wechatUnionid',
  128. render: (text) => {
  129. return SwitchSelectMap[text ? 1 : 0];
  130. },
  131. }, {
  132. title: '备考信息',
  133. dataIndex: 'prepareStatus',
  134. render: (text) => {
  135. return InputSelectMap[text ? 1 : 0];
  136. },
  137. }, {
  138. title: '操作',
  139. dataIndex: 'handler',
  140. render: (text, record) => {
  141. return <div className="table-button">
  142. {(
  143. <Link to={`/user/detail/${record.id}`}>查看</Link>
  144. )}
  145. </div>;
  146. },
  147. }];
  148. }
  149. initData() {
  150. const { search } = this.state;
  151. const data = Object.assign({}, search);
  152. if (data.time) {
  153. data.startTime = data.time[0] || '';
  154. data.endTime = data.time[1] || '';
  155. }
  156. User.list(data).then(result => {
  157. this.setTableData(result.list, result.total);
  158. });
  159. }
  160. addAction() {
  161. asyncForm('新建', this.itemList, {}, data => {
  162. return User.add(data).then(() => {
  163. asyncSMessage('添加成功!');
  164. this.refresh();
  165. });
  166. }).then(component => {
  167. this.formF = component;
  168. });
  169. }
  170. renderView() {
  171. return <Block flex>
  172. <FilterLayout
  173. show
  174. itemList={this.filterForm}
  175. data={this.state.search}
  176. onChange={data => {
  177. if (data.time.length > 0) {
  178. data.time = [data.time[0].format('YYYY-MM-DD HH:mm:ss'), data.time[1].format('YYYY-MM-DD HH:mm:ss')];
  179. }
  180. data.page = 1;
  181. this.search(data);
  182. }}
  183. ref={(ref) => {
  184. if (ref) this.filterF = ref;
  185. }} />
  186. <ActionLayout
  187. itemList={this.actionList}
  188. selectedKeys={this.state.selectedKeys}
  189. onAction={key => this.onAction(key)}
  190. />
  191. <TableLayout
  192. // select
  193. columns={this.tableSort(this.columns)}
  194. list={this.state.list}
  195. pagination={this.state.page}
  196. loading={this.props.core.loading}
  197. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  198. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  199. selectedKeys={this.state.selectedKeys}
  200. />
  201. </Block>;
  202. }
  203. }