import React,{ Component } from "react"; import { Modal,Checkbox,Select,Input,Upload,Button,Icon,message,DatePicker,Tooltip,Radio} from "antd"; import axios from'axios'; import {getUrl,handleDateString,appendFileSizeToUploadFileAll} from 'educoder'; import locale from 'antd/lib/date-picker/locale/zh_CN'; import moment from 'moment'; import Modals from '../../modals/Modals'; const Option = Select.Option; const dateFormat ="YYYY-MM-DD HH:mm" function range(start, end) { const result = []; for (let i = start; i < end; i++) { result.push(i); } return result; } function disabledDateTime() { return { disabledMinutes: () => range(1, 30).concat(range(31, 60)), // disabledSeconds: () => range(1,60) } } function disabledDate(current) { return current && current < moment().endOf('day').subtract(1, 'days'); } class Selectsetting extends Component{ constructor(props){ super(props); this.state={ description:undefined, datalist:undefined, course_groups:undefined, attachment_histories:undefined, datatime:undefined, fileList:[], fileListtype:false, is_public:false } } componentDidMount() { let {discussMessageid} =this.props; let course_id=this.props.course_id; let url="/files/"+discussMessageid+".json"; axios.get(url, { params:{ course_id:course_id, } }) .then((response) => { if(response.status===200){ let newcourse_groups=[]; let list =response.data.course_groups; if(list.length!=0){ list.forEach((item,key)=>{ newcourse_groups.push ({ course_group_id:item.course_group_id, course_group_name:item.course_group_id, publish_time:moment(item.course_group_publish_time).format(dateFormat) }) }) }else{ newcourse_groups.push ({ course_group_id:undefined, course_group_name:undefined, publish_time:"" }) } this.setState({ datalist:response.data, description: response.data.description, is_public: response.data.is_public, datatime:response.data.publish_time, // is_public:response.data.course_groups, //attachment_histories:response.data.attachment_histories course_groups:newcourse_groups }) } }) .catch(function (error) { console.log(error); }); let coursesId=this.props.match.params.coursesId; if(this.props.isAdmin()){ let url = `/courses/${coursesId}/all_course_groups.json` axios.get(url, { }) .then((response) => { this.setState({ course_groupss: response.data.course_groups, }) }) .catch(function (error) { console.log(error); }); } } getalldata=()=>{ } componentDidUpdate = (prevProps) => { if ( prevProps.visible != this.props.visible ) { console.log(prevProps) console.log(this.props) this.setState({ visible:this.props.visible }) this.getalldata() } } settextarea=(e)=>{ this.setState({ description:e.target.value }) } hidecouseShixunModal=()=>{ this.setState({ Modalstype:false, Modalstopval:"", ModalSave:this.hidecouseShixunModal, loadtype:false }) this.props.Cancel() } savecouseShixunModal=()=>{ let {fileList,is_public,description,datatime,course_groups}=this.state; let newfileList=[]; for(var list of fileList){ newfileList.push(list.response.id) } if(description===undefined||description===null){ }else if(description.length>100){ this.setState({ descriptiontypes:true }) return } let coursesId=this.props.match.params.coursesId; let attachmentId=this.props.attachmentId; let url="/files/"+this.props.discussMessageid+".json"; // axios.put(url,{ course_id:coursesId, new_attachment_id:newfileList.length===0?undefined:newfileList, course_second_category_id:this.props.coursesidtype===undefined||this.props.coursesidtype==="node"?0:attachmentId, is_public:is_public, publish_time:unified_setting===true?datatime===undefined?moment(new Date()).format('YYYY-MM-DD HH'):datatime:undefined, description:description, course_group_publish_times:unified_setting===false?course_groups:undefined }).then((result)=>{ if(result.data.status===0){ this.props.setupdate(attachmentId) this.props.showNotification("设置资源成功"); this.hidecouseShixunModal() } }) } onChangeTimepublish= (date, dateString) => { this.setState({ datatime:handleDateString(dateString), }) } // 附件相关 START handleChange = (info) => { if(info.file.status === 'uploading' || info.file.status === 'done' || info.file.status === 'removed') { let fileList = info.fileList; if (info.file.status != "removed") { this.setState({ fileList: appendFileSizeToUploadFileAll(fileList), fileListtype: true }); } else { this.setState({ fileList: appendFileSizeToUploadFileAll(fileList), }); } } } onAttachmentRemove = (file) => { if(!file.percent || file.percent == 100){ 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) { this.setState({ fileListtype:false, fileList:[] }) } } }) .catch(function (error) { console.log(error); }); this.setState({ fileListtype:false, }) }else{ this.setState({ fileListtype:false, fileList:[] }) } } render(){ let {datatime,description,datalist}=this.state; const uploadProps = { width: 600, 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) { this.props.showNotification('文件大小必须小于150MB!'); } return isLt150M; }, }; const radioStyle = { display: 'block', height: '30px', lineHeight: '30px', }; return(
{ this.state.fileListtype===true?"":}
{ this.state.fileListtype===true?
请先上传资源
:""}{this.props.course_is_public===true?
描述不能超过最大限制:100个字符
:""}