Commit 2d9ad9a1 by yuananting

fix:解决合并试卷详情接口参数新增的功能冲突

parents 845af639 4603352f
/*
* @Author: yuananting
* @Date: 2021-03-27 16:15:13
* @LastEditors: Please set LastEditors
* @LastEditTime: 2021-06-28 15:44:38
* @LastEditors: yuananting
* @LastEditTime: 2021-07-01 16:44:39
* @Description: 助学工具-新建/复制/编辑试卷
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
......@@ -21,8 +21,8 @@ import Bus from '@/core/bus';
import _ from 'underscore';
import { Route, withRouter } from 'react-router-dom';
import * as paperEmpty from '../../lottie/paperEmpty/data.json';
import AddExam from "@/modules/teach-tool/examination-manager/AddExam";
import BatchScore from "./components/BatchScore";
import AddExam from '@/modules/teach-tool/examination-manager/AddExam';
import BatchScore from './components/BatchScore';
const questionTypeEnum = {
SINGLE_CHOICE: '单选题',
......@@ -89,36 +89,36 @@ class OperatePaper extends Component {
],
scoreRule: [
{
typeKey: "SINGLE_CHOICE",
typeKey: 'SINGLE_CHOICE',
score: 2,
portionScore: 0,
totalQuestion: 0,
},
{
typeKey: "MULTI_CHOICE",
typeKey: 'MULTI_CHOICE',
score: 2,
portionScore: 0,
totalQuestion: 0,
},
{
typeKey: "JUDGE",
typeKey: 'JUDGE',
score: 2,
portionScore: 0,
totalQuestion: 0,
},
{
typeKey: "GAP_FILLING",
typeKey: 'GAP_FILLING',
score: 2,
portionScore: 0,
totalQuestion: 0,
},
{
typeKey: "INDEFINITE_CHOICE",
typeKey: 'INDEFINITE_CHOICE',
score: 2,
portionScore: 0,
totalQuestion: 0,
},
]
],
};
}
......@@ -129,10 +129,10 @@ class OperatePaper extends Component {
this.setState({ currentOperate: 'new', currentNav: '新建试卷' });
break;
case 'edit':
this.setState({ currentOperate: 'edit', currentNav: '编辑试卷' }, () => this.queryPaperDetail());
this.setState({ currentOperate: 'edit', currentNav: '编辑试卷' }, () => this.queryPaperDetail('edit'));
break;
case 'copy':
this.setState({ currentOperate: 'copy', currentNav: '复制试卷' }, () => this.queryPaperDetail());
this.setState({ currentOperate: 'copy', currentNav: '复制试卷' }, () => this.queryPaperDetail('copy'));
break;
}
}
......@@ -156,7 +156,7 @@ class OperatePaper extends Component {
};
// 编辑/复制试卷时获取相应试卷详情
queryPaperDetail = async () => {
queryPaperDetail = async (flag) => {
this.setState({ loading: true });
const { currentOperate } = this.state;
let query = {
......@@ -164,6 +164,7 @@ class OperatePaper extends Component {
source: 0,
userId: User.getStoreUserId(),
tenantId: User.getStoreId(),
flag: flag === 'copy',
};
const res = await AidToolService.queryPaperDetail(query);
const { result } = res;
......@@ -224,29 +225,29 @@ class OperatePaper extends Component {
}, 0);
const passScore = Math.round(totalScore * formData.passRate * 0.01);
let _scorerule = _.map(this.state.scoreRule,(item)=> {
switch(item.typeKey) {
case "SINGLE_CHOICE":
let _scorerule = _.map(this.state.scoreRule, (item) => {
switch (item.typeKey) {
case 'SINGLE_CHOICE':
item.totalQuestion = singleQuestion.length;
break;
case "MULTI_CHOICE":
case 'MULTI_CHOICE':
item.totalQuestion = multiQuestion.length;
break;
case "JUDGE":
case 'JUDGE':
item.totalQuestion = judgeQuestion.length;
break;
case "GAP_FILLING":
case 'GAP_FILLING':
item.totalQuestion = gapQuestion.length;
break;
case "INDEFINITE_CHOICE":
case 'INDEFINITE_CHOICE':
item.totalQuestion = indefiniteQuestion.length;
break;
default:
item.totalQuestion = 0
item.totalQuestion = 0;
break;
}
return item
})
return item;
});
this.setState({
formData: {
...formData,
......@@ -264,7 +265,7 @@ class OperatePaper extends Component {
questionCnt: _selectQuestionList.length,
totalScore,
},
scoreRule:_scorerule,
scoreRule: _scorerule,
});
};
......@@ -276,7 +277,7 @@ class OperatePaper extends Component {
getSelectedQuestion={selectQuestionList}
setSelectedQuestion={(list) => {
//按分数规则给每一题重新设置分数(只对新增题目有效)
let _list = this.setScoreByRule(list)
let _list = this.setScoreByRule(list);
this.setState({ selectQuestionModal: null }, () => {
this.setFormData(_list);
this.quickSorter(_list, sorterMethod, sorterBy);
......@@ -294,23 +295,23 @@ class OperatePaper extends Component {
setScoreByRule = (list) => {
//按批量设置分数规则给每一题重新设置分数(只对新增题目有效)
return _.map(list, (item)=> {
let exist = _.find(this.state.selectQuestionList, (q)=> {
return q.questionId === item.questionId
})
return _.map(list, (item) => {
let exist = _.find(this.state.selectQuestionList, (q) => {
return q.questionId === item.questionId;
});
if (exist) {
return item
return item;
}
let rule = _.find(this.state.scoreRule,(g)=> {
return g.typeKey === item.questionType
})
let rule = _.find(this.state.scoreRule, (g) => {
return g.typeKey === item.questionType;
});
if (rule) {
item.score = rule.score
item.portionScore = rule.portionScore
}
return item
})
item.score = rule.score;
item.portionScore = rule.portionScore;
}
return item;
});
};
// 移动已选题目
handleMoveItem = (index, moveLength) => {
const selectQuestionList = [...this.state.selectQuestionList];
......@@ -584,7 +585,7 @@ class OperatePaper extends Component {
max={100}
value={record.score || 2}
onChange={(value) => {
value = Math.round(value)
value = Math.round(value);
const _selectQuestionList = [...selectQuestionList];
this.setState(
{
......@@ -611,7 +612,7 @@ class OperatePaper extends Component {
max={record.score - 1}
value={record.portionScore || 0}
onChange={(value) => {
value = Math.round(value)
value = Math.round(value);
const _selectQuestionList = [...selectQuestionList];
this.setState(
{
......@@ -669,28 +670,50 @@ class OperatePaper extends Component {
//
onBatchScoreOK = (rules) => {
this.setState({
batchSetScoreVisible:false,
scoreRule:rules
},()=> {
let questionList = _.map(this.state.selectQuestionList,(item)=> {
let rule = _.find(this.state.scoreRule,(s)=> {
return s.typeKey === item.questionType
})
this.setState(
{
batchSetScoreVisible: false,
scoreRule: rules,
},
() => {
let questionList = _.map(this.state.selectQuestionList, (item) => {
let rule = _.find(this.state.scoreRule, (s) => {
return s.typeKey === item.questionType;
});
if (rule) {
item.score = rule.score
item.portionScore = rule.portionScore
item.score = rule.score;
item.portionScore = rule.portionScore;
}
return item
})
return item;
});
// 各类型题目总分值
const { formData, scoreRule } = this.state
const {singleChoiceCnt, multiChoiceCnt, judgeCnt, gapFillingCnt, indefiniteChoiceCnt} = formData
const singleChoiceScore = singleChoiceCnt*scoreRule.find((item)=> {return item.typeKey === "SINGLE_CHOICE"}).score
const multiChoiceScore = multiChoiceCnt*scoreRule.find((item)=> {return item.typeKey === "MULTI_CHOICE"}).score
const judgeScore = judgeCnt*scoreRule.find((item)=> {return item.typeKey === "JUDGE"}).score
const gapFillingScore = gapFillingCnt*scoreRule.find((item)=> {return item.typeKey === "GAP_FILLING"}).score
const indefiniteChoiceScore = indefiniteChoiceCnt*scoreRule.find((item)=> {return item.typeKey === "INDEFINITE_CHOICE"}).score
const { formData, scoreRule } = this.state;
const { singleChoiceCnt, multiChoiceCnt, judgeCnt, gapFillingCnt, indefiniteChoiceCnt } = formData;
const singleChoiceScore =
singleChoiceCnt *
scoreRule.find((item) => {
return item.typeKey === 'SINGLE_CHOICE';
}).score;
const multiChoiceScore =
multiChoiceCnt *
scoreRule.find((item) => {
return item.typeKey === 'MULTI_CHOICE';
}).score;
const judgeScore =
judgeCnt *
scoreRule.find((item) => {
return item.typeKey === 'JUDGE';
}).score;
const gapFillingScore =
gapFillingCnt *
scoreRule.find((item) => {
return item.typeKey === 'GAP_FILLING';
}).score;
const indefiniteChoiceScore =
indefiniteChoiceCnt *
scoreRule.find((item) => {
return item.typeKey === 'INDEFINITE_CHOICE';
}).score;
const totalScore = questionList.reduce((prev, cur) => {
return prev + Number(cur.score) || 0;
}, 0);
......@@ -698,7 +721,7 @@ class OperatePaper extends Component {
const passScore = Math.round(totalScore * formData.passRate * 0.01);
this.setState({
selectQuestionList:questionList,
selectQuestionList: questionList,
formData: {
...formData,
singleChoiceScore,
......@@ -708,10 +731,11 @@ class OperatePaper extends Component {
indefiniteChoiceScore,
totalScore,
passScore,
},
});
}
})
})
}
);
};
// 上下移题型
handleMoveTypeSorter = (index, moveLength) => {
const sorterTypeList = [...this.state.sorterTypeList];
......@@ -849,7 +873,7 @@ class OperatePaper extends Component {
max={100}
value={passRate}
onChange={(value) => {
value = Math.round(value)
value = Math.round(value);
this.setState(
{
formData: {
......@@ -884,13 +908,12 @@ class OperatePaper extends Component {
快捷排序
</Button>
<Button
className="choose-btn"
className='choose-btn'
onClick={() => {
this.setState({
batchSetScoreVisible: true,
});
}}
>
}}>
批量设置分数
</Button>
</Space>
......@@ -972,7 +995,7 @@ class OperatePaper extends Component {
<BatchScore
visible={this.state.batchSetScoreVisible}
onOK={this.onBatchScoreOK}
onCancel={()=> this.setState({batchSetScoreVisible:false})}
onCancel={() => this.setState({ batchSetScoreVisible: false })}
rules={this.state.scoreRule}
/>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment