groupAccount.jsx 11 KB

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