You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

378 lines
8.9 KiB

2 years ago
<template>
<view class='wrap'>
2 years ago
<view class='detail'>
<view class="detail-audio" v-if="detailInfo.video">
<view class="detail-audio-text">{{detailInfo.video?splitName(detailInfo.video.original_name):''}}</view>
<view class="detail-audio-play">
<free-audio startPic='../../static/detail-play.png' endPic='../../static/detail-stop.png'
audioId='audio1' :url="detailInfo.video?detailInfo.video.url:''"></free-audio>
2 years ago
</view>
</view>
2 years ago
<view class="detail-answer" v-if="question_list.length>0">
<view v-for="(item,index) in question_list">
<view class="detail-answer-item" v-if="index===currentIndex">
<view class='detail-answer-item-title'>
<span :class="{'detail-answer-item-title-more':item.type_name==='多选题'}">{{item.type_name}}</span>
<text v-html="item.title"></text>
</view>
<view class='detail-answer-answer'>
<view :class="{'detail-answer-answer-active':q.flag,
'detail-answer-answer-disbaled':showAnswer,
'detail-answer-answer-correct':q.is_correct===1&&showAnswer,
'detail-answer-answer-wrong':q.is_correct===0&&q.flag,}"
class="detail-answer-answer-item"
@click="answerChoose(item,q,qindex)" v-for="(q,qindex) in item.options">
<span>{{answerNum[qindex]}}</span>
<span>{{q.title}}</span>
</view>
<view class="detail-answer-answer-correctAnswer" v-if="showAnswer">
正确答案{{item.correctAnswer.join("、")}}
</view>
</view>
</view>
</view>
2 years ago
<view class="detail-btn" v-if="!isSubmit">
2 years ago
<view v-if="currentIndex<question_list.length-1" class="detail-btn-next" @click="next">
下一题
</view>
<view v-else class="detail-btn-next" :class="{'detail-btn-disabled':isSubmit}" @click="submit">
完成打卡
</view>
</view>
2 years ago
<view class="detail-btn" v-else>
2 years ago
<view class="detail-btn-next" @click="goMap">
返回地图
</view>
2 years ago
</view>
2 years ago
</view>
</view>
</view>
</template>
<script>
2 years ago
import freeAudio from '@/components/free-audio.vue'
import {toast} from '@/common/util.js'
2 years ago
export default {
2 years ago
components: {
freeAudio
},
2 years ago
data() {
return {
2 years ago
detailInfo: {},
question_list: [],
currentIndex: 0,
answerNum: ["A", "B", "C", "D", "E", "F", "G", "H"],
myAnswers:[],
hasAnswer:false,
// goBack:false,
showAnswer:false,
2 years ago
isSubmit:false,
isNext:false
2 years ago
};
},
methods: {
async getDetail(id) {
const res = await this.$u.api.pointDetail({
2 years ago
id:id
2 years ago
})
2 years ago
this.detailInfo = res.points
},
splitName(str){
if(str.indexOf(".")>-1){
return str.split(".")[0]
}else{
return str
}
2 years ago
},
2 years ago
async getQuestion() {
let res = await this.$u.api.getQuestions()
res.questions.map(item => {
let type = 0
item.correctAnswer = []
item.options.map(i => {
i.flag = false
if (i.is_correct === 1) {
type++
item.correctAnswer.push(this.answerNum[i.myindex - 1])
}
})
item.type_name = type > 1 ? '多选题' : '单选题'
item.title = this.replaceAtSymbolsWithSpan(item.title)
2 years ago
})
2 years ago
this.question_list = res.questions
console.log(this.question_list)
2 years ago
},
2 years ago
replaceAtSymbolsWithSpan(str) {
return str.replace(/@/g,
'<span style="display: inline-block;width:40px;border-bottom:1px solid #666;margin: 0 3px;margin-bottom: -2px;"></span>'
);
},
answerChoose(item,q,qindex){
this.hasAnswer = false
if(item.type_name==='单选题'){
item['options'].map((item1,index1)=>{
item1.flag = false
if(qindex===index1){
q.flag = true
this.hasAnswer = true
}
})
}else if(item.type_name==='多选题'){
q.flag = !q.flag
item['options'].map((item1,index1)=>{
if(item1.flag===true){
this.hasAnswer = true
}
})
}
},
next(){
if(!this.hasAnswer){
toast('请先答题')
return
}
2 years ago
if(this.isNext){
2 years ago
return
}
2 years ago
this.isNext = true
2 years ago
if(this.currentIndex==this.question_list.length-1){
uni.showLoading({title:'提交中'})
2 years ago
2 years ago
}
this.showAnswer = true
let answer_id = []
let that = this
this.question_list[this.currentIndex]['options'].map(item=>{
if(item.flag===true){
answer_id.push(item.id)
}
})
this.myAnswers.push({
question_id: this.question_list[this.currentIndex].id,
answer_ids: answer_id.join('')
})
setTimeout(function(){
if(that.currentIndex==that.question_list.length-1){
that.$u.api.saveQuiz({
point_id: that.$route.query?.id,
answers: that.myAnswers
}).then(res=>{
uni.hideLoading()
2 years ago
that.isSubmit = true
toast("打卡成功")
// toast('打卡成功',1000,function(){
// setTimeout(function(){
// uni.redirectTo({
// url:'/pages/map/map'
// })
// },500)
2 years ago
2 years ago
// })
2 years ago
})
// .then(res=>{
// uni.hideLoading()
// that.isSubmit = false
// })
}else{
that.currentIndex++
that.showAnswer = false
that.hasAnswer = false
2 years ago
that.isNext = false
2 years ago
}
2 years ago
},1000)
2 years ago
// if(this.currentIndex<this.question_list.length-1){
// setTimeout(function(){
// that.currentIndex++
// this.$u.api.saveQuiz({
// point_id: this.$route.query?.id,
// answers: this.myAnswers
// }).then(res=>{
// toast('打卡成功')
// this.goBack = true
// })
// this.showAnswer = false
// },2000)
// }else{
// console.log(this.myAnswers)
// console.log("okk")
// this.$u.api.saveQuiz({
// point_id: this.$route.query?.id,
// answers: this.myAnswers
// }).then(res=>{
// toast('打卡成功')
// this.goBack = true
// })
// }
},
submit(){
this.next()
},
goMap(){
uni.redirectTo({
url:'/pages/map/map'
})
2 years ago
}
},
2 years ago
onLoad(option) {
console.log("this.vuex_point_id",this.vuex_point_id)
this.getDetail(option.id)
this.getQuestion()
2 years ago
},
2 years ago
onUnload() { //普通页面在 onUnload 生命周期中执行
uni.$emit('stop')
console.log("onUnload")
},
onHide() { //tabBar页面在onHide生命周期中执行
uni.$emit('stop')
console.log("onHide")
},
beforeDestroy() {
uni.$emit('stop')
}
2 years ago
}
</script>
<style lang="scss">
.wrap {
2 years ago
background: url(../../static/detail-bg1.png) top left;
2 years ago
background-size: 100% 100%;
2 years ago
background-color: rgba(0, 0, 0, 0.5);
2 years ago
width: 100vw;
2 years ago
height: 100vh;
2 years ago
overflow: scroll;
2 years ago
padding: 20rpx;
padding-top: 125rpx;
// padding-bottom:0;
.detail {
&-audio {
background: #fff;
border-radius: 10rpx;
padding: 30rpx 20rpx;
min-height: 200rpx;
&-text {
color: #000000;
2 years ago
font-size: 32rpx;
padding-left:30rpx;
2 years ago
}
2 years ago
}
&-answer{
background: #fff;
border-radius: 10rpx 10rpx 0 0;
padding: 30rpx 20rpx;
margin-top:30rpx;
&-item{
border-bottom:1px solid #ddd;
margin:0 -20rpx;
margin-bottom:30rpx;
&-title{
padding:30rpx;
line-height: 1.8;
font-family: "宋体";
color: rgba(0,0,0,0.8);
span{
background-color: #d7b245;
display: inline-block;
padding:0rpx 20rpx;
color:#fff;
margin-right:10rpx;
border-radius: 10rpx;
font-weight: normal;
}
&-more{
background-color: cadetblue;
}
}
}
&-answer{
padding:30rpx;
padding-top:0;
&-item{
padding:20rpx 30rpx;
border:2px solid transparent;
border-radius:20rpx;
margin-bottom:20rpx;
span:first-child{
display: inline-block;
width:40rpx;
height:40rpx;
border:2px solid #999;
color:#999;
text-align: center;
line-height: 40rpx;
border-radius: 10rpx;
margin-right:10rpx
}
}
&-disbaled{
pointer-events: none;
}
&-active{
border:2px solid #d22425;
span:first-child{
border:2px solid #d22425;
background:#d22425;
color:#fff;
}
}
&-correct{
border:2px solid #56b81b;
span:first-child{
border:2px solid #56b81b;
background:#56b81b;
color:#fff;
}
}
&-wrong{
border:2px solid #d22425;
span:first-child{
border:2px solid #d22425;
background:#d22425;
color:#fff;
}
}
&-correctAnswer{
color:#333333;
padding-left:34rpx;
}
}
}
&-btn{
&-next{
box-shadow: 0.5px 3px 9px 0px rgba(235,107,85,0.3);
background:#e50015;
border-radius: 44rpx;
text-align: center;
height:88rpx;
color:#fff;
line-height: 88rpx;
font-size: 34rpx;
}
&-disabled{
background:#ddd;
}
}
2 years ago
}
}
</style>