shuishen
2022-02-26 c765784d2d2d4db55bfcb629cc3f6ec0b57dddcc
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
<template>
    <view>
        <!-- <nav-bar-sub></nav-bar-sub> -->
        <!-- 用于提示是否确认退出考试 -->
        <u-modal v-model="show" :content="content" :show-cancel-button="true" @confirm="handleConfirm"></u-modal>
 
        <!-- 渲染题目 -->
        <Answer :isReviewed='isReview' :examType="examType" @submit='handleCommit' @timeEnd='handleConfirm'
            @onChange='onChange'></Answer>
 
        <u-toast ref="uToast" />
    </view>
</template>
 
<script>
    import Answer from '@/components/dyw-answer/answer.vue';
    import {
        enterExam
    } from '@/common/api/exam'
    import {
        ModifyQuesList
    } from '@/common/api/examFunc'
    export default {
        data() {
            return {
                show: false,
                content: '是否确认交卷',
                isReview: false,
                questionList: [],
                examType: 'exam', //考试类型
            }
        },
        onLoad(option) {
 
            this.examType = option.examType
            
            var that = this
            if (option.examType == 'exam') {
                // 理论考试
                enterExam({
                    idCardNo: option.id
                }).then(res => {
                    var examObj = res.data.data.simulateExamRecord
 
                    examObj.exam = {
                        name: '测试考试',
                        examScore: 100,
                        examTime: res.data.data.simulateExamRecord.answerTime,
                        checkFace: 1,
                        ...option
                    }
                    
                    
 
                    examObj.exam.totalQuestion = res.data.data.examSubjectInfo.length
                    examObj.totalQuestion = res.data.data.examSubjectInfo.length
                    that.$store.state.examDetail = examObj
 
                    // 提取出所有的题目
                    ModifyQuesList(res.data.data.examSubjectInfo)
                })
            } else if (option.examType == 'paper') {
                // 模拟考试
                this.$api.paperStart(option.paperId)
                    .then(res => {
                        console.log('paperStart:', res);
                        that.$store.state.examDetail = res.values
                        console.log('paper examDetail:', res.values);
                        var quesModules = res.values.modules
                        that.$api.ModifyQuesList(quesModules)
                        console.log(that.$store.state.pracDetail);
                        console.log(that.$store.state.pracQuesList);
                    })
            } else if (option.examType == 'know') {
                // 知识点练习
                const knowSearch = JSON.parse(decodeURIComponent(option.knowSearch));
                console.log(knowSearch);
                this.$api.startKnow(knowSearch)
                    .then(res => {
                        if (res.status == 1) {
                            // 获取知识点失败
                            this.$refs.uToast.show({
                                title: res.message,
                                type: 'error',
                                // icon: false,
                                url: '/pages/exam/pracIndexKnow'
                            })
                        } else {
                            console.log('开始知识点练习的请求结果:', res);
                            that.$store.state.examDetail = res.values
                            var quesModules = res.values.modules
                            that.$api.ModifyQuesList(quesModules)
                            console.log(that.$store.state.pracDetail);
                            console.log(that.$store.state.pracQuesList);
                        }
                    })
            } else if (option.examType == 'course') {
                this.$api.startTheory(that.$store.state.access_token, option.paperId)
                    .then(res => {
                        that.$store.state.examDetail = res.values
                        var quesModules = res.values.modules
                        that.$api.ModifyQuesList(quesModules)
                    })
            } else {
                console.log("考试类型错误,请输入正确的类型");
                // return false
            }
 
            console.log('考题列表:', this.questionList);
        },
        components: {
            Answer
        },
        methods: {
            /* 提交答案 显示再次确认*/
            handleCommit(questionList) {
                // 显示是否确认交卷
                this.show = true;
            },
 
            // 已确认进行答案提交
            handleConfirm() {
                // 进行交卷的api请求
                let that = this
                if (this.examType == 'exam') {
                    this.$api.commitExam(this.$store.state.examDetail.exam.id, this.$store.state.examDetail.recordId)
                        .then(res => {
                            console.log('交卷:', res);
                            that.$u.route('/pages/exam/examResultPage', {
                                recordId: that.$store.state.examDetail.recordId,
                                examType: 'exam'
                            })
                        })
                } else if ((this.examType == 'paper') || (this.examType == 'know')) {
                    this.$api.commitPaper(this.$store.state.examDetail.exerciseId)
                        .then(res => {
                            console.log('交卷:', res);
                            that.$u.route('/pages/exam/examResultPage', {
                                exerciseId: that.$store.state.examDetail.exerciseId,
                                examType: 'paper',
                            })
                        })
                } else if (this.examType == 'store') {
                    this.$api.commitExam(this.$store.state.examDetail.exam.id, this.$store.state.examDetail.recordId)
                        .then(res => {
                            console.log('交卷:', res);
                            that.$u.route('/pages/exam/examResultPage', {
                                recordId: that.$store.state.examDetail.recordId,
                                examType: 'exam'
                            })
                        })
                } else if (this.examType == 'course') {
                    this.$api.commitCourse(this.$store.state.access_token, this.$store.state.examDetail.exerciseId)
                        .then(res => {
                            console.log('交卷:', res);
                            that.$u.route('/pages/exam/examResultPage', {
                                exerciseId: that.$store.state.examDetail.exerciseId,
                                examType: 'course',
                            })
                        })
                } else {
                    console.log("提交的考试类型出错");
                }
            },
            /* 题目答案变化
             */
            onChange(answer) {
                console.log(answer)
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    page {
        background-color: #FFFFFF;
    }
</style>