import React from 'react'; import ajax from 'jquery/src/ajax/xhr.js' import $ from 'jquery/src/ajax'; import { Modal, Button, Icon, Input, message } from 'antd'; import './changeModal.less'; const ChangePw = React.createClass({ getInitialState() { return { visible: false, getCodeButton: false, checkMobile: false, vsCodeSrc: globalConfig.context + '/open/getVCode', mCodeText: '获取验证码' }; }, showModal() { this.setState({ visible: true, }); }, handleOk() { if (!this.state.checkMobile) { message.warning('请输入正确的手机号码!'); } else if (this.state.checkMobile) { $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/user/mobile", data: { "mobile": this.state.mobile, "mobileCode": this.state.mcode } }).done(function (data) { if (!data.error.length) { this.setState({ visible: false, }); message.success('修改成功!3秒后跳转到登录页面,请重新登录!'); setInterval(function () { $.ajax({ method: "get", dataType: "json", url: globalConfig.context + "/login", }).done(function (data) { window.location.href = globalConfig.context + "/user/login.html" }); clearInterval(interval); }, 3000); } else { message.warning(data.error[0].message); }; }.bind(this)); }; }, handleCancel(e) { this.setState({ visible: false, }); }, reloadVCode() { this.setState({ vsCodeSrc: globalConfig.context + '/open/getVCode?t=' + Math.random() }); }, newMobileChange(e) { this.state.mobile = e.target.value; if (/^1[3-9]\d{9}$/.test(this.state.mobile)) { this.state.checkMobile = true } }, mcodeChange(e) { this.state.mcode = e.target.value; }, getMCode() { if (!this.state.checkMobile) { message.warning('请输入正确的手机号码!'); } else if (this.state.checkMobile) { $.ajax({ method: "get", dataType: "json", url: globalConfig.context + "/open/getMCode", data: { "mobile": this.state.mobile, "verificationCode": this.state.Vcode }, success: function (data) { let _me = this; if (data.error && data.error.length) { message.warning(data.error[0].message); this.reloadVCode(); } 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); this.reloadVCode(); }.bind(this), }); } }, render() { return (