Commit 2d9ad9a1 by yuananting

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

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