groupAccount.jsx 12 KB

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