张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<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>