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.
142 lines
3.8 KiB
142 lines
3.8 KiB
<template>
|
|
<view class="flex flex-col p-3">
|
|
<!-- 全局提示框 -->
|
|
<u-top-tips ref="uTips"></u-top-tips>
|
|
|
|
<!-- 有一页 -->
|
|
<view v-if="questionInfo.questions.length === 1">
|
|
<answerPage :turnPages="true" :question="questionInfo.questions[0]" ref="child" @nextQuestion="nextQuestion" />
|
|
</view>
|
|
|
|
<!-- 有两页 -->
|
|
<view v-if="questionInfo.questions.length === 2">
|
|
<promptPage @openAnswerPage="openAnswerPage" v-if="!showAnswerPage" :question="questionInfo.questions[0]" />
|
|
<answerPage v-else :turnPages="true" :question="questionInfo.questions[1]" ref="child" @nextQuestion="nextQuestion" />
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex';
|
|
import promptPage from './components/Test/promptPage';
|
|
import answerPage from './components/Test/answerPage';
|
|
|
|
export default {
|
|
components: { promptPage, answerPage },
|
|
|
|
data() {
|
|
return { showAnswerPage: false, param: {} };
|
|
},
|
|
|
|
watch: {
|
|
questionInfo(val) {
|
|
if (val) {
|
|
this.showAnswerPage = false;
|
|
this.setOptionId('');
|
|
}
|
|
},
|
|
},
|
|
|
|
computed: {
|
|
...mapState('project', ['project']),
|
|
...mapState('yanyuan', ['questionInfo', 'optionId']),
|
|
...mapState('task', ['task']),
|
|
...mapGetters('user', ['userId']),
|
|
},
|
|
|
|
methods: {
|
|
...mapMutations('task', ['setIsEvaluated']),
|
|
...mapMutations('yanyuan', ['setQuestionInfo', 'setAssessResult', 'setOptionId']),
|
|
...mapActions('yanyuan', ['handleQuestion']),
|
|
|
|
// 第二页
|
|
openAnswerPage() {
|
|
this.showAnswerPage = true;
|
|
},
|
|
|
|
// 设置参数
|
|
setParams() {
|
|
const { optionId, questionInfo, task } = this;
|
|
this.param = {
|
|
code: 'NLCP',
|
|
optionId: optionId,
|
|
questionId: questionInfo.id,
|
|
reportId: task.id,
|
|
};
|
|
return this.param;
|
|
},
|
|
|
|
/**
|
|
* 下一题
|
|
* @param { string } code 题目code NLCP:脑力测评 ZARIT:照顾者负担量表
|
|
* @param { string } optionId 选项ID
|
|
* @param { string } questionId 题目ID
|
|
* @param { string } reportId 测评ID 脑力测评ID或zaritID
|
|
*/
|
|
async nextQuestion() {
|
|
try {
|
|
this.$refs.child.openLoading();
|
|
const param = this.setParams();
|
|
await this.$u.api.saveAnswer(param);
|
|
await this.next();
|
|
this.$refs.child.closeLoading();
|
|
} catch (error) {
|
|
console.error('error: ', error);
|
|
this.$t.ui.showToast(error.msg || '提交失败');
|
|
this.$refs.child.closeLoading();
|
|
}
|
|
},
|
|
|
|
// 提交答案的下一步
|
|
async next() {
|
|
const { questionInfo, task } = this;
|
|
if (questionInfo.numStatus === 2) {
|
|
await this.submitAnswer();
|
|
} else {
|
|
const params = {
|
|
code: 'NLCP',
|
|
reportId: task.id,
|
|
num: questionInfo.num + 1,
|
|
};
|
|
await this.handleQuestion(params);
|
|
}
|
|
},
|
|
|
|
// 提交答案
|
|
async submitAnswer() {
|
|
try {
|
|
const params = { mentalTestId: this.task.id };
|
|
const data = await this.$u.api.mentalTestCalculate(params);
|
|
this.setAssessResult(data);
|
|
this.$refs.uTips.show({
|
|
title: '答案提交成功, 即将返回上一页',
|
|
type: 'success',
|
|
duration: '2000',
|
|
});
|
|
setTimeout(() => {
|
|
this.back();
|
|
}, 2000);
|
|
} catch (error) {
|
|
console.error('error: ', error);
|
|
this.$t.ui.showToast(error.msg || '提交失败');
|
|
}
|
|
},
|
|
|
|
// 返回时间轴
|
|
back() {
|
|
this.setIsEvaluated(true);
|
|
|
|
const { name, id, url } = this.project;
|
|
url && (uni.$t.domain = url);
|
|
this.$u.route('/pagesProject/project/project', {
|
|
u: this.userId,
|
|
p: id,
|
|
pname: name,
|
|
url: encodeURIComponent(url),
|
|
});
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style scoped lang="scss"></style>
|
|
|