import React,{ Component } from "react"; import {Form,Checkbox,DatePicker,Button,Input,Select,Tooltip} from "antd"; import { handleDateString } from 'educoder'; import PollDetailTabForthRules from '../poll/PollDetailTabForthRules'; import '../css/members.css'; import '../css/busyWork.css'; import '../poll/pollStyle.css'; import moment from 'moment'; import locale from 'antd/lib/date-picker/locale/zh_CN'; import axios from 'axios'; import Modals from '../../modals/Modals'; const Search=Input.Search; 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 { // disabledHours: () => range(0, 24).splice(4, 20), disabledMinutes: () => range(1, 30).concat(range(31, 60)), // disabledSeconds: () => [0, 60], }; } function disabledDate(current) { return current && current < moment().endOf('day').subtract(1, 'days'); } const dataformat="YYYY-MM-DD HH:mm"; class Exercisesetting extends Component{ constructor(props){ super(props); this.state={ flagPageEdit:undefined, flagPublic:undefined, flagRealName:undefined, unified_list:undefined, course_group:undefined, end_time:undefined, publish_time:undefined, unit_p_tip:"", unit_e_tip:"", rules:undefined, p_flag:true, e_flag:true, polls:undefined, //公用提示弹框相关 modalsType:false, modalsTopval:"", loadtype:false, modalSave:undefined, firstSetting:true, score_open:false, answer_open:false, unified_setting:true, show_statistic:false, question_random:true, choice_random:true, time:0, publish_timetype:false, end_timetype:false, exercise_group_id:[], page:1, limit:10, searchtext:"", order: "end_at", } console.log("Exercisesetting"); console.log("69"); console.log(props); } _getRequestParams() { const { order, exercise_group_id,searchtext, page ,limit} = this.state return { page, search:searchtext, order, limit: limit, group_id:exercise_group_id, } } //加载 componentDidMount=()=>{ this.getSettingInfo(); // window.addEventListener('click', this.handleClick); try { this.props.triggerRef(this); }catch (e) { } if(this.props.Commonheadofthetestpaper!=undefined){ this.editSetting() } if(this.props.isAdmin() === false){ this.cancelEdit() } } componentDidUpdate = (prevProps) => { if(prevProps.Commonheadofthetestpaper!= this.props.Commonheadofthetestpaper){ this.editSetting() } } _getRequestParams() { const { order, exercise_group_id,searchtext, page ,limit} = this.state return { page, search:searchtext, order, limit: limit, group_id:exercise_group_id, } } // handleClick=(e)=>{ // console.log(e); // } // 已有设置数据的查询 getSettingInfo=()=>{ let Id=this.props.match.params.Id; let url=`/exercises/${Id}/exercise_setting.json`; axios.get(url).then((result)=>{ if(result.status==200){ this.props.form.setFieldsValue({ time:result.data.exercise.time===-1?"":result.data.exercise.time, }); this.setState({ polls:result.data.exercise, flagPublic:result.data.exercise.is_public, flagRealName:result.data.exercise.un_anonymous, unified_list:result.data.published_course_groups, course_group:result.data.course_groups, publish_time:result.data.exercise.publish_time, end_time:result.data.exercise.end_time, firstSetting:result.data.published_course_groups.length==0 && result.data.exercise.publish_time == null && result.data.exercise.end_time==null, score_open:result.data.exercise.score_open, answer_open:result.data.exercise.answer_open, unified_setting:result.data.exercise.unified_setting, show_statistic:result.data.exercise.show_statistic, question_random:result.data.exercise.question_random, choice_random:result.data.exercise.choice_random, time:result.data.exercise.time, ...result.data.exercise }) if(result.data.exercise.unified_setting == true && moment(result.data.exercise.publish_time) <= moment()){ // if(this.props.isSuperAdmin()===true){ // this.setState({ // publish_timetype:false // }) // }else{ //发布后谁都不能改 this.setState({ publish_timetype:true }) // } } if(result.data.exercise.unified_setting == true && moment(result.data.exercise.end_time) <= moment()){ // if(this.props.isSuperAdmin()===true){ // this.setState({ // end_timetype:false // }) // }else{ this.setState({ end_timetype:true }) // } } let group=result.data.published_course_groups; if(group.length==0){ let list= [{ course_group_id:[], course_group_name:[], publish_time:undefined, end_time:undefined, publish_flag:"", end_flag:"", class_flag:"", course_search:"", poll_status:0, open:false }] this.setState({ rules:list }) }else{ let array=[]; for(var i=0;i{ console.log(error); }) } //提交form表单 handleSubmit = (e) => { e.preventDefault(); if(this.props&&this.props.Commonheadofthetestpaper.exercise_status){ console.log("190"); console.log(this.props.Commonheadofthetestpaper.exercise_status); } this.props.form.validateFieldsAndScroll((err, values) => { if(!err){ // 第一次进行问卷设置或者勾选了统一设置 let{unified_setting}=this.state if(unified_setting==true){ console.log("统一设置"); this.UnifiedSetting(); }else{ console.log("非统一设置"); this.NotUnifiedSetting(); } } }) } //跳转道描点的地方 scrollToAnchor = (anchorName) => { if (anchorName) { // 找到锚点 let anchorElement = document.getElementById(anchorName); // 如果对应id的锚点存在,就跳转到锚点 if(anchorElement) { anchorElement.scrollIntoView(); } } } UnifiedSetting=()=>{ let { unit_e_tip , unit_p_tip , publish_time , end_time ,course_group }=this.state // 如果两个时间都没有填写或者只选择了截止时间则先保存设置然后弹出立即发布弹框 if ( publish_time === undefined ||publish_time === null ){ this.setState({ unit_p_tip:"不能为空" }) this.scrollToAnchor("publishtimeid"); return // if(moment(end_time,dataformat)<=moment()){ // this.setState({ // unit_e_tip:"截止时间不能小于当前时间" // }) // }else{ // this.setState({ // unit_e_tip:"" // }) // let list=[]; // let group=course_group; // if(group.length>0){ // for(var i=0;i 0 ? 1 : 2, // visible:true, // Topval:"本操作只对“未发布”的对象生效", // Botvalleft:"暂不发布", // Botval:"则通过后续手动设置,定时发布", // starttime:"发布时间:"+this.props.getNowFormatDates(1), // endtime:"截止时间:" + moment(end_time == "" || end_time ==undefined ? this.props.getNowFormatDates(2):end_time).format(dataformat), // Cancelname:"暂不发布", // Savesname:"立即发布", // Cancel:this.homeworkhide, // Saves:this.homeworkstartend, // publishCourse:list, // publish_time:this.props.getNowFormatDates(1) // }) // } }else{ if(this.state.publish_timetype === false){ if(moment(publish_time,dataformat) < moment() ){ this.setState({ unit_p_tip:"发布时间不能小于当前时间" }) return; }else{ this.setState({ unit_p_tip:"" }) } } if(this.state.end_timetype === false){ if(moment(end_time,dataformat) <= moment(publish_time,dataformat)){ this.setState({ unit_e_tip:"截止时间不能小于发布时间" }) return; }else if(moment(end_time,dataformat)<=moment()){ this.setState({ unit_e_tip:"截止时间不能小于当前时间" }) return; }else{ this.setState({ unit_e_tip:"" }) } } this.commitSetting((result)=>{ console.log(result) if(result.status==200){ this.props.showNotification(`${result.data.message}`); this.getSettingInfo(); this.cancelEdit(); } }) } } // 非统一设置提交 NotUnifiedSetting=()=>{ const result = this.refs.pollDetailTabForthRules.exerciseSettingCheck(this.state.rules); this.setState({ rules: result.rules }) if(result.validate==false){ return; } this.commitSetting((result)=>{ console.log(result) if(result.status==200){ this.props.showNotification(`${result.data.message}`); this.cancelEdit(); this.getSettingInfo(); } }); } commitSetting=(callback)=>{ let exercise_id=this.props.match.params.Id; let url=`/exercises/${exercise_id}/commit_setting.json`; let params=[]; if(this.state.unified_setting){ params={ unified_setting:this.state.unified_setting, publish_time:this.state.publish_time, end_time:this.state.end_time, show_statistic:this.state.show_statistic, choice_random:this.state.choice_random, score_open:this.state.score_open, answer_open:this.state.answer_open, question_random:this.state.question_random, time:this.state.time, } }else{ let list=this.state.rules; let lists=[] list.map((item,key)=>{ let newlist={ course_group_id:item.course_group_id, publish_time:item.publish_time, end_time:item.end_time } lists.push(newlist) }) params={ unified_setting:this.state.unified_setting, show_statistic:this.state.show_statistic, question_random:this.state.question_random, choice_random:this.state.choice_random, score_open:this.state.score_open, answer_open:this.state.answer_open, publish_time_groups:lists, time:this.state.time, } } axios.post((url),params).then((result)=>{ callback(result); }).catch((error)=>{ console.log(error); }) } rulesCheckInfo=(rules)=>{ this.setState({ rules }) } cancelBox=()=>{ this.setState({ modalsType:false, modalsTopval:"", loadtype:false, }) } // 是否统一设置 changeUnit=(e)=>{ this.setState({ unified_setting:e.target.checked }) } //是否公开统计 ChangeFlagPublic=(e)=>{ this.setState({ score_open:e.target.checked }) } //是否实名问卷 ChangeFlagName=(e)=>{ this.setState({ answer_open:e.target.checked }) } //题目顺序随机打乱 questionrandom=(e)=>{ this.setState({ question_random:e.target.checked }) } //选项顺序随机打乱 choicerandom=(e)=>{ this.setState({ choice_random:e.target.checked }) } //答题时间 funlatepenalty=(e)=>{ let value= parseInt(e.target.value); if(isNaN(value)){ value=0 } this.setState({ time:value }) } showstatistic=(e)=>{ this.setState({ show_statistic:e.target.checked }) } onChangeTimepublish=(date, dateString)=>{ if(date===null){ this.setState({ publish_time: null, end_time:null }) }else{ if(moment(handleDateString(dateString),"YYYY-MM-DD HH:mm") <= moment()){ this.setState({ unit_p_tip:"发布时间不能早于当前时间", p_flag:true }) }else{ this.setState({ unit_p_tip:"", p_flag:false }) } this.setState({ publish_time: handleDateString(dateString), end_time:moment(moment(handleDateString(dateString)).add(1, 'months')).format("YYYY-MM-DD HH:mm") }) } } onChangeTimeEnd=(date, dateString)=>{ if(date===null){ this.setState({ end_time:null }) }else{ if(moment(date,"YYYY-MM-DD HH:mm") <= moment()){ this.setState({ unit_e_tip:"截止时间不能早于当前时间", e_flag:true }) }else if(moment(date,"YYYY-MM-DD HH:mm") <= moment(this.state.publish_time,"YYYY-MM-DD HH:mm")){ this.setState({ unit_e_tip:"截止时间不能早于发布时间", e_flag:true }) }else{ this.setState({ unit_e_tip:"", e_flag:false }) } this.setState({ end_time: handleDateString(dateString) }) } } //编辑 editSetting = () => { if(this.props.Commonheadofthetestpaper.course_is_end==true){ this.setState({ modalsType:true, modalsTopval:"课堂已结束不能再修改!", loadtype:true, modalSave:this.cancelBox }) }else{ this.setState({ flagPageEdit:true }) } } //取消编辑 cancelEdit=()=>{ this.getSettingInfo(); this.setState({ flagPageEdit:false }) } render(){ let{flagPageEdit,end_time,publish_time,course_group,rules, unit_p_tip, unit_e_tip, modalsType, modalsTopval, loadtype, modalSave, score_open, answer_open, unified_setting, show_statistic, question_random, choice_random, time, polls, publish_timetype, end_timetype }=this.state const { getFieldDecorator } = this.props.form; const formItemLayout = { labelCol: { xs: { span: 24 }, // sm: { span: 8 }, sm: { span: 24 }, }, wrapperCol: { xs: { span: 24 }, // sm: { span: 16 }, sm: { span: 24 }, }, }; // console.log(flagPageEdit===true?polls&&polls.exercise_status===1?3:2:1) return(

发布设置 { !flagPageEdit&&this.props.isAdmin()===true ? 编辑设置 {/**/} {/**/} {/**/} :"" }

{course_group&&course_group.length>1?

{getFieldDecorator('unified_setting') ( 统一设置 )} (选中则所有分班使用相同的发布设置,仅课堂管理员可修改;否则各个分班允许单独设置)

:""} { unified_setting===true ?
发布时间:

{ unit_p_tip !="" ? {unit_p_tip}:"" }

(学生收到试卷的时间)
截止时间:

{ unit_e_tip && unit_e_tip != "" ? { unit_e_tip }:"" }

(学生可以答题的时间截点)
: this.rulesCheckInfo(info)} > }

