|
@@ -1,19 +1,15 @@
|
1
|
1
|
<template>
|
2
|
|
- <div>
|
3
|
|
- <QuestionnHome />
|
4
|
|
- <!-- <img :src="backgeImg" class="ImagStyle" /> -->
|
5
|
|
- <popup
|
6
|
|
- :show="showPopup"
|
7
|
|
- @confirm="submitForm(currentQuestion.rightAnswer)"
|
8
|
|
- @cancel="cancelForm"
|
9
|
|
- :showCancel="true"
|
10
|
|
- :LoadingShow="LoadingShowAAA"
|
11
|
|
- :title="'确定提交答案吗'"
|
12
|
|
- :confirmText="`提交`"
|
13
|
|
- :cancelText="`取消提交`"
|
|
2
|
+ <div class="question-wrapper">
|
|
3
|
+ <QuestionnHome :show="showFirstScreen" :content="questionnaireContent" @confirm="showFirstScreen = false" />
|
|
4
|
+
|
|
5
|
+ <van-dialog
|
|
6
|
+ v-model="showPopup"
|
|
7
|
+ title="确定提交答案吗"
|
|
8
|
+ show-cancel-button
|
|
9
|
+ @confirm="submitForm()"
|
14
|
10
|
>
|
15
|
|
- <p>确定要提交答案吗?提交后内容不可更改!</p>
|
16
|
|
- </popup>
|
|
11
|
+ <p style="margin: 2em">确定要提交答案吗?</p>
|
|
12
|
+ </van-dialog>
|
17
|
13
|
|
18
|
14
|
<!-- 页面标题 -->
|
19
|
15
|
<div class="VSTD_box" v-if="questionList.length > 0">
|
|
@@ -25,27 +21,14 @@
|
25
|
21
|
<!-- 循环后端 的所有题 -->
|
26
|
22
|
<div class="VSTD_box_item">
|
27
|
23
|
<question
|
28
|
|
- :types="questionList[netx].questionType"
|
29
|
|
- :question="currentQuestion"
|
30
|
|
- :serial-no="netx + 1"
|
31
|
|
- v-model="currentQuestion.rightAnswer"
|
|
24
|
+ :step="step + 1"
|
|
25
|
+ :steps="total"
|
|
26
|
+ v-model="currentQuestion"
|
|
27
|
+ @next="step++"
|
|
28
|
+ @prev="step--"
|
|
29
|
+ @submit="showPopup = true"
|
32
|
30
|
></question>
|
33
|
|
-
|
34
|
|
- <div class="but-box">
|
35
|
|
- <van-form class="but-box-form-item">
|
36
|
|
- <van-button class="butsize" v-show="ButPrevious" @click="PreviousBut">上一题</van-button>
|
37
|
|
- <van-button
|
38
|
|
- type="info"
|
39
|
|
- class="butsize"
|
40
|
|
- v-show="Butnetx"
|
41
|
|
- @click="netxBut(currentQuestion.rightAnswer)"
|
42
|
|
- >下一题</van-button>
|
43
|
|
- <van-button type="info" class="butsize" v-show="Butsubmit" @click="firstSubmit">提交</van-button>
|
44
|
|
- </van-form>
|
45
|
|
- </div>
|
46
|
31
|
</div>
|
47
|
|
-
|
48
|
|
- <!-- 提交函数 -->
|
49
|
32
|
</van-form>
|
50
|
33
|
</div>
|
51
|
34
|
|
|
@@ -61,8 +44,8 @@
|
61
|
44
|
</template>
|
62
|
45
|
|
63
|
46
|
<script>
|
64
|
|
-import { getQuestion, getQuestionInfo, getQuestionAnswer } from '@/util/api'
|
65
|
|
-// import query from '@/util/query'
|
|
47
|
+import { Toast } from 'vant';
|
|
48
|
+import { getQuestionnaire, getQuestion, answerQuestionnaire } from '@/util/api'
|
66
|
49
|
|
67
|
50
|
export default {
|
68
|
51
|
name: 'QuestionDetail',
|
|
@@ -74,132 +57,66 @@ export default {
|
74
|
57
|
props: {},
|
75
|
58
|
data() {
|
76
|
59
|
return {
|
|
60
|
+ showFirstScreen: true,
|
|
61
|
+ questionnaireContent: {},
|
|
62
|
+
|
77
|
63
|
showPopup: false,
|
78
|
|
- LoadingShowAAA: false,
|
79
|
|
- // backgeImg: require('../assets/bgc.png'),
|
80
|
|
- netx: 0, //第一题第二题下标
|
81
|
|
- startData: null,
|
82
|
|
- endData: null,
|
83
|
|
- ButPrevious: false, //上一题
|
84
|
|
- Butsubmit: false, //提交
|
85
|
|
- Butnetx: true, //下一题
|
86
|
|
-
|
87
|
|
- indexSum: 0, //第indexSum题
|
88
|
|
- // questionId: '', //试题的id
|
89
|
|
- title: '', //返回的题目信息
|
90
|
|
- questionList: [], //答题保存的数组
|
91
|
|
-
|
92
|
|
- DSQ: null, //定时器,到时间自动提交
|
93
|
|
- DSQTime: 0 //后端返回的结束时间
|
|
64
|
+ step: 0,
|
|
65
|
+ total: 0,
|
|
66
|
+ questionList: []
|
94
|
67
|
}
|
95
|
68
|
},
|
96
|
69
|
computed: {
|
97
|
70
|
currentQuestion: {
|
98
|
71
|
get: function () {
|
99
|
|
- return this.questionList[this.netx]
|
|
72
|
+ return this.questionList[this.step]
|
100
|
73
|
},
|
101
|
74
|
set: function (val) {
|
102
|
|
- this.$set(this.questionList, this.netx, val)
|
|
75
|
+ this.$set(this.questionList, this.step, val)
|
103
|
76
|
}
|
104
|
77
|
}
|
105
|
78
|
},
|
106
|
|
- created() {
|
107
|
|
- // findIndex 用来获取数组中第一个满足条件的元素下标
|
108
|
|
- var v = this.questionList.findIndex((value, index, arr) => {
|
109
|
|
- return value.a == '2'
|
110
|
|
- })
|
111
|
|
- },
|
112
|
|
-
|
113
|
|
- mounted() {
|
114
|
|
- this.onSearch()
|
|
79
|
+ watch: {
|
|
80
|
+ '$route.query.id': {
|
|
81
|
+ handler(v) {
|
|
82
|
+ this.loadData(v)
|
|
83
|
+ },
|
|
84
|
+ immediate: true
|
|
85
|
+ }
|
115
|
86
|
},
|
116
|
|
-
|
117
|
87
|
methods: {
|
118
|
|
- cancelForm() {
|
119
|
|
- this.showPopup = false
|
120
|
|
- console.log('点击了取消')
|
121
|
|
- },
|
|
88
|
+ loadData(id) {
|
|
89
|
+ // 问卷信息
|
|
90
|
+ getQuestionnaire(id).then((e) => {
|
|
91
|
+ this.questionnaireContent = e || {}
|
|
92
|
+ })
|
122
|
93
|
|
123
|
|
- onSearch() {
|
124
|
|
- getQuestion('f5a47d178019bda33a370d7a6ed1e4c3').then((res) => {
|
|
94
|
+ // 问题列表
|
|
95
|
+ getQuestion(id).then((res) => {
|
125
|
96
|
console.log('题目列表', res)
|
126
|
97
|
const { records, total } = res
|
127
|
98
|
this.questionList = records || []
|
|
99
|
+ this.total = total
|
128
|
100
|
})
|
129
|
101
|
// let sum = 0
|
130
|
102
|
},
|
131
|
|
- firstSubmit() {
|
132
|
|
- this.showPopup = true
|
133
|
|
- },
|
|
103
|
+
|
134
|
104
|
submitForm(e) {
|
135
|
|
- this.LoadingShowAAA = true
|
136
|
|
- console.log('🚀 ~ f e', e)
|
137
|
|
- // const { questionId, rightAnswer } = this.question
|
138
|
|
- console.log(this.questionList)
|
139
|
|
-
|
140
|
|
- let NEW_ARR = this.questionList.map((obj) => {
|
141
|
|
- if (Array.isArray(obj.rightAnswer)) {
|
142
|
|
- let sliceArray = obj.rightAnswer.slice(1)
|
143
|
|
- let stringArray = sliceArray.sort().toLocaleString()
|
144
|
|
-
|
145
|
|
- return { questionId: obj.questionId, answer: stringArray }
|
146
|
|
- } else {
|
147
|
|
- return { questionId: obj.questionId, answer: obj.rightAnswer }
|
148
|
|
- }
|
149
|
|
- })
|
150
|
|
- console.log(NEW_ARR)
|
151
|
|
-
|
152
|
|
- getQuestionAnswer(
|
153
|
|
- 'f5a47d178019bda33a370d7a6ed1e4c3',
|
154
|
|
- // answerOpt: '22',
|
155
|
|
- // answerText: '1',
|
156
|
|
- // personId: this.$store.state.user.personId,
|
157
|
|
- // questionId: 'f5a47d178019bda33a370d7a6ed1e4c3',
|
158
|
|
- // score: '1'
|
159
|
|
- NEW_ARR
|
160
|
|
- ).then((e) => {
|
161
|
|
- console.log(e.score, e)
|
162
|
|
- // this.$store.commit('SET_USER_INFO', { scoreNumb: e.result.score })
|
163
|
|
- // this.$store.commit('SET_USER_INFO', { resultInfo: e.result.resultId })
|
164
|
|
- this.LoadingShowAAA = false
|
165
|
|
- this.showPopup = false
|
166
|
|
-
|
167
|
|
- this.$router.go(-1) //replace 不记录页面 ,无法返回
|
|
105
|
+ const toast = Toast.loading({
|
|
106
|
+ duration: 0, // 持续展示 toast
|
|
107
|
+ forbidClick: true,
|
|
108
|
+ message: '请稍后...',
|
|
109
|
+ });
|
|
110
|
+ answerQuestionnaire(this.$route.query.id, this.questionList).then(e => {
|
|
111
|
+ toast.clear();
|
|
112
|
+ Toast.success('感谢您的参与');
|
|
113
|
+ this.questionnaireContent.isAnswered = true
|
|
114
|
+ this.showFirstScreen = true
|
|
115
|
+ }).catch(e => {
|
|
116
|
+ toast.clear();
|
|
117
|
+ Toast.fail(e.message);
|
168
|
118
|
})
|
169
|
119
|
},
|
170
|
|
-
|
171
|
|
- netxBut(e) {
|
172
|
|
- if (e !== null) {
|
173
|
|
- if (this.netx >= this.questionList.length - 2) {
|
174
|
|
- this.Butnetx = false
|
175
|
|
- this.Butsubmit = true
|
176
|
|
- }
|
177
|
|
- if (this.netx <= this.questionList.length - 2) {
|
178
|
|
- this.netx = this.netx + 1
|
179
|
|
- this.ButPrevious = this.ButPrevious = true
|
180
|
|
- this.indexSum = this.indexSum + 1
|
181
|
|
- }
|
182
|
|
- } else {
|
183
|
|
- this.$message.warning('请选择至少一项')
|
184
|
|
- }
|
185
|
|
- },
|
186
|
|
-
|
187
|
|
- PreviousBut() {
|
188
|
|
- if (this.netx >= 1) {
|
189
|
|
- this.Butnetx = true
|
190
|
|
- this.Butsubmit = false
|
191
|
|
- }
|
192
|
|
- if (this.netx <= 1) {
|
193
|
|
- this.ButPrevious = this.ButPrevious = false
|
194
|
|
- this.Butnetx = true
|
195
|
|
- }
|
196
|
|
- if (this.netx <= 0) {
|
197
|
|
- console.log('???', this.netx, this.questionList.length)
|
198
|
|
- } else {
|
199
|
|
- this.netx = this.netx - 1
|
200
|
|
- this.indexSum = this.indexSum - 1
|
201
|
|
- }
|
202
|
|
- }
|
203
|
120
|
}
|
204
|
121
|
}
|
205
|
122
|
</script>
|
|
@@ -208,6 +125,13 @@ export default {
|
208
|
125
|
|
209
|
126
|
|
210
|
127
|
<style lang="less" scoped>
|
|
128
|
+
|
|
129
|
+.question-wrapper {
|
|
130
|
+ background-image: url('~@/assets/userImag/backImag.png');
|
|
131
|
+ background-size: 100%;
|
|
132
|
+ background-repeat: no-repeat;
|
|
133
|
+}
|
|
134
|
+
|
211
|
135
|
.ImagStyle {
|
212
|
136
|
width: 100%;
|
213
|
137
|
}
|