page.js 5.4 KB

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