答题设置

答题时长: {getFieldDecorator('time') ( )} 分钟 (空值,代表不限时长;非空值,代表限制时长,从学生首次答题开始持续计时)

答题显示:

{getFieldDecorator('question_random') ( 题目顺序随机打乱 )} (选中,则学生答题时,题目顺序按照题型随机显示)

{getFieldDecorator('choice_random') ( 选项顺序随机打乱 )} (选中,则学生答题时,选项顺序随机显示)

公开设置

{getFieldDecorator('score_open') ( 公开成绩 )} (选中,则在试卷截止时间之后,已提交答题的学生可以查看其它学生的成绩,否则只能查看自己的成绩)

{getFieldDecorator('answer_open') ( 公开答案 )} (选中,则在试卷截止时间之后,已提交答题的学生可以查看试卷题目的答案,否则不能查看)

{getFieldDecorator('show_statistic') ( 公开统计 )} (选中,则在试卷截止时间之后,已提交答题的学生可以查看答题统计,否则不能查看)

{ flagPageEdit&&this.props.isAdmin()===true ?
取消
:"" }
) } } const WrappedExercisesetting = Form.create({ name: 'exercisesetting' })(Exercisesetting); export default WrappedExercisesetting; // //提交form表单 // handleSubmit = (e) => { // // let{unified_setting,answer_open}=this.state; // e.preventDefault(); // let exercise_id=this.props.match.params.Id; // // this.props.form.validateFieldsAndScroll((err, values) => { // debugger // if(!err){ // // 第一次进行问卷设置或者勾选了统一设置 // if(unified_setting==true){ // if(this.state.p_flag == false && this.state.e_flag == true){ // // 选择了发布时间但截至时间没有选择 // this.setState({ // modalsType:true, // modalsTopval:"请选择截止时间", // loadtype:true, // modalSave:this.cancelBox // }) // return; // }else if(this.state.p_flag == true && this.state.e_flag == true){ // // 如果两个时间都没有填写则弹出立即发布弹框 // let{publish_time,end_time}=this.state // if(publish_time==undefined && end_time ==undefined){ // // }else{ // // 否则就是选择的时间错误 // this.setState({ // modalsType:true, // modalsTopval:"请选择正确的发布时间和截止时间", // loadtype:true, // modalSave:this.cancelBox // }) // } // return; // } // } // // let url=`/exercises/${exercise_id}/commit_setting.json`; // let params=[]; // if(values.unitSet){ // params={ // unified_setting:values.unitSet, // publish_time:this.state.publish_time, // end_time:this.state.end_time, // show_result:values.public, // un_anonymous:values.real // } // }else{ // params={ // unified_setting:values.unitSet, // show_result:values.public, // un_anonymous:values.real, // publish_time_groups:this.state.rules // } // } // axios.post((url),{params}).then((result)=>{ // if(result.status==200){ // this.props.showNotification(`${result.data.message}`); // } // }).catch((error)=>{ // console.log(error); // }) // } // }) // }