import React,{ Component } from "react"; import { Modal,Checkbox,Upload,Button,Icon,message,notification,Input} from "antd"; import { WordsBtn,getUrl, getUploadActionUrl,WordNumberTextarea} from 'educoder'; import axios from 'axios'; import Modals from '../../modals/Modals'; const CheckboxGroup = Checkbox.Group; const { TextArea } = Input; class AccessoryModal extends Component{ constructor(props){ super(props); this.state={ group_ids:[], fileList:[], Modalstype:false, Modalstopval:"", ModalCancel:"", ModalSave:"", loadtype:false, updatas:false, shixunsreplace:false, Errormessage:false, description:undefined } } componentDidMount() { } //勾选实训 shixunhomeworkedit=(list)=>{ this.setState({ group_ids:list }) } // 附件相关 START handleChange = (info) => { let fileList = info.fileList; console.log(fileList) // for(var list of fileList ){ // console.log(fileList) // } this.setState({ fileList:fileList, Errormessage:false, }); } onAttachmentRemove = (file) => { // confirm({ // title: '确定要删除这个附件吗?', // okText: '确定', // cancelText: '取消', // // content: 'Some descriptions', // onOk: () => { // this.deleteAttachment(file) // }, // onCancel() { // console.log('Cancel'); // }, // }); // return false; // this.setState({ // Modalstype:true, // Modalstopval:'确定要删除这个附件吗?', // ModalSave: ()=>this.deleteAttachment(file), // ModalCancel:this.cancelAttachment // }) // return false; if(!file.percent || file.percent == 100){ this.deleteAttachment(file); } } deleteAttachment = (file) => { const url = `/attachments/${file.response ? file.response.id : file.uid}.json` axios.delete(url, { }) .then((response) => { if (response.data) { const { status } = response.data; if (status == 0) { console.log('--- success') this.setState((state) => { const index = state.fileList.indexOf(file); const newFileList = state.fileList.slice(); newFileList.splice(index, 1); return { fileList: newFileList, }; }); } } }) .catch(function (error) { console.log(error); }); } ModalCancelModalCancel=()=>{ this.setState({ Modalstype:false, Modalstopval:"", ModalSave:this.ModalCancelModalCancel, loadtype:false, shixunsreplace:false, }) this.props.Cancel() } Saves=()=>{ let id=this.props.categoryid; let {fileList,description} =this.state; let newfileList=[]; for(var list of fileList){ newfileList.push(list.response.id) } if (newfileList.length == 0) { // this.props.showNotification('请先上传附件') if(this.props.modalname === "补交附件"){ this.setState({ Errormessage:true, shixunsreplace:false, }) }else{ this.setState({ shixunsreplace:true, Errormessage:false, }) } return; }else{ this.setState({ shixunsreplace:false, Errormessage:false, }) } let url= this.props.reviseAttachmentUrl || "/graduation_works/"+id+"/revise_attachment.json" axios.post(url,{ description:description, attachment_ids:newfileList }).then((result)=>{ if(result.data.status===0){ this.props.Cancel() this.props.setupdate() // this.setState({ // Modalstype:true, // Modalstopval:result.data.message, // ModalSave:this.ModalCancelModalCancel, // loadtype:true // }) this.ModalCancelModalCancel() notification.open({ message: '提示', description: '提交成功' }); if(this.props.seeworks!=undefined){ this.props.history.push(this.props.seeworks); } } }).catch((error)=>{ }) } settextarea=(e)=>{ this.setState({ description:e.target.value }) } //确认 hidestartshixunsreplace=()=>{ let id=this.props.categoryid; let {fileList,description} =this.state; let newfileList=[]; for(var list of fileList){ newfileList.push(list.response.id) } let url= this.props.reviseAttachmentUrl || "/graduation_works/"+id+"/revise_attachment.json" axios.post(url,{ description:description, attachment_ids:newfileList }).then((result)=>{ if(result.data.status===0){ this.props.Cancel() this.props.setupdate() // this.setState({ // Modalstype:true, // Modalstopval:result.data.message, // ModalSave:this.ModalCancelModalCancel, // loadtype:true // }) this.ModalCancelModalCancel() notification.open({ message: '提示', description: '提交成功' }); if(this.props.seeworks!=undefined){ this.props.history.push(this.props.seeworks); } } }).catch((error)=>{ }) } //取消 hidestartshixunsreplacetwo=()=>{ this.setState({ shixunsreplace:false, }) } render(){ let {settextarea,fileList, Modalstype, Modalstopval, ModalCancel, ModalSave, loadtype, shixunsreplace, description }=this.state; let {course_groups}=this.props; const uploadProps = { width: 600, // https://github.com/ant-design/ant-design/issues/15505 // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 // showUploadList: false, action: `${getUploadActionUrl()}`, onChange: this.handleChange, onRemove: this.onAttachmentRemove, beforeUpload: (file) => { console.log('beforeUpload', file.name); const isLt150M = file.size / 1024 / 1024 < 150; if (!isLt150M) { this.props.showNotification('文件大小必须小于150MB!'); } return isLt150M; }, }; return(

还未上传附件

是否确认提交作品?

this.hidestartshixunsreplace()}>确认 this.hidestartshixunsreplacetwo()}>取消
{/*提示*/}

(单个文件最大150M)

this.settextarea(e)} value={description} maxlength={100} /> { this.state.Errormessage && this.state.Errormessage === true ?

还未上传附件

: "" } {this.state.updatas===true?请上传附件:""}
) } } export default AccessoryModal;