import React, { Component } from 'react'; import { SnackbarHOC } from 'educoder'; import {BrowserRouter as Router,Route,Switch,Link} from 'react-router-dom'; import {Tooltip,Menu,Pagination,Spin, Dropdown,Checkbox} from 'antd'; import axios from 'axios'; import {getImageUrl,WordsBtn} from 'educoder'; import moment from 'moment'; import Modals from '../../modals/Modals'; import SendTopics from '../../modals/SendTopics' import NoneData from '../../courses/coursesPublic/NoneData'; import "./usersInfo.css"; import Withoutpermission from './Withoutpermission.png'; class InfosTopics extends Component{ constructor(props){ super(props); this.state={ isSpin:false, category:"normal", course_list_id:undefined, sort_by:"updated_at", sort_direction:"desc", page:1, data:undefined, checkBoxValues:[], per_page:15, isshowprofes:false } } componentDidMount(){ // let types=this.props.match.params.topicstype; // let professional_certification=this.props.current_user&&this.props.current_user.professional_certification; // // if(professional_certification===false&&types==="publicly"){ // this.setState({ // isshowprofes:true // }) // }else{ // this.updataslist() // } this.updataslist() } // componentDidUpdate(prevProps) { // // if(prevProps.current_user!=this.props.current_user){ // let types=this.props.match.params.topicstype; // let professional_certification=this.props.current_user&&this.props.current_user.professional_certification; // // console.log(professional_certification) // if(professional_certification===false&&types==="publicly"){ // this.setState({ // isshowprofes:true // }) // }else{ // this.updataslist() // } // } // } updataslist=()=>{ let types=this.props.match.params.topicstype; let { category,course_list_id,sort_by,sort_direction,page}=this.state; this.searchAlldata(types,category,course_list_id,sort_by,sort_direction,page) } searchAlldata=(type,category,course_list_id,sort_by,sort_direction,page)=>{ this.setState({ isSpin:true }) let {per_page}=this.state; let url=`/users/question_banks.json`; axios.get(encodeURI(url),{params:{ type, object_type:category, course_list_id, sort_by, sort_direction, page, per_page } }).then((response) => { if(response){ if(response.status){ if(response.data.status == -2){ this.setState({ isshowprofes:true, isSpin:false }) }else if(response.data.status === 403||response.data.status === 401||response.data.status === 500){ this.setState({ isSpin:false }) }else{ this.setState({ data:response.data, checkBoxValues:[], isSpin:false }) } } } }).catch((error) => { this.setState({ isSpin:false }) }); } searchCategory=(type)=>{ this.setState({ category:type, course_list_id:undefined, }) let types=this.props.match.params.topicstype; let { category,course_list_id,sort_by,sort_direction,page}=this.state; this.searchAlldata(types,type,undefined,sort_by,sort_direction,page) } searchCourselistid=(id)=>{ this.setState({ course_list_id:id }) let types=this.props.match.params.topicstype; let { category,course_list_id,sort_by,sort_direction,page}=this.state; this.searchAlldata(types,category,id,sort_by,sort_direction,page) } onCheckBoxChange=(checkedValues)=>{ if(checkedValues.length>15){ this.props.showNotification("选择条数不能大于15条") }else{ this.setState({ checkBoxValues:checkedValues }) } } updatedlist=(updatedtype)=>{ let types=this.props.match.params.topicstype; let { category,course_list_id,sort_by,sort_direction,page}=this.state; if(updatedtype===sort_by){ if(sort_direction==="desc"){ this.setState({ sort_direction:"asc", sort_by:updatedtype }) this.searchAlldata(types,category,course_list_id,updatedtype,"asc",page) }else{ this.setState({ sort_direction:"desc", sort_by:updatedtype }) this.searchAlldata(types,category,course_list_id,updatedtype,"desc",page) } }else{ this.setState({ sort_direction:"desc", sort_by:updatedtype }) this.searchAlldata(types,category,course_list_id,updatedtype,"desc",page) } } changePage=(pageNumber)=>{ let types=this.props.match.params.topicstype; let { category,course_list_id,sort_by,sort_direction,page}=this.state; this.searchAlldata(types,category,course_list_id,sort_by,sort_direction,pageNumber) this.setState({ page:pageNumber, checkBoxValues:[] }) } deletecheckBoxValues=()=>{ let {checkBoxValues}=this.state; if(checkBoxValues.length===0){ this.props.showNotification("请选择题库") }else{ this.setState({ Modalstype:true, Modalstopval:"是否确认删除?", ModalCancel:this.topicscancelmodel, ModalSave:this.topicssavedelete, }) } } topicssavedelete=()=>{ let {checkBoxValues,category}=this.state; const url = `/question_banks/multi_delete.json`; axios.delete(url, { data: { object_id: checkBoxValues, object_type:category }}) .then((response) => { if(response.data.status===0){ this.updataslist() this.props.showNotification(response.data.message) }else{ this.props.showNotification(response.data.message) } }) .catch(function (error) { console.log(error); }); this.topicscancelmodel() } topicscancelmodel=()=>{ this.setState({ Modalstype:false, Loadtype:false, visible:false, Modalstopval:"", ModalCancel:"", ModalSave:"", checkBoxValues:[], checkedtype:false }) } openTopics=(id)=>{ this.setState({ Modalstype:true, Modalstopval:"公开后不能重设为私有", ModalsBottomval:"是否确认设为公开?", ModalCancel:this.topicscancelmodel, ModalSave:()=>this.topicssaveonOpen(id), }) } topicssaveonOpen=(id)=>{ let {category}=this.state; const url = `/question_banks/multi_public.json`; axios.post(url,{ object_id:[id], object_type:category }).then((response) => { if(response.data.status===0){ this.updataslist() this.props.showNotification(response.data.message) }else{ this.props.showNotification(response.data.message) } }).catch(function (error) { console.log(error); }); this.topicscancelmodel() } sendTopics=()=>{ let {checkBoxValues}=this.state; if(checkBoxValues.length===0){ this.props.showNotification("请选择题库") }else{ this.setState({ visible:true }) } } render(){ let{ category, course_list_id, isSpin, data, page, sort_direction, sort_by, checkBoxValues, Modalstype, visible, isshowprofes } = this.state; let { is_current, current_user, }=this.props; let categorylist=[ {val:"普通作业",type:"normal"}, {val:"分组作业",type:"group"}, {val:"毕设选题",type:"gtopic"}, {val:"毕设任务",type:"gtask"}, {val:"试卷",type:"exercise"}, {val:"问卷",type:"poll"}, ] let types=this.props.match.params.topicstype; let username=this.props.match.params.username; //types===publicly 公共 //types===personal 私有 let user_id=this.props.current_user&&this.props.current_user.user_id; let user_type=this.props.current_user&&this.props.current_user.user_identity; let targetuserid=this.props.data&&this.props.data.id; // console.log(is_current) // console.log(current_user) // console.log(current_user.is_teacher) // console.log(current_user.admin) const menu = (
); // console.log(this.props) return(
共 {data&&data.count===undefined?0:data&&data.count} 个 已选择 {checkBoxValues.length} 个 (不支持跨页勾选)
{types==="publicly"?{item.creator_name}:""}
{item.quotes_count} 次引用
{item.solve_count} 次答题
{moment(item.updated_at).fromNow()}
{item.course_list_name===null?"":