import React,{Component} from "React"; import { Form, Select, Input, Button,Checkbox,Upload,Icon,message,Modal} from "antd"; import {Link} from 'react-router-dom'; import TPMMDEditor from '../../../tpm/challengesnew/TPMMDEditor'; import { WordsBtn,getUrl } from 'educoder'; import axios from 'axios'; import Modals from '../../../modals/Modals'; import '../../css/Courses.css'; const { Option} = Select; const CheckboxGroup = Checkbox.Group; const confirm = Modal.confirm; let GraduationTasksedittype=true; class GraduationTasksedit extends Component{ constructor(props){ super(props) this.state={ coursename:"", coursesearch:"", title_num:60, title_value:"", fileList: [], contents: [{val:"",id:1}], taskid:"", taskneme:"", tasktype:undefined, name:"", description:undefined, } } componentDidMount(){ let tasksid=this.props.match.params.category_id; let url ="/graduation_tasks/"+tasksid+"/edit.json" axios.get(url).then((result)=>{ // console.log(result) let newfilelist=[]; if(result.data.attachments.length!=0){ for(var list of result.data.attachments){ newfilelist.push({ uid:list.id, name:list.title, status: 'done', url:list.url, }) } } this.setState({ fileList:newfilelist, description:result.data.description, tasktype:result.data.task_type, name:result.data.task_name, data:result.data, }) this.props.form.setFieldsValue({ tasktype:result.data.task_type, name:result.data.task_name, }); }).catch((error)=>{ console.log(error) }) } handleSubmit=(e)=>{ let {fileList}=this.state; let listid=[] let graduation_id=this.state.data.graduation_id; for(var list of fileList){ if(list.response!=undefined){ listid.push(list.response.id) }else{ listid.push(list.uid) } } // console.log(listid) e.preventDefault(); if(GraduationTasksedittype===true){ this.props.form.validateFields((err, values) => { if (!err) { if(values.tasktype===undefined){ this.scrollToAnchors("tasktypes"); return } if(values.name===undefined){ this.scrollToAnchors("nametypes"); return } if(values.description===undefined){ this.scrollToAnchors("descriptiontypes"); return }else if(values.description.length>5000){ this.scrollToAnchors("descriptiontypes"); return } console.log('Received values of form: ', values); // console.log(fileList); let tasksid=this.props.match.params.category_id; let url="/graduation_tasks/"+tasksid+".json" axios.put(url, { task_type:parseInt(values.tasktype), name:values.name, description:values.description, attachment_ids:listid, } ).then((response) => { if(response.status===200) { // console.log(response) GraduationTasksedittype=false; // window.location.href="/courses/"+course_id+"/graduation/"+graduationId+"/graduation_tasks/"+category_id+"/questions"; // this.goback() this.props.history.push("/courses/"+this.props.match.params.coursesId+"/graduation_tasks/"+graduation_id+"/"+this.props.match.params.category_id +"/setting"); } }).catch((error) => { console.log(error) }) } }); } } goback=()=>{ // let courseId=this.props.match.params.coursesId; // window.location.href="/courses/"+courseId+"/graduation_tasks/"+this.state.data.graduation_id; // goback = () => { window.history.go(-1) } // 输入title changeTitle=(e)=>{ this.setState({ title_num:60-parseInt(e.target.value.length), title_value:e.target.value }) } // 附件相关 START handleChange = (info) => { let fileList = info.fileList; console.log(fileList) // for(var list of fileList ){ // console.log(fileList) // } this.setState({ fileList }); } 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; } cancelAttachment=()=>{ this.setState({ Modalstype:false, Loadtype:false, Modalstopval:'确定要删除这个附件吗?', ModalSave:"", ModalCancel:"" }) } deleteAttachment = (file) => { this.cancelAttachment(); const url = `/attachments/${file.response ? file.response.id : file.uid}.json` axios.delete(url, { }) .then((response) => { if (response.data) { if ( response.data.status === 0) { this.setState({ Modalstype:false, Modalstopval:response.data.message, ModalSave:this.cancelAttachment, Loadtype:true, }) 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); }); } render(){ const { getFieldDecorator } = this.props.form; let {title_num,pageType,name,description,Loadtype, Modalstype,Modalstopval,ModalCancel,ModalSave} =this.state; let {coursedata}=this.props; let courseId=this.props.match.params.coursesId; let category_id=this.props.match.params.category_id; const uploadProps = { width: 600, // https://github.com/ant-design/ant-design/issues/15505 // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 // showUploadList: false, action: `${getUrl()}/api/attachments.json`, onChange: this.handleChange, onRemove: this.onAttachmentRemove, beforeUpload: (file) => { console.log('beforeUpload', file.name); const isLt150M = file.size / 1024 / 1024 < 150; if (!isLt150M) { message.error('文件大小必须小于150MB!'); } return isLt150M; }, }; return(
{/*提示*/}

{this.props.current_user&&this.props.current_user.course_name} > 毕设任务 > {name===""?"": {name} > } {"编辑"}

编辑毕设任务

返回
{description===undefined?"":
{/*内容*/}
{getFieldDecorator('tasktype', { rules: [{ required: true, message: "请选择任务类型" }], })()} (选择确认后,无法修改) {getFieldDecorator('name', { rules: [{ required: true, message: "请输入标题" }], })()}
{getFieldDecorator('description', { rules: [{ required: true, message: '请输入帖子内容', }, { max: 10000, message: '最大限制为10000个字符', }], })( )} (单个文件150M以内) {/*{attachments&&attachments.map((item,key)=>{*/} {/*return(*/} {/*
*/} {/**/} {/**/} {/**/} {/**/} {/*{item.title}*/} {/**/} {/**/} {/*{item.filesize}*/} {/**/} {/*{item.delete===true?*/} {/*this.onAttachmentRemove(item)}*/} {/*aria-hidden="true">*/} {/*:""}*/} {/*
*/} {/*)*/} {/*})}*/}
取消
}
) } } const GraduationTaskseditApp = Form.create({ name: 'coursesNew' })(GraduationTasksedit); export default GraduationTaskseditApp;