RegisterForm.js
9.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
import React,{PropTypes} from 'react'
import {reduxForm,Field,submit,SubmissionError, initialize, formValueSelector,getFormValues} from 'redux-form';
import InputField from './widget/reduxForm/InputField';
import {connect} from 'react-redux';
import { Button,Tabs,Steps,Checkbox,Icon } from 'antd';
const TabPane = Tabs.TabPane;
const Step = Steps.Step;
import cx from 'classnames';
import l from './loginFormLess.les';
import { sendLoginSmsCode,doRegister,changeRegisterStatus } from '../redux/actions/authed';
import { required,mobile,minValue,maxLength,number,password } from './widget/reduxForm/validate';
class RegisterForm extends React.Component {
constructor(props) {
super(props);
this.nextStep = this.nextStep.bind(this);
this.prevStep = this.prevStep.bind(this);
this.finishStep = this.finishStep.bind(this);
this.myRegister = this.myRegister.bind(this);
this.changeCheck = this.changeCheck.bind(this);
this.linkLogin = this.linkLogin.bind(this);
this.sendcodeCode = this.sendcodeCode.bind(this);
this.renderStepOne = this.renderStepOne.bind(this);
this.renderStepTwo = this.renderStepTwo.bind(this);
this.renderStepThree = this.renderStepThree.bind(this);
this.subtractCount = this.subtractCount.bind(this);
this.changeMobile = this.changeMobile.bind(this);
this.state={
current :0,
countTime :0,
runCount :false,
init :false,
userMobile:'',
isChecked:false
}
}
componentDidMount() {
}
componentWillReceiveProps(nextProps){
const {myValues,error}=nextProps;
const {current}=myValues;
if(this.props.myValues&&this.props.myValues.current!=current){
this.setState({
current:current
});
}
}
componentWillUnmount(){
clearInterval(this.timer)
}
nextStep(){ //下一步
const { current } = this.state;
const {touch,dispatch,change,valid,submit,myValues={}} = this.props;
dispatch(submit());
if(current>2){
// this.setState({
// current:2
// });
dispatch(change('current',2));
clearInterval(this.timer)
}else if(current<1&&valid){
if(current == 0){
this.sendcodeCode();
}
dispatch(change('current',current +1));
this.setState({
current:current +1
});
}else if(myValues.current==1&&valid){
dispatch(change('current',current +1));
this.setState({
current:2
});
clearInterval(this.timer)
}
}
prevStep(){ //返回上一步
const { current } = this.state;
const {change,dispatch} = this.props;
dispatch(change('current',current-1));
this.setState({
current :Number(current - 1),
init :false,
countTime:0,
runCount :false,
});
clearInterval(this.timer)
}
finishStep(){//提交表单
const { dispatch,submit } = this.props;
dispatch(submit());
}
myRegister(e){//键盘事件
const {dispatch,submit}=this.props;
if(e.keyCode == 13){
dispatch( submit());
}
}
changeCheck(e){
this.setState({
isChecked:e.target.checked
});
}
linkLogin(){
const {dispatch} = this.props;
dispatch(changeRegisterStatus(false))
window.location = '#/login';
}
sendcodeCode(){
clearInterval(this.timer);
const { dispatch,current } = this.props;
const { userMobile } = this.state;
this.setState({
runCount :true,
countTime:60
});
setTimeout(()=>{
dispatch(sendLoginSmsCode({
'mobile':userMobile,
'type':'register',
'scope':'global_access:tenant_admin'
},current));
// dispatch(submit());
},300);
this.timer=setInterval(this.subtractCount,1000);
}
subtractCount(){
const { runCount,countTime } = this.state;
console.log("进入倒计时")
if(runCount&&countTime>0){
this.setState({
countTime:countTime-1
})
}else if(countTime<=0){
this.setState({
runCount:false,
init :true
});
clearInterval(this.timer);
}
}
changeMobile(e){//输入手机号 input
const { dispatch,change } = this.props;
this.setState({
userMobile:e.target.value
});
dispatch(change('mobile',e.target.value));
}
renderStepOne(){ //第一步
const { current,isChecked } = this.state;
return(
<div>
<div className={cx(l.login_tab_content,'login_input')}>
<InputField type='text' name='mobile' onChange={this.changeMobile} optionValue='mobile' placeholder='请输入手机号' />
</div>
<div className={cx(l.step_action,'register_check')}>
<Button disabled={isChecked?false:true} type="primary" onClick={this.nextStep.bind(current)}>下一步</Button>
</div>
<div className={cx(l.step_action,'register_check')}>
<Checkbox checked={isChecked} onChange={this.changeCheck}></Checkbox><a href="https://hropublic.oss-cn-beijing.aliyuncs.com/hro_template/%E3%80%8AWORKAI%E7%94%A8%E6%88%B7%E6%9C%8D%E5%8A%A1%E5%8D%8F%E8%AE%AE%E3%80%8B.doc">我已阅读并同意接受使用《workai使用协议》</a>
<div className={cx(l.register_tip)} onClick={this.linkLogin}>我有账号,直接登录</div>
</div>
</div>
)
}
renderStepTwo(){ //第二步
const { runCount,countTime,init,current } = this.state;
return(
<div>
<div className={cx(l.login_tab_content,'login_input')}>
<InputField type='text' name='sms_code' placeholder='请输入您收到的验证码'/>
<div className={cx('getCode')}>
<Button onClick={this.sendcodeCode.bind(this)} disabled={runCount?true:false}>{runCount?(countTime+' s'):init&&!runCount?'重新获取':'获取验证码'}</Button>
</div>
</div>
<div className={cx(l.step_action,'register_check')}>
<Button type="primary" onClick={this.nextStep.bind(current)}>下一步</Button>
<div className={runCount?cx(l.gray_button):cx(l.register_prev)} onClick={runCount?()=>{}:this.prevStep}>返回上一步</div>
</div>
</div>
)
}
renderStepThree(){ //第三步
return(
<div>
<div className={cx(l.login_tab_content,'login_input')}>
<InputField type='text' name='name' placeholder='请输入公司名称' onKeyUp={this.myRegister}/>
<InputField type='text' name='username' placeholder='请输入姓名' onKeyUp={this.myRegister}/>
<InputField type='password' name='password' placeholder='请设置密码' onKeyUp={this.myRegister} />
</div>
<div className={cx(l.step_action,'register_check')}>
<Button type="primary" onClick={this.finishStep}>完成</Button>
<div className={cx(l.register_prev)} onClick={this.prevStep}>返回上一步</div>
</div>
</div>
)
}
render() {
const { current } = this.state;
const { registerSeccess } =this.props;
return(
<div className={cx('register')}>
{
registerSeccess ?
(
<div style={{textAlign:'center'}}>
<Icon type="check-circle" style={{fontSize:'40px',color:'#3CC43C'}}/>
<div className={cx(l.success_con)}>
您的资料我们已经收到,<br/>
客服将在1 - 3 个工作日内为您开通试用服务。<br/>
您也可以直接拨打400-1616-030电话快速咨询开通。
</div>
<Button type="primary" onClick={this.linkLogin}>确定</Button>
</div>
):(
<div>
<div className={cx(l.register_title)}>
<p style={{display:'inline-block',verticalAlign:'-webkit-baseline-middle'}}>
<span>欢迎注册 WORK AI</span><br/>
<span>互联网转型从这一步开始</span>
</p>
</div>
<Steps size='default' current={current}>
<Step key={0}/>
<Step key={1}/>
<Step key={2}/>
</Steps>
<div>
{
current == 0 ? (this.renderStepOne()):
current == 1 ? (this.renderStepTwo()): (this.renderStepThree())
}
</div>
<InputField type='hidden' name='current'/>
<div style={{color:'red',marginBottom:'8px'}}>{this.props.error}</div>
</div>
)
}
</div>
)
}
}
const submitForm=(values,dispatch,props)=>{
if(values.current=='2'){
return dispatch(doRegister(values));
}
}
const validate=(values,props)=>{
const errors={};
if(values.current=='0'){
if(required(values.mobile)){
errors.mobile=required(values.mobile);
}else if(mobile(values.mobile)){
errors.mobile=mobile(values.mobile);
}
}else if(values.current=='1'){
if(required(values.sms_code)){
errors.sms_code=required(values.sms_code);
}else if(number(values.sms_code)){
errors.sms_code=number(values.sms_code);
}
}else if(values.current=='2'){
if(required(values.name)){
errors.name=required(values.name);
}
if(required(values.username)){
errors.username=required(values.username);
}
if(required(values.password)){
errors.password=required(values.password);
}else if(password(values.password)){
errors.password=password(values.password);
}
}
return errors;
}
const selector = formValueSelector('register_form');
RegisterForm = reduxForm({
form: 'register_form',
onSubmit:submitForm,
validate,
initialValues:{current:'0'}
})(RegisterForm);
const mapState=(state) => {
const {authed:{registerSeccess}}=state;
return {
myValues: getFormValues('register_form')(state),
registerSeccess
};
}
export default connect(mapState)(RegisterForm);