|
@@ -34,8 +34,8 @@
|
|
|
teamQuestionnaireId:'',
|
|
|
list:[],
|
|
|
questionnaire:null,
|
|
|
- isLoading: true, // 新增加载状态
|
|
|
- isSubmitting: false // 新增提交状态
|
|
|
+ isLoading: true,
|
|
|
+ isSubmitting: false
|
|
|
}
|
|
|
},
|
|
|
onLoad(option) {
|
|
@@ -56,7 +56,9 @@
|
|
|
if (item.warn) {
|
|
|
this.$set(item, 'warn', false);
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setQuestionnaireCache();
|
|
|
},
|
|
|
getList(){
|
|
|
let questionnaire = null;
|
|
@@ -103,7 +105,6 @@
|
|
|
});
|
|
|
|
|
|
if (firstUnansweredIndex > -1) {
|
|
|
- // 使用 uni.showModal 以提供更好的用户体验
|
|
|
return uni.showModal({
|
|
|
title: '提示',
|
|
|
content: `第 ${firstUnansweredIndex + 1} 项未选择答案,请选择。`,
|
|
@@ -111,49 +112,42 @@
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- // 使用更清晰的逻辑构建提交数据
|
|
|
const submitList = this.list.map(question => {
|
|
|
- // 映射 userAnswer 数组,并添加一个清晰的 `isSelected` 字段
|
|
|
const formattedUserAnswer = question.userAnswer.map(option => ({
|
|
|
...option,
|
|
|
- // 假设后端需要一个布尔值来表示是否选中
|
|
|
isSelected: option.questionOption === question.answer
|
|
|
}));
|
|
|
|
|
|
- // 剔除前端专用的字段(answer, warn),保持提交数据纯净
|
|
|
const { answer, warn, ...restOfQuestion } = question;
|
|
|
|
|
|
return {
|
|
|
...restOfQuestion,
|
|
|
- isAnswer: '1', // 标记为已作答
|
|
|
- userAnswer: formattedUserAnswer // 使用格式化后的数组
|
|
|
+ isAnswer: '1',
|
|
|
+ userAnswer: formattedUserAnswer
|
|
|
};
|
|
|
});
|
|
|
|
|
|
this.isSubmitting = true;
|
|
|
this.$api.post('/core/team/member/answer/submit', submitList).then(res => {
|
|
|
if (res.data.code !== 0) {
|
|
|
- // 在失败时也应该重置提交状态
|
|
|
this.isSubmitting = false;
|
|
|
return this.$showToast(res.data.msg);
|
|
|
}
|
|
|
uni.removeStorageSync('questionnaire');
|
|
|
- // 提交成功后建议使用 redirectTo 或 reLaunch,防止用户返回到填写页
|
|
|
uni.redirectTo({
|
|
|
url: '/pages/questionnaireResult'
|
|
|
});
|
|
|
}).catch(err => {
|
|
|
- // this.isSubmitting = false; // .finally() 中已经处理
|
|
|
this.$showToast('网络异常,请稍后重试');
|
|
|
})
|
|
|
.finally(() => {
|
|
|
- this.isSubmitting = false; // 确保无论成功或失败,提交状态都会被重置
|
|
|
+ this.isSubmitting = false;
|
|
|
});
|
|
|
},
|
|
|
setQuestionnaireCache(){
|
|
|
const answeredList = this.list
|
|
|
- .filter(l => l.answer) // 过滤出已回答的
|
|
|
- .map(l => ({ id: l.id, answer: l.answer })); // 转换成需要的格式
|
|
|
+ .filter(l => l.answer)
|
|
|
+ .map(l => ({ id: l.id, answer: l.answer }));
|
|
|
|
|
|
if (answeredList.length === 0) {
|
|
|
uni.removeStorageSync('questionnaire');
|
|
@@ -167,13 +161,13 @@
|
|
|
uni.setStorageSync('questionnaire', JSON.stringify(qinfo));
|
|
|
}
|
|
|
},
|
|
|
- onUnload() {
|
|
|
- this.setQuestionnaireCache();
|
|
|
- },
|
|
|
- onBackPress() {
|
|
|
- this.setQuestionnaireCache();
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // onUnload() {
|
|
|
+ // this.setQuestionnaireCache();
|
|
|
+ // },
|
|
|
+ // onBackPress() {
|
|
|
+ // this.setQuestionnaireCache();
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
}
|
|
|
</script>
|
|
|
|