uniapp选择题
页面部分代码
<view class="content">
<view class="all">
<view class="maintop">
<text v-if="itempage==0" style="font-weight: bold;">1</text><text v-else="itempage!=0" style="font-weight: bold;">{{itempage/7+1}}</text>
<text style="color: #808080;">/{{ti.length/7}}</text>
<text v-if="ti[itempage+1].dd.length>1"class="btncs">多选题</text>
<text v-if="ti[itempage+1].dd.length==1" class="btncs">单选题</text>
</view>
<view v-for="(item,index) in ti.slice(itempage,itempage+7)" class="main">
<view class="titles">{{item.date}}</view>
<view class="chiose" v-for="(answ,i) in item.roomNums" @click="getansw(answ,item,i)" :key="i">
<view v-if="checkArry.indexOf(i) !=-1" class="imgc"></view>
<view v-if="checkArry.indexOf(i) ==-1" class="imgc1"></view>
<text>{{answ.right}}.{{answ.name}}</text>
</view>
</view>
</view>
<view v-for="(item,index) in ti.slice(itempage,itempage+7)" v-if="item.has==true" class="next">
<view class="nexts1">
<text style="font-size: 32rpx;">正确答案</text>:<text style="color: red;font-size: 32rpx;" v-for="dd in ti[itempage+1].dd">{{dd}}</text>
</view>
<button v-if="itempage/7+1!=ti.length/7" @click="next()" class="nexts2">下一题</button>
<button v-if="itempage/7+1==ti.length/7" @click="next()" class="nexts2" @tap="navchouj()">抽奖</button>
</view>
</view>
js代码
<script>
export default {
data() {
return {
chiosed:-1,
xz:false,
show:0,
fail:0,
title: '生态环境保护知识竞赛',
openid: '',
userImg: '',
userName: '',
defen: 0,
itempage: 0,
ti: [],
}
},
onLoad() {
},
methods: {
getansw(answ, item,i) {
let that = this;
if (that.checkArry.indexOf(i) == -1&&that.ti[that.itempage + 5].chioseNum + 1 <= that.ti[that.itempage + 1].dd.length) {
that.checkArry.push(i);
} else {
}
that.xz=true;
that.chiosed=i;
that.ti[that.itempage + 2].chiosed = answ.right;
if (that.ti[that.itempage + 5].chioseNum + 1 == that.ti[that.itempage + 1].dd.length) {
if (that.ti[that.itempage + 3].chiose.indexOf(answ.right) == -1 && that.ti[that.itempage + 1].dd.indexOf(answ.right) !=-1) {
that.ti[that.itempage + 3].chiose.push(answ.right);
that.ti[that.itempage + 5].chioseNum = that.ti[that.itempage + 5].chioseNum + 1;
that.ti[that.itempage + 2].has = true;
that.defen += 1;
that.fail+=1;
setTimeout(function () {
if(that.fail<that.ti.length/7){
that.itempage = 7 + that.itempage;
that.chiosed=-1;
that.checkArry=[];
}
},1200);
} else if (that.ti[that.itempage + 3].chiose.indexOf(answ.right) == -1 && that.ti[that.itempage + 1].dd.indexOf(answ.right) == -1) {
that.ti[that.itempage + 3].chiose.push(answ.right);
that.ti[that.itempage + 5].chioseNum = that.ti[that.itempage + 1].dd.length;
that.ti[that.itempage + 2].has = true;
that.fail+=1;
that.defen += 0;
} else {
}
} else if (that.ti[that.itempage + 5].chioseNum + 1 < that.ti[that.itempage + 1].dd.length) {
if (that.ti[that.itempage + 3].chiose.indexOf(answ.right) == -1 && that.ti[that.itempage + 1].dd.indexOf(answ.right) !=-1) {
that.ti[that.itempage + 3].chiose.push(answ.right);
that.ti[that.itempage + 5].chioseNum = that.ti[that.itempage + 5].chioseNum + 1;
} else if (that.ti[that.itempage + 3].chiose.indexOf(answ.right) == -1 && that.ti[that.itempage + 1].dd.indexOf(answ.right) == -1) {
that.ti[that.itempage + 3].chiose.push(answ.right);
that.ti[that.itempage + 5].chioseNum = that.ti[that.itempage + 1].dd.length;
that.ti[that.itempage + 2].has = true;
that.fail+=1;
that.defen += 0;
} else {
}
} else {
}
}
}
</script>