import React,{ Component } from "react"; import { Modal,Checkbox,Upload,Button,Icon,message,DatePicker,Select,Tooltip,Radio} from "antd"; import axios from 'axios'; import Modals from '../../modals/Modals'; import {getUrl,handleDateString,bytesToSize,appendFileSizeToUploadFileAll} from 'educoder'; import locale from 'antd/lib/date-picker/locale/zh_CN'; import moment from 'moment'; const CheckboxGroup = Checkbox.Group; const Option = Select.Option; 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(0,60) } } function disabledDate(current) { return current && current < moment().endOf('day').subtract(1, 'days'); } const dateFormat="YYYY-MM-DD HH:mm"; class Sendresource extends Component{ constructor(props){ super(props); this.state={ group_ids:[], fileList:[], Modalstype:false, Modalstopval:"", ModalCancel:"", ModalSave:"", fileListtype:false, loadtype:false, is_public:false, datatime:undefined, // moment(new Date()).format('YYYY-MM-DD HH:mm:ss'), course_group_publish_times:[ { group_id : undefined, publish_time :undefined, course_group_name:undefined }], course_groups:undefined, course_groups_count:undefined, Radiovalue:0, Radiovaluetype:false } } componentDidMount() { } //勾选实训 shixunhomeworkedit=(list)=>{ this.setState({ group_ids:list }) } // 附件相关 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:[] }) } } ModalCancelModalCancel=()=>{ this.setState({ Modalstype:false, Modalstopval:"", ModalSave:this.ModalCancelModalCancel, loadtype:false }) this.props.Cancel() } Saves=()=>{ let {fileList,description,is_public,datatime,Radiovalue,course_group_publish_times} =this.state; let newfileList=[]; for(var list of fileList){ newfileList.push(list.response.id) } if(newfileList.length===0){ this.setState({ newfileListtype:true }) return } if(this.state.Radiovalue===1&&this.props.course_groups.length===0){ if(datatime===undefined||datatime===null||datatime=== ""){ this.setState({ Radiovaluetype:true }) return }else{ this.setState({ Radiovaluetype:false }) } } if(description===undefined){ }else if(description.length>100){ this.setState({ descriptiontype:true }) return } let coursesId=this.props.match.params.coursesId; let attachmentId=this.props.attachmentId; let url="/files/upload.json"; axios.post(url,{ course_id:coursesId, course_second_category_id:this.props.coursesidtype===undefined||this.props.coursesidtype==="node"?0:attachmentId, attachment_ids:newfileList, is_public:is_public, publish_time:this.props.course_groups.length===0?Radiovalue===1?datatime===undefined? undefined:datatime:undefined:"", description:description, delay_publish:Radiovalue, group_settings:this.props.course_groups.length===0?"":course_group_publish_times }).then((result)=>{ if(result.data.status===0){ this.ModalCancelModalCancel(); this.props.updataleftNavfun(); this.props.showNotification("上传资源成功"); this.props.setupdate(this.props.attachmentId) } }) } settextarea=(e)=>{ this.setState({ description:e.target.value }) } onChangepublic=(e)=>{ this.setState({ is_public:e.target.checked }) } onChangeTimepublish= (date, dateString,key,type) => { if(type===1){ this.setState({ datatime:handleDateString(dateString), }) }else if(type===2){ let {course_group_publish_times}=this.state; let newgroup_publish=course_group_publish_times; for(var i=0; i{ if(e.target.value===0){ this.setState({ datatime:undefined }) } this.setState({ Radiovalue: e.target.value, }); } addgrouppublish=()=>{ let newlist=this.state.course_group_publish_times; newlist.push( { group_id : undefined, publish_time :undefined, course_group_name:undefined }) this.setState({ course_group_publish_times:newlist }) } deletegrouppublish=(key)=>{ let newlist=this.state.course_group_publish_times; newlist.splice(key,1); this.setState({ course_group_publish_times:newlist }) } selectassigngroups=(e,index,key)=>{ let {course_group_publish_times}=this.state; let newgroup_publish=course_group_publish_times; for(var i=0; i { // 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', }; //console.log(this.state.course_group_publish_times) return(
{/*提示*/}

{ this.state.fileListtype===true?"":}

{ this.state.fileListtype===true?

每次只能上传一个资源,
删除下面资源可重新上传 }>
(单个文件最大150M)
:"" } {this.state.fileListtype===false? (单个文件最大150M) :""}

{newfileListtype===true&&this.state.fileListtype===false?

请先上传资源

:""}

{this.props.course_is_public===true?

公开: 选中,所有用户可见,否则课堂成员可见
:""}

发布设置: 立即发布 延期发布 {this.props.course_groups.length===0? this.onChangeTimepublish(e,index,undefined,1)} disabledTime={disabledDateTime} disabledDate={disabledDate} disabled={this.state.Radiovalue===1?false:true} />:""} (按照设置的时间定时发布) {this.props.course_groups.length>0?this.props.isStudent()===true?"":
{this.state.Radiovalue===1?:""} { course_group_publish_times.map((item,key)=>{ return(
this.onChangeTimepublish(e,index,key,2)} // onChange={ this.onChangeTimepublish } disabledTime={disabledDateTime} disabledDate={disabledDate} /> {key!=0?this.deletegrouppublish(key)}>:""} {key+1===this.props.course_groups.length?"":}
) }) }
:""}
{/*{course_group_publish_timestype===true?

请填写完整

:""}*/} {descriptiontype===true?

请输入资源描述,最大限制100个字符

:""} {this.state.Radiovaluetype===true?

发布时间不能为空

:""}
) } } export default Sendresource;