page.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. }, {
  36. key: 'mobile',
  37. type: 'input',
  38. name: '手机号',
  39. placeholder: '请输入',
  40. option: {
  41. rules: [{ required: true, message: '请输入手机号' }],
  42. normalize: (value) => {
  43. if (this.mobile === value) return value;
  44. if (this.timeout) {
  45. clearTimeout(this.timeout);
  46. this.timeout = null;
  47. }
  48. this.timeout = setTimeout(() => {
  49. User.validMobile({ area: this.formF.getFieldValue(), mobile: value }).then(result => {
  50. this.mobile = value;
  51. this.itemList[1].suffix = !result ? '已注册' : '未注册';
  52. this.formF.setFieldsValue({ load: true });
  53. });
  54. }, 1500);
  55. return value;
  56. },
  57. },
  58. }, {
  59. key: 'nickname',
  60. type: 'input',
  61. name: '昵称',
  62. }, {
  63. key: 'email',
  64. type: 'input',
  65. name: '邮箱',
  66. }];
  67. this.filterForm = [{
  68. key: 'keyword',
  69. type: 'input',
  70. name: 'ID/手机号',
  71. placeholder: '请输入',
  72. }, {
  73. key: 'real',
  74. type: 'select',
  75. allowClear: true,
  76. name: '实名认证',
  77. select: PassSelect,
  78. placeholder: '请选择',
  79. number: true,
  80. }, {
  81. key: 'wechat',
  82. type: 'select',
  83. allowClear: true,
  84. name: '绑定微信',
  85. select: SwitchSelect,
  86. placeholder: '请选择',
  87. number: true,
  88. }, {
  89. key: 'prepare',
  90. type: 'select',
  91. allowClear: true,
  92. name: '备考信息',
  93. select: InputSelect,
  94. placeholder: '请选择',
  95. number: true,
  96. }, {
  97. key: 'time',
  98. type: 'daterange',
  99. name: '注册时间',
  100. }];
  101. this.columns = [{
  102. title: 'ID',
  103. dataIndex: 'id',
  104. }, {
  105. title: '手机号',
  106. dataIndex: 'mobile',
  107. }, {
  108. title: '昵称',
  109. dataIndex: 'nickname',
  110. }, {
  111. title: '注册时间',
  112. dataIndex: 'createTime',
  113. render: (text) => {
  114. return formatDate(text, 'YYYY-MM-DD');
  115. },
  116. }, {
  117. title: '实名认证',
  118. dataIndex: 'realStatus',
  119. render: (text) => {
  120. return PassSelectMap[text ? 1 : 0];
  121. },
  122. }, {
  123. title: '绑定微信',
  124. dataIndex: 'wechatUnionid',
  125. render: (text) => {
  126. return SwitchSelectMap[text ? 1 : 0];
  127. },
  128. }, {
  129. title: '备考信息',
  130. dataIndex: 'prepareStatus',
  131. render: (text) => {
  132. return InputSelectMap[text ? 1 : 0];
  133. },
  134. }, {
  135. title: '操作',
  136. dataIndex: 'handler',
  137. render: (text, record) => {
  138. return <div className="table-button">
  139. {(
  140. <Link to={`/user/detail/${record.id}`}>查看</Link>
  141. )}
  142. </div>;
  143. },
  144. }];
  145. }
  146. initData() {
  147. const { search } = this.state;
  148. const data = Object.assign({}, search);
  149. if (data.time) {
  150. data.startTime = data.time[0] || '';
  151. data.endTime = data.time[1] || '';
  152. }
  153. User.list(data).then(result => {
  154. this.setTableData(result.list, result.total);
  155. });
  156. }
  157. addAction() {
  158. asyncForm('新建', this.itemList, {}, data => {
  159. return User.add(data).then(() => {
  160. asyncSMessage('添加成功!');
  161. this.refresh();
  162. });
  163. }).then(component => {
  164. this.formF = component;
  165. });
  166. }
  167. renderView() {
  168. return <Block flex>
  169. <FilterLayout
  170. show
  171. itemList={this.filterForm}
  172. data={this.state.search}
  173. onChange={data => {
  174. if (data.time.length > 0) {
  175. data.time = [data.time[0].format('YYYY-MM-DD HH:mm:ss'), data.time[1].format('YYYY-MM-DD HH:mm:ss')];
  176. }
  177. this.search(data);
  178. }}
  179. ref={(ref) => {
  180. if (ref) this.filterF = ref;
  181. }} />
  182. <ActionLayout
  183. itemList={this.actionList}
  184. selectedKeys={this.state.selectedKeys}
  185. onAction={key => this.onAction(key)}
  186. />
  187. <TableLayout
  188. // select
  189. columns={this.tableSort(this.columns)}
  190. list={this.state.list}
  191. pagination={this.state.page}
  192. loading={this.props.core.loading}
  193. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  194. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  195. selectedKeys={this.state.selectedKeys}
  196. />
  197. </Block>;
  198. }
  199. }