import React, { PureComponent } from "react"; import { connect } from "dva"; // import { routerRedux, Link } from 'dva/router'; import { Form, Input, Button, Row, Col, Cascader, Steps, message,Checkbox } from "antd"; import "./PersonalRegistration.less"; import { // getDistrictData, //省市区选择 // getDistrictChineseData, systemPerAccountInfoVerificationPhone, //联系人手机验证接口 systemPlatNewsSendVerificationCode, //获取验证码接口 systemPlatNewsVerificationCode, //验证短信验证码接口 systemPerAccountInfoSave //注册接口 } from "../../services/api"; import bcx_utils from "../../common/bcx_utils"; import IconS from "../../components/IconS"; import PCascader from '../../components/Pro/PCascader'; const FormItem = Form.Item; const { Step } = Steps; @connect(state => ({ register: state.register })) @Form.create() export default class PersonalRegistration extends PureComponent { constructor(props, context) { super(props, context); this.state = { count: 0, areas: [] //省市区 }; } /******************************生命周期******************************/ componentDidMount = () => { // this.getDistrict(); //省市区选择 }; componentWillUnmount = () => { clearInterval(this.interval); }; /******************************相关事件******************************/ onGetCaptcha = () => { this.getMobileVerificationCode(); }; /******************************ajax请求******************************/ // //省市区 // getDistrict = () => { // getDistrictData().then(res => { // const areas = res.data.map(val => { // return { // value: val.regionId, // label: val.regionName, // children: val.childs.map(valChild => { // return { // value: valChild.regionId, // label: valChild.regionName, // children: valChild.childs.map(valChildChild => { // return { // value: valChildChild.regionId, // label: valChildChild.regionName // }; // }) // }; // }) // }; // }); // this.setState({ areas }); // }); // }; //获取验证码 getMobileVerificationCode = () => { const mobile = this.props.form.getFieldValue("mobile"); if (!mobile || mobile === null) { message.error("联系手机不能为空!"); } if (mobile && mobile !== null && mobile.length === 11) { systemPerAccountInfoVerificationPhone({ mobile }) .then(() => { let count = 59; this.setState({ count }); this.interval = setInterval(() => { count -= 1; this.setState({ count }); if (count === 0) { clearInterval(this.interval); } }, 1000); systemPlatNewsSendVerificationCode({ mobile }).then( res => { console.log("验证码是否发送成功:", res); }, err => { console.log("获取验证码错误信息:", err); } ); }) .catch(err => { console.log("验证码处手机号码是否被注册:", err); message.error(err); }); } }; handleSubmit = e => { e.preventDefault(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { console.log("Received values of form1111: ", values); } }); //验证手机号码是否被注册 const mobile = this.props.form.getFieldValue("mobile"); const code = this.props.form.getFieldValue("code"); const verificationCodeData = { mobile, code }; if (mobile && mobile.length === 11) { // bcx_utils.preventRepeatAsync(callback => callback((resolve) => { systemPerAccountInfoVerificationPhone({ mobile }).then( res => { if (res.retType === "0") { systemPlatNewsVerificationCode(verificationCodeData).then( codeRes => { if (codeRes.retType === "0") { this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { const residence = this.props.form.getFieldValue( "residence" ); const phone = this.props.form.getFieldValue("mobile"); let province; let city; let area; if (residence) { [province, city = "", area = ""] = [ residence[0], residence[1], residence[2] ]; // province = residence[0]; // city = residence[1]; // area = residence[2]; } const submitData = { phone, province, city, area }; bcx_utils.preventRepeatAsync(callback => callback(resolve => { systemPerAccountInfoSave(submitData).then( submitRes => { resolve(false); if (window.top === window.self) { this.props.history.push( "PersonalRegistrationResult" ); } else { const url = window.location.href.split("#")[0]; window.top.location = url + "#/user/PersonalRegistrationResult"; } }, error => { message.error(error, 2, () => { resolve(false); }); } ); }) ); } }); } }, err => { message.error(err); } ); } }, err => { message.error(err); } ); // })); } }; /******************************render******************************/ render() { const { count } = this.state; const { getFieldDecorator } = this.props.form; const formItemLayout = { labelCol: { xs: { span: 4 }, sm: { span: 4 } }, wrapperCol: { xs: { span: 20 }, sm: { span: 20 } } }; const tailFormItemLayout = { wrapperCol: { xs: { span: 24, offset: 0 }, sm: { span: 18, offset: 4 } } }; return (