import React,{ Component } from "react"; import { Modal,Checkbox,Select,Input,Spin,Icon} from "antd"; import axios from'axios'; import NoneData from "../coursesPublic/NoneData"; import Modals from '../../modals/Modals'; const Option = Select.Option; const Search = Input.Search; 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/, '') } 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' } } componentDidMount() { this.getallfiles(undefined,1) } componentDidUpdate = (prevProps) => { let {getallfiles}=this.state; if ( prevProps.visible != this.props.visible ) { } } //勾选实训 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; //滑动到底判断 if(e.currentTarget.scrollHeight-e.currentTarget.scrollTop===e.currentTarget.clientHeight){ 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}=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 }) } axios.post(url, { course_id:coursesId, attachment_ids:patheditarry, course_second_category_id:this.props.coursesidtype===undefined||this.props.coursesidtype==="node"?0:attachmentId, } ).then((response) => { if(response.data.status===0){ // this.setState({ // Modalstype:true, // Modalstopval:response.data.message, // ModalSave:this.ModalCancelModalCancel, // loadtype:true // }) this.ModalCancelModalCancel(); this.props.updataleftNavfun(); this.props.showNotification("选用资源成功"); this.props.setupdate(attachmentId) } }).catch((error) => { console.log(error) }) } selectCloseList=(value)=>{ this.setState({ category_id:value }) } render(){ let {Searchvalue,type,category_id,Resourcelist,hometypepvisible,patheditarry}=this.state; let {visible,shixunmodallist}=this.props; const antIcon = ; 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.state.patheditarrytype===true?

    请选择资源

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