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,getUploadActionUrl} 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, Radiovaluetype:false } } componentDidMount() { this.getalldata(); } getalldata=()=>{ 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){ this.setState({ datalist:response.data, description: response.data.description, is_public:response.data.is_public, datatime:response.data.publish_time, Radiovalue:response.data.delay_publish==false?0:1, //attachment_histories:response.data.attachment_histories }) } }) .catch(function (error) { console.log(error); }); } componentDidUpdate = (prevProps) => { if ( prevProps.visible != this.props.visible ) { 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 }) } savecouseShixunModal=()=>{ let {fileList,is_public,description,datatime,Radiovalue}=this.state; let newfileList=[]; for(var list of fileList){ newfileList.push(list.response.id) } if(this.state.Radiovalue===1){ if(datatime===undefined||datatime===null||datatime=== ""){ this.setState({ Radiovaluetype:true }) return }else{ this.setState({ Radiovaluetype:false }) } } 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:Radiovalue===0?undefined:datatime===undefined?moment(new Date(),dateFormat):datatime, description:description, delay_publish:Radiovalue }).then((result)=>{ if(result.data.status===0){ this.hidecouseShixunModal() this.props.setupdate(attachmentId) this.props.showNotification("设置资源成功"); this.props.Cancel() } }) } 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:[] }) } } onChangepublic=(e)=>{ this.setState({ is_public:e.target.checked }) } RadioonChange=(e)=>{ if(e.target.value===0){ this.setState({ datatime:undefined }) } this.setState({ Radiovalue: e.target.value, }); } delectfils=(id)=>{ this.setState({ Modalstype:true, Modalstopval:"是否确定删除该历史资源?", ModalSave:()=>this.delectcousedelectfils(id), ModalCancel:this.hidecouseShixunModal, loadtype:false }) } delectcousedelectfils=(id)=>{ const url = `/attachments/${id}.json?type=history`; axios.delete(url) .then((response) => { if (response.data.status == 0) { // {"status":1,"message":"删除成功"} this.hidecouseShixunModal() this.getalldata() this.props.showNotification(response.data.message); }else{ this.props.showNotification(response.data.message); } }) .catch(function (error) { console.log(error); }); } render(){ let {datatime,description,datalist}=this.state; const uploadProps = { width: 600, 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; }, }; const radioStyle = { display: 'block', height: '30px', lineHeight: '30px', }; return(
{/*提示*/}
  • 资源名称
  • 下载
  • {/*
  • 引用
  • */}
  • 版本号
  • {datalist&&datalist.title} {datalist&&datalist.attachment_histories.length===0?"":当前版本}
  • {datalist&&datalist.downloads_count}
  • {datalist&&datalist.quotes}
  • {moment(datalist&&datalist.created_on).format('YYYY-MM-DD HH:mm')==="Invalid date"?"":moment(datalist&&datalist.created_on).format('YYYY-MM-DD HH:mm')}
  • {datalist&&datalist.attachment_histories.map((item,key)=>{ return(
  • {item.title} {/*当前版本*/}
  • {item.downloads_count}
  • {/*
  • {item.quotes}
  • */}
  • {moment(item.created_on).format('YYYY-MM-DD HH:mm')==="Invalid date"?"":moment(item.created_on).format('YYYY-MM-DD HH:mm')}
  • this.delectfils(item.id)}>
    ) })}

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

    { this.state.fileListtype===true?

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

    {this.state.newfileListtypes===true?

    请先上传资源

    :""}

    {this.props.course_is_public===true?

    公开:this.onChangepublic(e)}> 选中,所有用户可见,否则课堂成员可见
    :""}

    发布设置: this.RadioonChange(e)} value={this.state.Radiovalue} style={{'width': '460px'}}> 立即发布 延期发布 (按照设置的时间定时发布)
    {this.state.descriptiontypes===true?

    描述不能超过最大限制:100个字符

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

    发布时间不能为空

    :""}
    this.props.Cancel()}>取消 确定
    ) } } export default Selectsetting;