import React, { PureComponent } from 'react'; import { connect } from 'dva'; // import { routerRedux, Link } from 'dva/router'; import { Form, Select, Input, Button, Row, Col, Cascader, Steps, message, Checkbox, Alert } from 'antd'; import bcx_utils from '../../common/bcx_utils'; import { getDistrictData, //省市区选择 publicCommonDictGetDictByCodeTypes, //公共信息 systemRoleIsCharge, //联系人手机验证接口 systemPlatNewsSendVerificationCode, //获取验证码接口 systemPlatNewsVerificationCode, //验证短信验证码接口 systemComBaseInfoSave, //注册接口 publicCommonDictGetInstitutionTypeByIndustryType // 根据行业类型获取机构 } from '../../services/api'; import IconS from '../../components/IconS'; import PCascader from '../../components/Pro/PCascader'; import './EnterpriseRegistration.less'; const FormItem = Form.Item; const { Option } = Select; const { Step } = Steps; @connect(state => ({ register: state.register })) @Form.create() export default class EnterpriseRegistration extends PureComponent { constructor(props, context) { super(props, context); this.state = { count: 0, // areas: [], //省市区 industryType: [], //行业类型 institutionType: [], //机构类型 economicType: [], //经济类型 comType: [], //企业类型 currentInstitutionTypeValue: '' //机构类型所选择值,条件判断下面备注信息使用 }; } /******************************生命周期******************************/ componentDidMount = () => { this.getAllType(); //获取所有类型 // this.getDistrict(); //省市区选择 }; componentWillUnmount = () => { //this.interval && clearInterval(this.interval); clearInterval(this.interval); }; /******************************ajax请求******************************/ // //省市区 // getDistrict = () => { // getDistrictData().then(data => { // const areas = data.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) { systemRoleIsCharge({ 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); } ); }, err => { console.log('验证码处手机号码是否被注册:', err); // message.error("该手机已经注册成为个人用户,不能再注册"); message.error(err); } ); } }; /******************************相关事件******************************/ onGetCaptcha = () => { this.getMobileVerificationCode(); }; //获得行业类型,经济类型,机构类型,企业类型 getAllType = () => { publicCommonDictGetDictByCodeTypes({ codeTypes: ['industryType', 'economicType', 'comType'] }).then(res => { //判断获取数据是否为空 if (res.data) { const allTypeData = res.data; this.setState({ industryType: allTypeData.industryType, economicType: allTypeData.economicType, // institutionType: allTypeData.institutionType, comType: allTypeData.comType }); } }); }; //行业类型选择 renderIndustry = () => { return this.state.industryType.map((val, key) => { return ( ); }); }; // 根据行业类型获取机构 changeIndustry = val => { const { setFieldsValue } = this.props.form; setFieldsValue({ institutionType: undefined }); publicCommonDictGetInstitutionTypeByIndustryType({ industryType: val }).then(res => { if (res.data) { this.setState({ institutionType: res.data }); } }); }; //机构类型选择 renderInstitution = () => { return this.state.institutionType.map((val, key) => { return ( ); }); }; //经济类型选择 renderEconomic = () => { return this.state.economicType.map((val, key) => { return ( ); }); }; //企业类型选择 renderCompany = () => { return this.state.comType.map((val, key) => { return ( ); }); }; handleSubmit = e => { e.preventDefault(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { const { comName, regAddress, economicType, industryType, comType, institutionType } = values; //验证手机号码是否被注册 const mobile = this.props.form.getFieldValue('mobile'); const code = this.props.form.getFieldValue('code'); // const verificationCodeData = { mobile, code }; if (mobile && mobile.length === 11) { systemPlatNewsVerificationCode({ mobile, code }) .then(res => { if (res.retType === '0') { const residence = this.props.form.getFieldValue('residence'); const legalRepPhone = this.props.form.getFieldValue('mobile'); let regprovince; let regcity; let area; if (residence) { [regprovince, regcity, area] = [ residence[0], residence[1], residence[2] ]; } const comBaseInfoDto = { comName, regProvince: regprovince, regCity: regcity, regArea: area, regAddress, economicType, industryType, comType, institutionType, legalRepPhone }; bcx_utils.preventRepeatAsync(callback => callback(resolve => { systemComBaseInfoSave(comBaseInfoDto) .then(submitRes => { resolve(false); // message.success('注册成功!'); this.props.history.push( `EnterpriseRegistrationResult?institution=${ this.state.currentInstitutionTypeValue }` ); }) .catch(dd => { resolve(false); }); }) ); } }) .catch(errs => { // message.error(aa); console.log(errs); }); } } }); }; /******************************render******************************/ render() { const { count } = this.state; const { getFieldDecorator } = this.props.form; const formItemLayout = { labelCol: { xs: { span: 6 }, sm: { span: 6 } }, wrapperCol: { xs: { span: 18 }, sm: { span: 18 } } }; const tailFormItemLayout = { wrapperCol: { xs: { span: 24, offset: 4 }, sm: { span: 20, offset: 4 } } }; return (