import React from "react"; import { Upload, message, Button, Icon } from "antd"; import { FormComponentProps, } from "antd/lib/form/Form"; import { FormItemProps } from "antd/lib/form/FormItem"; type P = FormComponentProps & FormItemProps & { onSuccess(data: string[]); }; type S = { // fieldList: object[], name: string; }; const props = { name: "file", showUploadList: false, action: "/portal-provider/batchRecharge/updateExcel" }; class CustomUpload extends React.Component
{ state = { name: "" }; loadTemplate = e => { e.preventDefault(); const origin = location.origin; window.open( `${origin}/portal-provider/batchRecharge/downloadExcelTemplate` ); }; remove = () => { this.setState({ name: "" }); // this.props.onSuccess([]); this.props.form.setFieldsValue({ mobileList:"" }) }; handleChange = info => { console.log(info); this.setState({ name: info.file.name }); if (info.file.status === "done") { const { data, code, message: msg } = info.file.response; if (code === 0) { this.props.onSuccess(data); this.props.form.setFieldsValue({ mobileList:data.join() }) } else { message.error(msg); } } else if (info.file.status === "error") { message.error(`${info.file.name} file upload failed.`); } }; render() { const { name } = this.state; return (
); } } export default CustomUpload;