试卷-多选题-调分

dev_cs
caicai8 5 years ago
parent 09f4b0079b
commit 3722c0ceaa

@ -77,7 +77,9 @@ class ExerciseReviewAndAnswer extends Component{
exerciseTotalScore:undefined, exerciseTotalScore:undefined,
// 加载效果 // 加载效果
isSpin:false isSpin:false,
// 调分数组
ajustSore:undefined
} }
} }
componentDidUpdate (prevProps) { componentDidUpdate (prevProps) {
@ -190,7 +192,23 @@ class ExerciseReviewAndAnswer extends Component{
user_exercise_status:1, user_exercise_status:1,
Id:result.data.exercise_answer_user.user_id, Id:result.data.exercise_answer_user.user_id,
exerciseTotalScore:result.data.exercise_answer_user.score, 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)=>{ }).catch((error)=>{
@ -227,7 +245,7 @@ class ExerciseReviewAndAnswer extends Component{
} }
scrollToAnchor=(index)=>{ scrollToAnchor=(index)=>{
let name="Anchor_"+index; let name="Anchor_"+index;
console.log($("#Anchor_"+index).scrollTop()); // console.log($("#Anchor_"+index).scrollTop());
if (index) { if (index) {
// let anchorElement = document.getElementById(name); // let anchorElement = document.getElementById(name);
// if(anchorElement) { anchorElement.scrollIntoView(); } // if(anchorElement) { anchorElement.scrollIntoView(); }
@ -244,62 +262,115 @@ class ExerciseReviewAndAnswer extends Component{
) )
} }
// 调分 // 调分
showSetScore=(key,flag,setId)=>{ showSetScore=(key,flag,position,type,id)=>{
this.setState( this.setState(
(prevState) => ({ (prevState) => ({
exercise_questions : update(prevState.exercise_questions, {[key]: { setScore: {$set: flag == undefined || flag==false ? true : false}}}) exercise_questions : update(prevState.exercise_questions, {[key]: { setScore: {$set: flag == undefined || flag==false ? true : false}}})
}),()=>{ }),()=>{
if (setId && (flag == undefined || flag==false)) { if (position && type && (flag == undefined || flag==false)) {
$("html").animate({ scrollTop: $("#Anchor_"+setId).offset().top - 150 }) $("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({ // this.setState({
score:undefined // 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]*$/; let reg = /^[0-9]+.?[0-9]*$/;
if(reg.test(value)==false){ if(reg.test(value)==false){
this.setState({ // this.setState({
setTip:"请输入数字" // setTip:"请输入数字"
}) // })
this.setState(
(prevState) => ({
ajustSore : update(prevState.ajustSore, {[index]: { setTip: {$set: "请输入数字"}}})
})
)
return; return;
}else{ }else{
this.setState({ // this.setState({
setTip:"", // setTip:"",
score:value // score:value
}) // })
this.setState(
(prevState) => ({
ajustSore : update(prevState.ajustSore, {[index]: { inputSore: {$set: value},setTip:{$set: ""}}})
})
)
} }
} }
changeScoreReasons=(e)=>{ changeScoreReasons=(e,id)=>{
console.log(e.target.value); // console.log(e.target.value);
this.setState({ // this.setState({
setScoreReason:e.target.value // 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)=>{ setAction=(key,q_id,maxScore)=>{
let {ajustSore}=this.state;
let{ score,setScoreReason ,setTip }=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){ if(!score && score != 0){
this.setState({ // this.setState({
setTip:"请输入分数" // setTip:"请输入分数"
}) // })
this.setState(
(prevState) => ({
ajustSore : update(prevState.ajustSore, {[index]: { setTip: {$set: "请输入分数"}}})
})
)
return; return;
} }
if(score < 0){ if(score < 0){
this.setState({ // this.setState({
setTip:"分数必须大于或者等于0" // setTip:"分数必须大于或者等于0"
}) // })
this.setState(
(prevState) => ({
ajustSore : update(prevState.ajustSore, {[index]: { setTip: {$set: "分数必须大于或者等于0"}}})
})
)
return; return;
} }
if(score > maxScore){ if(score > maxScore){
this.setState({ // this.setState({
setTip:"分数不能大于当前题目的分数" // setTip:"分数不能大于当前题目的分数"
}) // })
this.setState(
(prevState) => ({
ajustSore : update(prevState.ajustSore, {[index]: { setTip: {$set: "分数不能大于当前题目的分数"}}})
})
)
return; return;
} }
if(setTip==""){ if(setTip==""){
@ -311,20 +382,20 @@ class ExerciseReviewAndAnswer extends Component{
}).then((result)=>{ }).then((result)=>{
if(result.status==200){ if(result.status==200){
this.props.showNotification('调分成功'); this.props.showNotification('调分成功');
console.log(this.state.exercise_questions);
let statusScore = score==0 ? 0 : score > 0 && score < maxScore ? 2 : 1; let statusScore = score==0 ? 0 : score > 0 && score < maxScore ? 2 : 1;
console.log(statusScore);
this.setState( this.setState(
(prevState) => ({ (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); this.showSetScore(key,true);
} }
}).catch((error)=>{ }).catch((error)=>{
@ -518,12 +589,13 @@ class ExerciseReviewAndAnswer extends Component{
ModalSave, ModalSave,
Loadtype, Loadtype,
exerciseTotalScore, exerciseTotalScore,
isSpin isSpin,
ajustSore
}=this.state }=this.state
let isAdmin = this.props.isAdmin(); let isAdmin = this.props.isAdmin();
let isStudent =this.props.isStudent(); let isStudent =this.props.isStudent();
const { current_user } = this.props const { current_user } = this.props
console.log(data&&data.exercise.user_name) // console.log(data&&data.exercise.user_name)
return( return(
<div className="newMain" style={{paddingTop:"0px"}}> <div className="newMain" style={{paddingTop:"0px"}}>
<Spin size="large" spinning={isSpin}> <Spin size="large" spinning={isSpin}>
@ -709,6 +781,8 @@ class ExerciseReviewAndAnswer extends Component{
<div> <div>
{ {
exercise_questions && exercise_questions.map((item,key)=>{ exercise_questions && exercise_questions.map((item,key)=>{
debugger;
let list = ajustSore && ajustSore.filter(obj => obj.id === item.question_id);
return( return(
<div className="bor-top-greyE pt30 pb30" id={"Anchor_"+parseInt(key+1)}> <div className="bor-top-greyE pt30 pb30" id={"Anchor_"+parseInt(key+1)}>
<p className="clearfix font-16 pl30 pr30"> <p className="clearfix font-16 pl30 pr30">
@ -716,32 +790,32 @@ class ExerciseReviewAndAnswer extends Component{
<span className="fr"> <span className="fr">
{ {
// 填空(一直都有调分),和简答题调分:老师身份 已经评分的才能出现调分按钮 // 填空(一直都有调分),和简答题调分:老师身份 已经评分的才能出现调分按钮
isAdmin && ((parseInt(item.answer_status) != 0 && item.question_type == 4) || item.question_type == 3) ? isAdmin && ((parseInt(item.answer_status) != 0 && item.question_type == 4) || item.question_type == 3 || item.question_type == 1) ?
<WordsBtn style="blue" className="mr20 font-16 fl" onClick={()=>this.showSetScore(key,item.setScore,item.q_position+"_"+item.question_type)}>调分</WordsBtn>:"" <WordsBtn style="blue" className="ml20 font-16 fl" onClick={()=>this.showSetScore(key,item.setScore,item.q_position,item.question_type,item.question_id)}>调分</WordsBtn>:""
} }
{ {
// 简答题,未评分的显示未批 // 简答题,未评分的显示未批
isAdmin && parseInt(item.answer_status) == 0 && item.question_type == 4 ? isAdmin && parseInt(item.answer_status) == 0 && item.question_type == 4 ?
<span className="color-red fl mr20">未批</span>:"" <span className="color-red fl ml20">未批</span>:""
} }
{ {
// 客观题:老师||学生(试卷已截止且答案公开)显示正确答案 // 客观题:老师||学生(试卷已截止且答案公开)显示正确答案
item.question_type < 3 && item.standard_answer_show ? item.question_type < 3 && item.standard_answer_show ?
<span className="font-16 ml20"> <span className="font-16 fl ml20">
正确答案{ item.standard_answer_show } 正确答案{ item.standard_answer_show }
</span>:"" </span>:""
} }
{ {
//(老师身份且除实训题外) || (学生身份且试卷已经截止)就显示用户当前题目所得分数 //(老师身份且除实训题外) || (学生身份且试卷已经截止)就显示用户当前题目所得分数
( isAdmin || (isStudent && exercise.exercise_status == 3)) && item.question_type != 5 && item.user_score ? ( isAdmin || (isStudent && exercise.exercise_status == 3)) && item.question_type != 5 && item.user_score ?
<span className="font-16 ml20"> <span className="font-16 ml20 fl">
<span><span className={parseInt(item.answer_status) == 0 ?"color-red":parseInt(item.answer_status) == 1 ?"color-green":"color-orange-tip"}>{item.user_score}</span> </span> <span><span className={parseInt(item.answer_status) == 0 ?"color-red":parseInt(item.answer_status) == 1 ?"color-green":"color-orange-tip"}>{item.user_score}</span> </span>
</span> : "" </span> : ""
} }
{ {
//实训题 ,答题 //实训题 ,答题
item.question_type == 5 && item.question_type == 5 &&
<a href={"/shixuns/"+item.shixun_identifier+"/challenges"} target="_blank" class="font-16 color-blue" target={"_blank"}>实训详情</a> <a href={"/shixuns/"+item.shixun_identifier+"/challenges"} target="_blank" class="font-16 color-blue fl" target={"_blank"}>实训详情</a>
} }
</span> </span>
</p> </p>
@ -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) &&
<div className="ml30 mr30 bor-top-greyE pt30 mt20 clearfix df"> <div className="ml30 mr30 bor-top-greyE pt30 mt20 clearfix df">
<img src={getImageUrl(`images/${item.question_comments.user_picture}`)} width="48" height="48" className="radius mr10"/> <img src={getImageUrl(`images/${item.question_comments.user_picture}`)} width="48" height="48" className="radius mr10"/>
<div className="flex1"> <div className="flex1">
@ -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))?
<div className="ml30 mr30 bor-top-greyE pt20 mt20" id={`${"Anchor_"+item.q_position+"_"+item.question_type}`}> <div className="ml30 mr30 bor-top-greyE pt20 mt20" id={`${"Anchor_"+item.q_position+"_"+item.question_type}`}>
<div className="edu-txt-right"> <div className="edu-txt-right">
<span><span className="color-red">*</span></span> <span><span className="color-red">*</span></span>
@ -848,12 +922,12 @@ class ExerciseReviewAndAnswer extends Component{
<InputNumber <InputNumber
placeholder="请填写分数" placeholder="请填写分数"
min={0} min={0}
max={item.question_score} // max={item.question_score}
value={score} value={list && list.length>0 && list[0].inputSore}
step={0.1} step={0.1}
precision={1} precision={1}
className={ setTip !="" ? "edu-txt-center winput-115-40 fl mt3 noticeTip inputNumber30" : "edu-txt-center winput-115-40 fl mt3 inputNumber30"} 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={this.inputScore} onChange={(value)=>this.inputScore(value,item.question_id)}
></InputNumber> ></InputNumber>
<span className="ml5"></span> <span className="ml5"></span>
{ {
@ -862,11 +936,11 @@ class ExerciseReviewAndAnswer extends Component{
<ActionBtn style="blue" className="middle ml20" onClick={()=>this.setAction(key,item.question_id,item.question_score)}>确认</ActionBtn> <ActionBtn style="blue" className="middle ml20" onClick={()=>this.setAction(key,item.question_id,item.question_score)}>确认</ActionBtn>
</p> </p>
{ {
setTip !="" ? <p className="color-red edu-txt-left">{setTip}</p> :"" list && list.length > 0 && list[0].setTip !="" ? <p className="color-red edu-txt-left">{ list[0].setTip }</p> :""
} }
</li> </li>
</div> </div>
<Textarea className="winput-100-150 mt20" value={setScoreReason} style={{height:"180px"}} maxLength="100" onChange={this.changeScoreReasons} placeholder="请您输入评语最大限制100个字符"></Textarea> <Textarea className="winput-100-150 mt20" value={list && list.length>0 && list[0].desc} style={{height:"180px"}} maxLength="100" onChange={(e)=>this.changeScoreReasons(e,item.question_id)} placeholder="请您输入评语最大限制100个字符"></Textarea>
</div>:"" </div>:""
} }
</div> </div>

Loading…
Cancel
Save