diff --git a/public/react/src/modules/courses/exercise/ExerciseReviewAndAnswer.js b/public/react/src/modules/courses/exercise/ExerciseReviewAndAnswer.js index 930593c15..b5a1a7c26 100644 --- a/public/react/src/modules/courses/exercise/ExerciseReviewAndAnswer.js +++ b/public/react/src/modules/courses/exercise/ExerciseReviewAndAnswer.js @@ -77,7 +77,9 @@ class ExerciseReviewAndAnswer extends Component{ exerciseTotalScore:undefined, // 加载效果 - isSpin:false + isSpin:false, + // 调分数组 + ajustSore:undefined } } componentDidUpdate (prevProps) { @@ -190,7 +192,23 @@ class ExerciseReviewAndAnswer extends Component{ user_exercise_status:1, Id:result.data.exercise_answer_user.user_id, exerciseTotalScore:result.data.exercise_answer_user.score, - isSpin:false + isSpin:false, + }) + // 先将未批的简答题放入到调分数组中 + let ajustSore = []; + result.data && result.data.exercise_questions.length>0 && result.data.exercise_questions.map((item,key)=>{ + if( item.question_type == 4 && item.answer_status == 0 ){ + ajustSore.push({ + inputSore:undefined, + desc:undefined, + id:item.question_id, + position:item.q_position, + setTip:"" + }) + } + }) + this.setState({ + ajustSore }) } }).catch((error)=>{ @@ -227,7 +245,7 @@ class ExerciseReviewAndAnswer extends Component{ } scrollToAnchor=(index)=>{ let name="Anchor_"+index; - console.log($("#Anchor_"+index).scrollTop()); + // console.log($("#Anchor_"+index).scrollTop()); if (index) { // let anchorElement = document.getElementById(name); // if(anchorElement) { anchorElement.scrollIntoView(); } @@ -244,62 +262,115 @@ class ExerciseReviewAndAnswer extends Component{ ) } // 调分 - showSetScore=(key,flag,setId)=>{ + showSetScore=(key,flag,position,type,id)=>{ this.setState( (prevState) => ({ exercise_questions : update(prevState.exercise_questions, {[key]: { setScore: {$set: flag == undefined || flag==false ? true : false}}}) }),()=>{ - if (setId && (flag == undefined || flag==false)) { - $("html").animate({ scrollTop: $("#Anchor_"+setId).offset().top - 150 }) + if (position && type && (flag == undefined || flag==false)) { + $("html").animate({ scrollTop: $("#Anchor_"+position+"_"+type).offset().top - 150 }); + + if(id){ + let { ajustSore } = this.state; + let obj = ajustSore.filter(obj => obj.id === id).length > 0; + if(!obj){ + ajustSore.push({ + id, + inputSore:undefined, + desc:undefined, + position:position, + setTip:"" + }) + } + } } } ) - this.setState({ - score:undefined - }) + // this.setState({ + // score:undefined + // }) } - inputScore=(value)=>{ - + inputScore=(value,id)=>{ + let { ajustSore } = this.state; + var index = ajustSore.map(function (item) { return item.id; }).indexOf(id); let reg = /^[0-9]+.?[0-9]*$/; if(reg.test(value)==false){ - this.setState({ - setTip:"请输入数字" - }) + // this.setState({ + // setTip:"请输入数字" + // }) + this.setState( + (prevState) => ({ + ajustSore : update(prevState.ajustSore, {[index]: { setTip: {$set: "请输入数字"}}}) + }) + ) return; }else{ - this.setState({ - setTip:"", - score:value - }) + // this.setState({ + // setTip:"", + // score:value + // }) + this.setState( + (prevState) => ({ + ajustSore : update(prevState.ajustSore, {[index]: { inputSore: {$set: value},setTip:{$set: ""}}}) + }) + ) } } - changeScoreReasons=(e)=>{ - console.log(e.target.value); - this.setState({ - setScoreReason:e.target.value - }) + changeScoreReasons=(e,id)=>{ + // console.log(e.target.value); + // this.setState({ + // setScoreReason:e.target.value + // }) + let value = e.target.value; + let { ajustSore } = this.state; + var index = ajustSore.map(function (item) { return item.id; }).indexOf(id); + this.setState( + (prevState) => ({ + ajustSore : update(prevState.ajustSore, {[index]: { desc: {$set: value}}}) + }) + ) } //确认调分 setAction=(key,q_id,maxScore)=>{ - - let{ score,setScoreReason ,setTip }=this.state; + let {ajustSore}=this.state; + let list = ajustSore.filter(obj => obj.id == q_id); + let index = ajustSore.map(function (item) { return item.id; }).indexOf(q_id); + + let score = list[0].inputSore; + let setScoreReason = list[0].desc; + let{ setTip }=this.state; if(!score && score != 0){ - this.setState({ - setTip:"请输入分数" - }) + // this.setState({ + // setTip:"请输入分数" + // }) + this.setState( + (prevState) => ({ + ajustSore : update(prevState.ajustSore, {[index]: { setTip: {$set: "请输入分数"}}}) + }) + ) return; } if(score < 0){ - this.setState({ - setTip:"分数必须大于或者等于0" - }) + // this.setState({ + // setTip:"分数必须大于或者等于0" + // }) + this.setState( + (prevState) => ({ + ajustSore : update(prevState.ajustSore, {[index]: { setTip: {$set: "分数必须大于或者等于0"}}}) + }) + ) return; } if(score > maxScore){ - this.setState({ - setTip:"分数不能大于当前题目的分数" - }) + // this.setState({ + // setTip:"分数不能大于当前题目的分数" + // }) + this.setState( + (prevState) => ({ + ajustSore : update(prevState.ajustSore, {[index]: { setTip: {$set: "分数不能大于当前题目的分数"}}}) + }) + ) return; } if(setTip==""){ @@ -311,20 +382,20 @@ class ExerciseReviewAndAnswer extends Component{ }).then((result)=>{ if(result.status==200){ this.props.showNotification('调分成功'); - console.log(this.state.exercise_questions); + let statusScore = score==0 ? 0 : score > 0 && score < maxScore ? 2 : 1; - console.log(statusScore); + this.setState( (prevState) => ({ - exercise_questions : update(prevState.exercise_questions, {[key]: { user_score: {$set: score},answer_status : {$set: statusScore},question_comments:{$set:result.data.question_comments} }}), + exercise_questions : update(prevState.exercise_questions, {[key]: { user_score: {$set: parseFloat(score).toFixed(1)},answer_status : {$set: statusScore},question_comments:{$set:result.data.question_comments} }}), + }) + ) + + this.setState( + (prevState) => ({ + ajustSore : update(prevState.ajustSore, {[index]: { desc: {$set: undefined},inputSore:{ $set:undefined }}}) }) ) - console.log(this.state.exercise_questions); - this.setState({ - score:undefined, - setTip:"", - setScoreReason:undefined - }) this.showSetScore(key,true); } }).catch((error)=>{ @@ -518,12 +589,13 @@ class ExerciseReviewAndAnswer extends Component{ ModalSave, Loadtype, exerciseTotalScore, - isSpin + isSpin, + ajustSore }=this.state let isAdmin = this.props.isAdmin(); let isStudent =this.props.isStudent(); const { current_user } = this.props - console.log(data&&data.exercise.user_name) + // console.log(data&&data.exercise.user_name) return(
@@ -716,32 +790,32 @@ class ExerciseReviewAndAnswer extends Component{
{
// 填空(一直都有调分),和简答题调分:老师身份 已经评分的才能出现调分按钮
- isAdmin && ((parseInt(item.answer_status) != 0 && item.question_type == 4) || item.question_type == 3) ?
-
{setTip}
:"" + list && list.length > 0 && list[0].setTip !="" ?{ list[0].setTip }
:"" }