groupAccount.jsx 10 KB

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