|
@@ -341,6 +341,24 @@ export class InterestSearchComponent implements OnInit {
|
|
|
|
|
|
|
|
|
async submit() {
|
|
|
+
|
|
|
+ const { completed, firstIncompleteIndex } = this.checkQuestionsCompleted();
|
|
|
+
|
|
|
+ if (!completed) {
|
|
|
+
|
|
|
+ const toast = document.createElement('ion-toast');
|
|
|
+ toast.message = '请完成所有问题';
|
|
|
+ toast.duration = 2000;
|
|
|
+ toast.position = 'top';
|
|
|
+ toast.color = 'warning';
|
|
|
+ document.body.appendChild(toast);
|
|
|
+ await toast.present();
|
|
|
+
|
|
|
+
|
|
|
+ this.scrollToQuestion(firstIncompleteIndex);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
if (!this.questionnaire) {
|
|
|
console.error("未加载问卷数据。");
|
|
@@ -354,7 +372,7 @@ export class InterestSearchComponent implements OnInit {
|
|
|
|
|
|
const answersArray: string[] = [];
|
|
|
|
|
|
-
|
|
|
+
|
|
|
for (const question of this.questionsWithOptions) {
|
|
|
const selectedOptionId = this.answers[question.QuestionId];
|
|
|
if (selectedOptionId) {
|
|
@@ -776,4 +794,29 @@ export class InterestSearchComponent implements OnInit {
|
|
|
await toast.present();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private checkQuestionsCompleted(): { completed: boolean, firstIncompleteIndex: number } {
|
|
|
+
|
|
|
+ for (let i = 0; i < this.questionsWithOptions.length; i++) {
|
|
|
+ const question = this.questionsWithOptions[i];
|
|
|
+ if (!this.answers[question.QuestionId]) {
|
|
|
+ return { completed: false, firstIncompleteIndex: i };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return { completed: true, firstIncompleteIndex: -1 };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private scrollToQuestion(index: number) {
|
|
|
+ setTimeout(() => {
|
|
|
+ const questionElements = document.querySelectorAll('.question-container');
|
|
|
+ if (questionElements[index]) {
|
|
|
+ questionElements[index].scrollIntoView({
|
|
|
+ behavior: 'smooth',
|
|
|
+ block: 'center'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, 100);
|
|
|
+ }
|
|
|
}
|