<template>
|
<view class="topic_index">
|
<view class="topic_index_content">
|
<view class="topic_content_item">
|
<text>{{topicList[topicIndex].question}}</text>
|
<view class="item_answer">
|
<u-checkbox-group
|
v-if="topicList[topicIndex].multiple"
|
v-model="topicList[topicIndex].radio"
|
placement="column"
|
:disabled="topicList[topicIndex].disabled"
|
@change="changeRadio">
|
<u-checkbox
|
:customStyle="{marginBottom: '15px'}"
|
v-for="item in topicList[topicIndex].answerList"
|
:key="item.ansId"
|
:label="item.answer"
|
:name="item.ansId">
|
</u-checkbox>
|
</u-checkbox-group>
|
<u-radio-group
|
v-else
|
v-model="topicList[topicIndex].radio"
|
placement="column"
|
:disabled="topicList[topicIndex].disabled"
|
@change="changeRadio">
|
<u-radio
|
:customStyle="{marginBottom: '15px'}"
|
v-for="item in topicList[topicIndex].answerList"
|
:key="item.ansId"
|
:label="item.answer"
|
:name="item.ansId">
|
</u-radio>
|
</u-radio-group>
|
</view>
|
</view>
|
<view class="item_button">
|
<u-button type="primary" :plain="true" text="上一题" @click="changeTopic()"></u-button>
|
<u-button type="primary" color="#1976FF" text="下一题" @click="nextTopic(topicList[topicIndex])"></u-button>
|
</view>
|
<view class="topic_content_item" v-if="topicList[topicIndex].isAnswer">
|
<text>正确答案:</text>
|
<text>{{topicList[topicIndex].answer}}</text>
|
</view>
|
</view>
|
<u-modal :show="showMould" title="提示" :content='content' @confirm="navigetBack()"></u-modal>
|
</view>
|
</template>
|
|
<script>
|
export default {
|
data() {
|
return {
|
recordId: '',
|
disabled: false,
|
topicIndex: 0,
|
topicList: [],
|
showMould: false, // 答题完成后提示
|
content: '',
|
totalScore: 0
|
}
|
},
|
onLoad(option) {
|
this.getCheckTopicInfo(option.examId);
|
},
|
methods: {
|
// 获取考题信息
|
async getCheckTopicInfo(examId) {
|
const { data } = await this.$api.reboSystem.getCheckTopicInfo({
|
examId: examId
|
});
|
this.recordId = data.recordId;
|
this.topicList = data.queList.map(item => {
|
const list = item.answerList.filter(item => item.isRight === 1);
|
item.next = true;
|
item.isAnswer = false;
|
if(list.length > 1) {
|
item.multiple = true;
|
} else {
|
item.multiple = false;
|
}
|
return item;
|
});
|
},
|
// 选择答案
|
changeRadio(data) {
|
let answerList = this.topicList[this.topicIndex].answerList.filter(item => item.isRight === 1);
|
const ansIdData = answerList.map(item => item.ansId);
|
const answerData = answerList.map(item => item.answer);
|
if(this.topicList[this.topicIndex].multiple) {
|
this.$set(this.topicList[this.topicIndex], 'radio', data.sort().toString());
|
} else {
|
this.$set(this.topicList[this.topicIndex], 'radio', data);
|
}
|
|
if(this.topicList[this.topicIndex].radio !== ansIdData.sort().toString()) {
|
this.$set(this.topicList[this.topicIndex], 'next', false);
|
this.$set(this.topicList[this.topicIndex], 'answer', answerData.toString());
|
} else {
|
this.$set(this.topicList[this.topicIndex], 'next', true);
|
this.$set(this.topicList[this.topicIndex], 'answer', '');
|
}
|
},
|
// 上一题
|
changeTopic() {
|
if((this.topicIndex > 0) && (this.topicIndex <= this.topicList.length)) {
|
this.topicIndex -= 1;
|
} else {
|
uni.$u.toast('已经是第一题了!');
|
}
|
},
|
// 下一题
|
nextTopic(data) {
|
console.log(data,'????')
|
console.log(this.topicList[this.topicIndex],'00101');
|
if(data.radio) {
|
if(data.next) {
|
this.$api.reboSystem.nextCommitAnswer({
|
recordId: this.recordId,
|
queId: data.queId,
|
answerIds: data.radio ? data.radio.toString() : ''
|
}).then((res) => {
|
if(res.data.isFinish === 1) {
|
console.log(res,'===返回')
|
this.totalScore = res.data.totalScore ? res.data.totalScore : 0;
|
this.content = `答题已结束,您的分数为${this.totalScore}分`;
|
this.showMould = true;
|
}
|
})
|
if(this.topicIndex < (this.topicList.length - 1)) {
|
this.isAnswer = false;
|
this.$set(this.topicList[this.topicIndex], 'disabled', true);
|
this.$set(this.topicList[this.topicIndex], 'isAnswer', false);
|
this.topicIndex += 1;
|
} else if(this.topicIndex = (this.topicList.length - 1)) {
|
uni.$u.toast('已经是最后一题了!');
|
this.$set(this.topicList[this.topicIndex], 'disabled', true);
|
}
|
} else {
|
uni.$u.toast('回答错误!');
|
this.isAnswer = true;
|
this.$set(this.topicList[this.topicIndex], 'disabled', true);
|
this.$set(this.topicList[this.topicIndex], 'next', true);
|
this.$set(this.topicList[this.topicIndex], 'isAnswer', true);
|
}
|
} else {
|
if(this.topicIndex < (this.topicList.length - 1)) {
|
this.topicIndex += 1;
|
} else {
|
uni.$u.toast('已经是最后一题了!');
|
}
|
}
|
},
|
// 结束后返回
|
navigetBack() {
|
uni.navigateBack({
|
delta: 2
|
});
|
}
|
}
|
}
|
</script>
|
|
<style scoped lang="scss">
|
.topic_index {
|
height: 100vh;
|
padding: 10px;
|
background: #DBDDDF;
|
height: calc(100vh - 20px);
|
|
.topic_index_content {
|
width: 100%;
|
height: 100%;
|
background: #FFFFFF;
|
border-radius: 8px;
|
|
.topic_content_item {
|
display: flex;
|
flex-direction: column;
|
padding: 15px;
|
|
&:first-child {
|
min-height: 40vh;
|
}
|
|
.item_answer {
|
margin: 30px 0 20px;
|
}
|
}
|
|
.item_button {
|
display: flex;
|
justify-content: space-between;
|
|
/deep/ .u-button--plain {
|
width: 48%;
|
}
|
|
/deep/ .u-button--square {
|
width: 48%;
|
}
|
}
|
}
|
}
|
</style>
|