import React,{ Component } from "react"; import { Modal,Checkbox,Select,Input,Spin,Icon,Radio,DatePicker} from "antd"; import locale from 'antd/lib/date-picker/locale/zh_CN'; import axios from'axios'; import {handleDateString} from 'educoder'; import NoneData from "../coursesPublic/NoneData"; import Modals from '../../modals/Modals'; import moment from 'moment'; const Option = Select.Option; const Search = Input.Search; const dateFormat ="YYYY-MM-DD HH:mm" function formatDate(date) { var dateee = new Date(date).toJSON(); return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '') } 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 Selectresource extends Component{ constructor(props){ super(props); this.state={ Searchvalue:undefined, type:'all', category_id:0, page:1, Resourcelist:undefined, hometypepvisible:true, getallfiles:false, searchtype:'getallfiles', Radiovalue:0, datatime:undefined } } componentDidMount() { this.getallfiles(undefined,1) } componentDidUpdate = (prevProps) => { } //勾选实训 shixunhomeworkedit=(list)=>{ this.setState({ patheditarry:list }) } //搜索 SenttotheValue=(e)=>{ this.setState({ Searchvalue:e.target.value, page:1, }) } SenttotheSearch=(value)=>{ let {searchtype}=this.state; if(searchtype==="getallfiles"){ this.getallfiles(value,1) }else if(searchtype==="getmyfiles"){ this.getmyfiles(value,1) } } setupdatalist=(url,newpage)=>{ let {Resourcelist,Searchvalue}=this.state; if(Resourcelist!=undefined){ let newResourcelist=Resourcelist.files; axios.get(url,{ params:{ page:newpage, page_size:15, search:Searchvalue, } }).then((result)=>{ var list=result.data.data.files; for(var i=0;i{ console.log(error) }) } } contentViewScroll=(e)=>{ let {page,searchtype}=this.state; let newscrollTop=parseInt(e.currentTarget.scrollTop); let allclientHeight=e.currentTarget.clientHeight+newscrollTop; //滑动到底判断 if(e.currentTarget.scrollHeight-allclientHeight===0||e.currentTarget.scrollHeight-allclientHeight===1||e.currentTarget.scrollHeight-allclientHeight===-1){ let newpage=page+1; let url if(searchtype==="getallfiles"){ url="/files/public_with_course_and_project.json"; this.setupdatalist(url,newpage) }else if(searchtype==="getmyfiles"){ url="/files/mine_with_course_and_project.json"; this.setupdatalist(url,newpage) } } } //tag changeTag=(types)=>{ this.setState({ type:types, page:1, patheditarry:[], Resourcelist:undefined }) // this.props.funshixunmodallist(Searchvalue,types,true,1) // this.props.funpatheditarry([]) if(types==="all"){ this.getallfiles(undefined,1) }else if(types==="my"){ this.getmyfiles(undefined,1) } } getallfiles=(value,page)=>{ let url = "/files/public_with_course_and_project.json"; axios.get(url,{ params:{ page:1, page_size:15, search:value, } }).then((result)=>{ this.setState({ Resourcelist:result.data.data, hometypepvisible:false, getallfiles:true, searchtype:'getallfiles' }) }).catch((error)=>{ console.log(error) }) } getmyfiles=(value,page)=>{ let url = "/files/mine_with_course_and_project.json"; axios.get(url,{ params:{ page:1, page_size:15, search:value, } }).then((result)=>{ this.setState({ Resourcelist: result.data.data, hometypepvisible:false, searchtype:'getmyfiles' }) }).catch((error)=>{ console.log(error) }) } hidecouseShixunModal=()=>{ this.props.hidecouseShixunModal() } ModalCancelModalCancel=()=>{ this.setState({ Modalstype:false, visible:false, Modalstopval:"", ModalSave:this.ModalCancelModalCancel, loadtype:false }) this.props.hidecouseShixunModal() } savecouseShixunModal=()=>{ let {patheditarry,datatime,Radiovalue}=this.state; let {coursesId,attachmentId}=this.props; let url="/files/import.json"; if(patheditarry===undefined||patheditarry.length===0){ this.setState({ patheditarrytype:true }) return }else{ this.setState({ patheditarrytype:false }) } if(this.state.Radiovalue===1){ if(datatime===undefined||datatime===null||datatime=== ""){ this.setState({ Radiovaluetype:true }) return }else{ this.setState({ Radiovaluetype:false }) } } axios.post(url, { course_id:coursesId, attachment_ids:patheditarry, course_second_category_id:this.props.coursesidtype===undefined||this.props.coursesidtype==="node"?0:attachmentId, delay_publish:Radiovalue, publish_time:Radiovalue===1?datatime:undefined } ).then((response) => { if(response.data.status===0){ this.ModalCancelModalCancel(); this.props.updataleftNavfun(); this.props.showNotification("选用资源成功"); this.props.setupdate(attachmentId) } }).catch((error) => { console.log(error) }) } RadioonChange=(e)=>{ if(e.target.value===0){ this.setState({ datatime:undefined }) } this.setState({ Radiovalue: e.target.value, }); } onChangeTimepublish= (date, dateString) => { this.setState({ datatime:handleDateString(dateString), }) } render(){ let {Searchvalue,type,Resourcelist,hometypepvisible,patheditarry,datatime}=this.state; let {visible}=this.props; const antIcon = ; const radioStyle = { display: 'block', height: '30px', lineHeight: '30px', }; return(
{/*提示*/} {visible===true?
  • 资源名称
  • 大小
  • 发布人
  • 时间
{ Resourcelist === undefined ?"":Resourcelist.files.length===0?: { Resourcelist.files.map((item,key)=>{ return(
  • {item.filesize}
  • {item.author.name}
  • {formatDate(item.created_on)}
  • ) }) }
    }
    发布设置: 立即发布 延迟发布 this.onChangeTimepublish(e,index,undefined,1)} disabledTime={disabledDateTime} disabledDate={disabledDate} disabled={this.state.Radiovalue===1?false:true} /> (按照设置的时间定时发布)
    {this.state.patheditarrytype===true?

    请选择资源

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

    发布时间不能为空

    :""}
    :""}
    ) } } export default Selectresource;