import React from 'react'; import { Form, Input, Tooltip, Icon, Cascader, Select, Row, Col, Checkbox, Button, Spin, message } from 'antd'; import "./account.less"; import ajax from 'jquery/src/ajax/xhr.js' import $ from 'jquery/src/ajax'; import Modal from './modal'; import weixin from '../../../image/weixin-w.png'; import qq from '../../../image/qq-w.png'; import weibo from '../../../image/weibo-w.png'; const FormItem = Form.Item; const Option = Select.Option; const LoginContent = Form.create()(React.createClass({ getInitialState() { return { passwordDirty: false, getCodeButton: true, loading: false, mCodeText: '获取验证码', vCodeUrl: globalConfig.context + '/open/getVCode' }; }, handleSubmit(e) { e.preventDefault(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { this.setState({ loading: true }); $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + "/register", data: { "mobile": values.phone, "password": values.password, "type": 0, "mobileCode": values.phonecaptcha } }).done(function (data) { if (!data.error.length) { message.success('注册成功,5秒后跳转到登录页!'); let interval = setInterval(function () { window.location.href = "./login.html" clearInterval(interval); }, 5000); } else { message.warning(data.error[0].message); this.reloadVCode(); } }.bind(this)).always(function () { this.setState({ loading: false }); }.bind(this)); } }); }, handlePasswordBlur(e) { const value = e.target.value; this.setState({ passwordDirty: this.state.passwordDirty || !!value }); }, checkPassowrd(rule, value, callback) { const form = this.props.form; if (value && value !== form.getFieldValue('password')) { callback('两次密码输入必须相同!'); } else { callback(); } }, checkPhone(rule, value, callback) { const form = this.props.form; const _me = this; if (!(/^1[34578]\d{9}$/.test(value))) { callback('请输入正确的手机号码!'); _me.setState({ getCodeButton: true }); } else { callback(); _me.setState({ getCodeButton: false }); } }, getMCode() { const _me = this; const form = this.props.form; if (!form.getFieldValue('captcha')) { message.warning('图形验证码不能为空!'); return; }; this.setState({ loading: true }); $.ajax({ method: "get", dataType: "json", url: globalConfig.context + "/open/getMCode", data: { "mobile": form.getFieldValue('phone'), "sign": false, "verificationCode": form.getFieldValue('captcha') }, success: function (data) { if (data.error && data.error.length) { message.warning(data.error[0].message); } else { message.success('验证码发送成功!'); this.setState({ getCodeButton: true }); let interval = setInterval(function () { _me.setState({ getCodeButton: false }); clearInterval(interval); }, 60000); let i = 59; let countDown = setInterval(function () { _me.setState({ mCodeText: '剩余' + i + '秒' }); i--; if (i == 0) { clearInterval(countDown); _me.setState({ mCodeText: '获取验证码' }); }; }, 1000); }; }.bind(this) }).always(function () { this.setState({ loading: false }); }.bind(this)); }, checkConfirm(rule, value, callback) { const form = this.props.form; if (value && value.length < 6) { callback('密码长度必须大于或者等于6位!'); }; if (value && this.state.passwordDirty) { form.validateFields(['confirm'], { force: true }); } callback(); }, reloadVCode() { this.setState({ vCodeUrl: globalConfig.context + '/open/getVCode?t=' + Math.random() }) }, closeModal() { this.setState({ showDesc: false }); }, render() { const { getFieldDecorator } = this.props.form; const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 }, }; const tailFormItemLayout = { wrapperCol: { span: 14, offset: 6, }, }; return (