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.

344 lines
8.1 KiB

3 years ago
<template>
<view class="containers">
<view class="steps">
3 months ago
<uni-steps :options="steps" :active="stepActive" active-color="#4f607e" />
1 month ago
</view>
<view class="expire" v-if="studyInfo.expire_day">
<view>通过测验后{{studyInfo.expire_day}}天内可不再重复学习</view>
<view class="en-text">After passing the test, you don't need to repeat learning within {{studyInfo.expire_day}} days.</view>
3 years ago
</view>
<view class="asks">
1 month ago
<view v-for="(item,index) in askList" :key="index">
<view class="question-title">
<view>{{index+1}}{{item.title}}({{item.type==1?'单选':'多选'}}{{item.type==1?'Single Choice':'Multiple Choice'}})</view>
</view>
3 years ago
<view v-if="item.type==1">
<uni-data-checkbox v-model="result[index]" @change="e=>radioAnswer(e,index)"
:localdata="item.answer" :wrap='true' :map="{text:'content',value:'content'}" />
</view>
<view v-if="item.type==2">
<uni-data-checkbox v-model="resultArr[index]" @change="e=>chenckAnswer(e,item,index)"
:localdata="item.answer" :wrap='true' multiple :map="{text:'content',value:'content'}" />
</view>
</view>
1 month ago
</view>
3 years ago
3 years ago
<view disabled class="justify-between submitBtn">
1 month ago
<view class="submit-text">
<text>需要正确率达{{rate}}%</text>
<text class="en-text">Need {{rate}}% accuracy rate</text>
</view>
<view class="submit-btn" @click="submitAnswer">
<text>提交</text>
<text class="en-text">Submit</text>
</view>
3 years ago
</view>
</view>
</template>
<script>
export default {
data() {
return {
type: 1,
steps: [{
1 month ago
title: '填报\nRegistration'
3 years ago
}, {
1 month ago
title: '测验\nTest'
3 years ago
}, {
1 month ago
title: '完成\nComplete'
3 years ago
}],
stepActive: 1,
studyInfo: {},
rate: 0,
askList: [],
correctNum: {},
3 years ago
answerList: [],
result: {}, //单选
resultArr: [], // 多选
1 month ago
formData: {},
askData:{},
3 years ago
askContent:[],
3 years ago
}
},
onLoad(options) {
let that = this
1 month ago
this.type = options.type
this.askData.type = parseInt(options.type)
// for(let i=0;i<20;i++){
// this.resultArr.push([])
// }
3 years ago
this.getFormdata()
1 month ago
this.getStudy()
3 years ago
},
1 month ago
methods: {
getFormdata(){
// let res = uni.getStorageSync('formdata')
// this.formData = res
let res = uni.getStorageSync('studydata')
this.askData = res
3 years ago
},
async getStudy() {
let that = this
this.util.request({
api: '/api/mobile/visit/get-ask',
data: {
type: that.type
},
utilSuccess: function(res) {
that.studyInfo = res
that.askList = res.asks
1 month ago
that.rate = parseInt(res.rate)
that.askData.ask = res.asks
that.askData.expire_day = res.expire_day
for(let i=0;i<res.asks.length;i++){
that.resultArr.push([])
3 years ago
}
3 years ago
},
utilFail: function(res) {}
})
},
// 获取选择的答案
3 years ago
radioAnswer(e, index) {
1 month ago
this.correctNum[index] = e.detail.data.result
3 years ago
this.askContent[index] = e.detail.data.content
3 years ago
},
chenckAnswer(e, item, index) {
let answer = item.answer
let correctLength = 0
let data = e.detail.data
for (var k of answer) {
if (k.result == 1) {
correctLength++
}
}
// 多选少于正确答案数量 返回0 错误
3 years ago
if (data.length != correctLength) {
3 years ago
this.correctNum[index] = 0
return
} else {
for (var m of data) {
if (m.result == 0) {
this.correctNum[index] = 0
} else {
this.correctNum[index] = 1
}
}
}
},
// 匹配答案正确率
submitAnswer() {
1 month ago
let correctLength = 0
3 years ago
console.log("this.correctNum",this.correctNum)
3 years ago
for (var key in this.correctNum) {
if (this.correctNum[key] == 1) {
correctLength++
}
}
let per = parseFloat(correctLength / this.askList.length) * 100
if (per < this.rate) {
1 month ago
this.util.alert("正确率不达标/The accuracy rate does not meet the standard")
3 years ago
} else {
this.submitForm()
}
},
submitForm() {
1 month ago
let that = this
this.resultArr.map((k,index)=>{
if(k.length>0){
this.askContent[index] = k
}
})
this.askData.content = this.askContent
console.log(this.result,this.resultArr,'---',this.askContent)
console.log("askdata",this.askData)
that.submitStudy()
2 years ago
return
3 years ago
this.util.request({
api: '/api/mobile/visit/visit-save',
method: "POST",
data: that.formData,
utilSuccess: function(res) {
1 month ago
uni.showToast({
title: res.msg,
duration: 2000,
icon: 'none'
})
3 years ago
that.newsSubscription()
3 years ago
},
1 month ago
utilFail: function(res) {
console.log(res)
uni.showToast({
title: res,
duration: 2000,
icon: 'none'
})
}
})
},
submitStudy() {
let that = this
console.log("that.askData",that.askData)
// return
this.util.request({
api: '/api/mobile/visit/ask-save',
method: "POST",
data: that.askData,
utilSuccess: function(res) {
if(uni.getStorageSync('studydata')){
uni.removeStorageSync('studydata')
}
uni.showToast({
title: '提交成功',
duration: 1500,
icon: 'none'
})
setTimeout(function(){
uni.redirectTo({
url: '/pages/index/index'
})
},1500)
},
utilFail: function(res) {
uni.showToast({
title: res,
duration: 2000,
icon: 'none'
})
3 years ago
}
})
1 month ago
},
newsSubscription() {
uni.getSetting({
withSubscriptions: true, //是否获取用户订阅消息的订阅状态默认false不返回
success(res) {
if (res.authSetting['scope.subscribeMessage']) {
uni.removeStorageSync('formdata')
uni.redirectTo({
url: '/pages/visit/successform'
})
} else {
// 用户没有点击“总是保持以上,不再询问”则每次都会调起订阅消息
uni.requestSubscribeMessage({
2 months ago
tmplIds: ['OfDFwAIZyXqvPgmc_czIXhveVtp3n_ftyWJEks1DSi4',
1 month ago
'r8n41lmkGeob15YBuuxhG7MbpgVSsUxKnK9ORPtr5VY'],
success(res) {
console.log("res", res)
uni.showToast({
title:'订阅成功'
})
uni.removeStorageSync('formdata')
uni.redirectTo({
url: '/pages/visit/successform'
})
}
})
}
}
});
3 years ago
},
3 years ago
}
}
</script>
<style scoped>
.containers {
background-color: #fff;
padding: 20rpx;
padding-bottom: 60rpx;
1 month ago
position: relative;
3 years ago
overflow: hidden;
3 years ago
}
1 month ago
.asks {
min-height: 80vh;
overflow-y: auto;
padding-bottom:60rpx
3 years ago
}
3 years ago
.asks>view,
.asks>view>view {
margin-bottom: 20rpx
}
.containers>.submitBtn {
3 years ago
position: fixed;
bottom: 0;
1 month ago
width: 100%;
2 years ago
left:0
3 years ago
}
1 month ago
.containers>.submitBtn .submit-text {
display: flex;
padding: 28rpx 20rpx;
3 years ago
width: 70%;
background-color: #f8f8f8;
1 month ago
border-radius: 10rpx 0 0 10rpx;
3 years ago
}
1 month ago
.containers>.submitBtn .submit-btn {
3 years ago
width: 30%;
3 months ago
background-color: #4f607e;
3 years ago
color: #fff;
1 month ago
display: flex;
border-radius: 0 10rpx 10rpx 0;
padding: 28rpx 10rpx;
cursor: pointer;
3 years ago
}
.steps {
margin-bottom: 40rpx
}
1 month ago
.expire{
text-align: center;
font-size: 40rpx;
/* padding: 10px; */
margin-bottom: 40rpx;
display: flex;
flex-direction: column;
}
.expire .en-text {
font-size: 28rpx;
color: #999;
margin-top: 8rpx;
}
.question-title {
margin-bottom: 20rpx;
}
.question-title .en-text {
font-size: 24rpx;
color: #999;
margin-top: 6rpx;
}
.submit-text {
display: flex;
flex-direction: column;
justify-content: center;
padding-left: 20rpx;
}
.submit-text .en-text {
font-size: 22rpx;
color: #666;
margin-top: 4rpx;
}
.submit-btn {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.submit-btn .en-text {
font-size: 20rpx;
opacity: 0.9;
margin-top: 2rpx;
}
</style>