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(
@@ -709,6 +781,8 @@ class ExerciseReviewAndAnswer extends Component{
{ exercise_questions && exercise_questions.map((item,key)=>{ + debugger; + let list = ajustSore && ajustSore.filter(obj => obj.id === item.question_id); return(

@@ -716,32 +790,32 @@ class ExerciseReviewAndAnswer extends Component{ { // 填空(一直都有调分),和简答题调分:老师身份 已经评分的才能出现调分按钮 - isAdmin && ((parseInt(item.answer_status) != 0 && item.question_type == 4) || item.question_type == 3) ? - this.showSetScore(key,item.setScore,item.q_position+"_"+item.question_type)}>调分:"" + isAdmin && ((parseInt(item.answer_status) != 0 && item.question_type == 4) || item.question_type == 3 || item.question_type == 1) ? + this.showSetScore(key,item.setScore,item.q_position,item.question_type,item.question_id)}>调分:"" } { // 简答题,未评分的显示未批 isAdmin && parseInt(item.answer_status) == 0 && item.question_type == 4 ? - 未批:"" + 未批:"" } { // 客观题:老师||学生(试卷已截止且答案公开)显示正确答案 item.question_type < 3 && item.standard_answer_show ? - + 正确答案:{ item.standard_answer_show } :"" } { //(老师身份且除实训题外) || (学生身份且试卷已经截止)就显示用户当前题目所得分数 ( isAdmin || (isStudent && exercise.exercise_status == 3)) && item.question_type != 5 && item.user_score ? - + {item.user_score} : "" } { //实训题 ,答题 item.question_type == 5 && - 实训详情 + 实训详情 }

@@ -825,7 +899,7 @@ class ExerciseReviewAndAnswer extends Component{ { //调分理由部分 - item.question_comments && item.question_comments.comment && (item.question_type == 3 || item.question_type == 4) && + item.question_comments && item.question_comments.comment && (item.question_type == 3 || item.question_type == 4 || item.question_type == 1) &&
@@ -839,7 +913,7 @@ class ExerciseReviewAndAnswer extends Component{ } { // 调分输入部分 - isAdmin && ((item.setScore && item.question_type == 3) || ((item.setScore || parseInt(item.answer_status) == 0) && item.question_type == 4))? + isAdmin && ((item.setScore && item.question_type == 3) || (item.setScore && item.question_type == 1) || ((item.setScore || parseInt(item.answer_status) == 0) && item.question_type == 4))?
*调分: @@ -848,12 +922,12 @@ class ExerciseReviewAndAnswer extends Component{ 0 && list[0].inputSore} step={0.1} precision={1} - className={ setTip !="" ? "edu-txt-center winput-115-40 fl mt3 noticeTip inputNumber30" : "edu-txt-center winput-115-40 fl mt3 inputNumber30"} - onChange={this.inputScore} + className={ list && list.length>0 && list[0].setTip !="" ? "edu-txt-center winput-115-40 fl mt3 noticeTip inputNumber30" : "edu-txt-center winput-115-40 fl mt3 inputNumber30"} + onChange={(value)=>this.inputScore(value,item.question_id)} > { @@ -862,11 +936,11 @@ class ExerciseReviewAndAnswer extends Component{ this.setAction(key,item.question_id,item.question_score)}>确认

{ - setTip !="" ?

{setTip}

:"" + list && list.length > 0 && list[0].setTip !="" ?

{ list[0].setTip }

:"" }
- +
:"" }