import React, { Component } from "react"; import { Form, Input, Divider, Button, Checkbox, message, Modal } from "antd"; import { FormComponentProps } from "antd/lib/form"; import FormItemDecorator from "@/components/FormItemDecorator"; import InputWarpperUpload from "@/components/InputWarpperUpload"; import ContactForm from "@/components/ContactForm"; import { UploadType } from "@/components/CustComponents/ClampUpload"; import { AddressCascader, CitySelector } from "@/components/CustComponents"; import { CitySelectorType } from "@/components/CustComponents/CitySelector/type"; import { AccountApplyRequest } from "@/api/service/AccountService"; import { ContactEntity } from "@/components/ContactForm"; import { IDistrict } from "@/api/service/DistrictService"; import Api from "@/api"; import { VerifyCompanyNameRequest } from "@/api/service/AccountService"; import { HTTP_STATUS } from "@/shared/common/constants"; type P = FormComponentProps & { agreement: boolean; onSubmit(values); onGoBack(); onAgreement(); onAgreementChange(agreement?: boolean); entity: AccountApplyRequest; companyNameDisabled?: boolean; }; type S = { tipsVisible: boolean; contactEntity: ContactEntity; addressOptions: IDistrict[]; }; let timer = null; class ApplyForm extends Component
{ state = { tipsVisible: false, contactEntity: null, addressOptions: [] }; toggleTipsVisible = () => { const { tipsVisible } = this.state; this.setState({ tipsVisible: !tipsVisible }); }; handleSubmit = e => { e.preventDefault(); const { agreement } = this.props; if (!agreement) { message.warning("请先勾选喜马拉雅开方平台开发者协议"); return false; } const { form } = this.props; form.validateFields((errs, values) => { if (!errs) { this.toggleTipsVisible(); } }); }; onSubmit = () => { const { form, onSubmit, entity } = this.props; const { getFieldValue, getFieldsValue } = form; const values = getFieldsValue(); const { addressOptions } = this.state; const companyAddr = getFieldValue("companyAddr"); const address = addressOptions.map(item => item.label).join("/"); values.companyAddr = address + "-" + companyAddr; if (entity && entity.developerId) { values.developerId = entity.developerId; } onSubmit && onSubmit(values); }; addressChange = (value, options) => { this.setState({ addressOptions: options }); }; companyNameChange = (rule, value, callback) => { if (!value) { return false; } !!timer && clearTimeout(timer); timer = setTimeout(() => { this.verifyCompanyName(value, callback); }, 500); }; verifyCompanyName = (companyName, callback) => { const { entity } = this.props; let params: VerifyCompanyNameRequest = { companyName: companyName }; if (entity && entity.developerId) { params.developerId = +entity.developerId; } Api.account .verifyCompanyName(params) .then(r => { console.log({ r }); if (HTTP_STATUS.SUCCESSS === r.code && r.data) { //验证不通过 callback("该公司名称已注册,请换一个在试。"); } else { callback(); } }) .catch(e => { callback(); }); }; agreementChange = e => { const { checked } = e.target; this.props.onAgreementChange(checked); }; render() { const { form, entity, companyNameDisabled, agreement } = this.props; const { tipsVisible } = this.state; let companyArea = []; if (entity && entity.companyArea) { companyArea = entity.companyArea.split(","); } const contactEntity = { contactName: entity && entity.contactName, // 手机号 contactMobile: entity && entity.contactMobile, // 邮箱 contactEmail: entity && entity.contactEmail }; return ( <>
我已确认信息, 是否确认提交申请?
()(ApplyForm);