groupAccount.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import React from 'react';
  2. import { Form, Input, message, Icon, Cascader, Select, Row, Col, Checkbox, Button, Spin } from 'antd';
  3. import "./group.less";
  4. import ajax from 'jquery/src/ajax/xhr.js'
  5. import $ from 'jquery/src/ajax';
  6. const FormItem = Form.Item;
  7. const Option = Select.Option;
  8. const Group = Form.create()(React.createClass({
  9. getInitialState() {
  10. return {
  11. passwordDirty: false,
  12. getCodeButton: true,
  13. loading: false,
  14. mCodeText: '获取验证码'
  15. };
  16. },
  17. handleSubmit(e) {
  18. e.preventDefault();
  19. this.props.form.validateFieldsAndScroll((err, values) => {
  20. if (!err) {
  21. this.setState({
  22. loading: true
  23. });
  24. $.ajax({
  25. method: "POST",
  26. dataType: "json",
  27. crossDomain: false,
  28. url: globalConfig.context + "/register",
  29. data: {
  30. "mobile": values.phone,
  31. "password": values.password,
  32. "type": 1,
  33. "companyName": values.company,
  34. "contacts": values.user,
  35. "mobileCode": values.phonecaptcha
  36. }
  37. }).done(function (data) {
  38. if (!data.error.length) {
  39. message.success('注册成功,5秒后跳转到登录页!');
  40. let interval = setInterval(function () {
  41. window.location.href = "./login.html?1"
  42. clearInterval(interval);
  43. }, 5000);
  44. } else {
  45. message.warning(data.error[0].message);
  46. document.getElementById('VCode').src = globalConfig.context + '/open/getVCode?t=' + Math.random();
  47. }
  48. }.bind(this)).always(function () {
  49. this.setState({
  50. loading: false
  51. });
  52. }.bind(this));
  53. }
  54. });
  55. },
  56. getMCode() {
  57. const _me = this;
  58. const form = this.props.form;
  59. $.ajax({
  60. method: "get",
  61. dataType: "json",
  62. url: globalConfig.context + "/open/getMCode",
  63. data: {
  64. "mobile": form.getFieldValue('phone'),
  65. "verificationCode": form.getFieldValue('captcha')
  66. },
  67. success: function (data) {
  68. if (data.error && data.error.length) {
  69. message.warning(data.error[0].message);
  70. } else {
  71. message.success('验证码发送成功!');
  72. this.setState({
  73. getCodeButton: true
  74. });
  75. let interval = setInterval(function () {
  76. _me.setState({
  77. getCodeButton: false
  78. });
  79. clearInterval(interval);
  80. }, 60000);
  81. let i = 59;
  82. let countDown = setInterval(function () {
  83. _me.setState({
  84. mCodeText: '剩余' + i + '秒'
  85. });
  86. i--;
  87. if (i == 0) {
  88. clearInterval(countDown);
  89. _me.setState({
  90. mCodeText: '获取验证码'
  91. });
  92. };
  93. }, 1000);
  94. };
  95. }.bind(this)
  96. }).always(function () {
  97. this.setState({
  98. loading: false
  99. });
  100. }.bind(this));
  101. },
  102. handlePasswordBlur(e) {
  103. const value = e.target.value;
  104. this.setState({ passwordDirty: this.state.passwordDirty || !!value });
  105. },
  106. checkPassowrd(rule, value, callback) {
  107. const form = this.props.form;
  108. if (value && value !== form.getFieldValue('password')) {
  109. callback('两次密码输入必须相同!');
  110. } else {
  111. callback();
  112. }
  113. },
  114. checkPhone(rule, value, callback) {
  115. const form = this.props.form;
  116. const _me = this;
  117. if (!(/^1[34578]\d{9}$/.test(value))) {
  118. callback('请输入正确的手机号码!');
  119. _me.setState({
  120. getCodeButton: true
  121. });
  122. } else {
  123. callback();
  124. _me.setState({
  125. getCodeButton: false
  126. });
  127. }
  128. },
  129. checkConfirm(rule, value, callback) {
  130. const form = this.props.form;
  131. if (value && value.length < 6) {
  132. callback('密码长度必须大于或者等于6位!');
  133. };
  134. if (value && this.state.passwordDirty) {
  135. form.validateFields(['confirm'], { force: true });
  136. }
  137. callback();
  138. },
  139. reloadVCode(e) {
  140. e.target.src = globalConfig.context + '/open/getVCode?t=' + Math.random();
  141. },
  142. render() {
  143. const { getFieldDecorator } = this.props.form;
  144. const formItemLayout = {
  145. labelCol: { span: 6 },
  146. wrapperCol: { span: 14 },
  147. };
  148. const tailFormItemLayout = {
  149. wrapperCol: {
  150. span: 14,
  151. offset: 6,
  152. },
  153. };
  154. return (
  155. <div className="group clearfix">
  156. <Form className="account-left" horizontal onSubmit={this.handleSubmit}>
  157. <FormItem
  158. {...formItemLayout}
  159. label="密码"
  160. extra={<span><Icon type="exclamation-circle" /> 建议字母、数字和符号两种以上组合,6-20个字符</span>}
  161. hasFeedback
  162. >
  163. {getFieldDecorator('password', {
  164. rules: [{
  165. required: true, message: '请输入密码!',
  166. }, {
  167. validator: this.checkConfirm,
  168. }],
  169. })(
  170. <Input type="password" onBlur={this.handlePasswordBlur} />
  171. )}
  172. </FormItem>
  173. <FormItem
  174. {...formItemLayout}
  175. label="确认密码"
  176. extra={<span><Icon type="exclamation-circle" /> 请再次输入密码</span>}
  177. hasFeedback
  178. >
  179. {getFieldDecorator('confirm', {
  180. rules: [{
  181. required: true, message: '请再次输入密码!',
  182. }, {
  183. validator: this.checkPassowrd,
  184. }],
  185. })(
  186. <Input type="password" />
  187. )}
  188. </FormItem>
  189. <FormItem
  190. {...formItemLayout}
  191. label="手机号码"
  192. hasFeedback
  193. extra={<span><Icon type="exclamation-circle" /> 请输入正确的手机号码</span>}
  194. >
  195. {getFieldDecorator('phone', {
  196. rules: [{ required: true, message: '请输入手机号码!' }, {
  197. validator: this.checkPhone,
  198. }],
  199. })(
  200. <Input size="large" />
  201. )}
  202. </FormItem>
  203. <FormItem
  204. {...formItemLayout}
  205. label="验证码"
  206. extra={<span className="redFont"><Icon type="exclamation-circle" /> 看不清?点击图片更换验证码</span>}
  207. >
  208. <Row gutter={8}>
  209. <Col span={16}>
  210. {getFieldDecorator('captcha', {
  211. rules: [{ required: true, message: '请输入图片中的验证码' }],
  212. })(
  213. <Input size="large" />
  214. )}
  215. </Col>
  216. <Col span={8}>
  217. <div className="acc-getVcode">
  218. <img id="VCode" src={globalConfig.context + '/open/getVCode'} alt="" onClick={this.reloadVCode} />
  219. </div>
  220. </Col>
  221. </Row>
  222. </FormItem>
  223. <FormItem
  224. {...formItemLayout}
  225. label="手机验证码"
  226. extra={<span><Icon type="exclamation-circle" /> 点击获取后我们将发送验证码到上面手机号</span>}
  227. >
  228. <Row gutter={8}>
  229. <Col span={16}>
  230. {getFieldDecorator('phonecaptcha', {
  231. rules: [{ required: true, message: '请输入手机获取到的验证码' }],
  232. })(
  233. <Input size="large" />
  234. )}
  235. </Col>
  236. <Col span={8}>
  237. <Button size="large" onClick={this.getMCode} disabled={this.state.getCodeButton}>{this.state.mCodeText}</Button>
  238. </Col>
  239. </Row>
  240. </FormItem>
  241. <FormItem
  242. {...formItemLayout}
  243. label="单位名称"
  244. hasFeedback
  245. extra={<span><Icon type="exclamation-circle" /> 请填写工商局注册的全称</span>}
  246. >
  247. {getFieldDecorator('company', {
  248. rules: [{ required: true, message: '请填写公司全称!' }],
  249. })(
  250. <Input size="large" />
  251. )}
  252. </FormItem>
  253. <FormItem
  254. {...formItemLayout}
  255. label="联系人"
  256. hasFeedback
  257. >
  258. {getFieldDecorator('user', {
  259. rules: [{ required: true, message: '请输入联系人姓名!' }],
  260. })(
  261. <Input size="large" />
  262. )}
  263. </FormItem>
  264. <FormItem {...tailFormItemLayout} style={{ marginBottom: 8 }}>
  265. {getFieldDecorator('agreement', {
  266. valuePropName: 'checked',
  267. })(
  268. <Checkbox>同意 <a> 阿凡提会员服务协议条款</a></Checkbox>
  269. )}
  270. </FormItem>
  271. <FormItem {...tailFormItemLayout}>
  272. <Button type="primary" htmlType="submit" size="large">提 交</Button>
  273. </FormItem>
  274. </Form>
  275. </div>
  276. );
  277. },
  278. }));
  279. export default Group;