ali vor 2 Jahren
Ursprung
Commit
cc504a0bb1

+ 78 - 24
src/components/Widgets/Other/Shop/ShopCompleteInfo/components/AllQuestions.vue

@@ -6,7 +6,7 @@
              outline
              outline
              size="sm"
              size="sm"
              class="btn-next-question"
              class="btn-next-question"
-             @click="changeQuestion(questionPanel + 1)">
+             @click="nextQuestion">
         سوال بعدی
         سوال بعدی
         <q-icon name="arrow_back_ios" />
         <q-icon name="arrow_back_ios" />
       </q-btn>
       </q-btn>
@@ -15,7 +15,7 @@
              outline
              outline
              size="sm"
              size="sm"
              class="btn-prev-question"
              class="btn-prev-question"
-             @click="changeQuestion(questionPanel - 1)">
+             @click="prevQuestion">
         <q-icon name="arrow_forward_ios" />
         <q-icon name="arrow_forward_ios" />
         سوال قبلی
         سوال قبلی
       </q-btn>
       </q-btn>
@@ -98,6 +98,20 @@ export default {
     this.mounted = true
     this.mounted = true
   },
   },
   methods: {
   methods: {
+    nextQuestion () {
+      this.sendAnswer(this.questionPanel - 1)
+        .then(() => {
+          this.changeQuestion(this.questionPanel + 1)
+        })
+        .catch(() => {})
+    },
+    prevQuestion () {
+      this.sendAnswer(this.questionPanel - 1)
+        .then(() => {
+          this.changeQuestion(this.questionPanel - 1)
+        })
+        .catch(() => {})
+    },
     changeQuestion (newNumber) {
     changeQuestion (newNumber) {
       this.questionPanel = newNumber
       this.questionPanel = newNumber
     },
     },
@@ -116,28 +130,29 @@ export default {
             label: 'ثبت پاسخ',
             label: 'ثبت پاسخ',
             placeholder: ' ',
             placeholder: ' ',
             atClick: () => {
             atClick: () => {
-              const answerText = FormBuilderAssist.getInputsByName(this.questionInputs[answerSheetIndex], 'answer_text').value
-              if (!answerText && !hasChoise) {
-                this.$q.notify({
-                  type: 'negative',
-                  message: 'لطفا متن پاسخ را کامل کنید.'
-                })
-                return
-              }
-              const entityCreate = this.$refs['entityCreate_' + answerSheetIndex.toString()][0]
-              entityCreate.entityLoading = true
-              entityCreate.createEntity(false)
-                .then(() => {
-                  if (this.questionPanel < this.answerBook.answer_sheet_info.list.length) {
-                    this.changeQuestion(this.questionPanel + 1)
-                  } else if (this.questionPanel === this.answerBook.answer_sheet_info.list.length) {
-                    this.confirmAnswers()
-                  }
-                  entityCreate.entityLoading = false
-                })
-                .catch(() => {
-                  entityCreate.entityLoading = false
-                })
+              this.sendAnswer(answerSheetIndex)
+              // const answerText = FormBuilderAssist.getInputsByName(this.questionInputs[answerSheetIndex], 'answer_text').value
+              // if (!answerText && !hasChoise) {
+              //   this.$q.notify({
+              //     type: 'negative',
+              //     message: 'لطفا متن پاسخ را کامل کنید.'
+              //   })
+              //   return
+              // }
+              // const entityCreate = this.$refs['entityCreate_' + answerSheetIndex.toString()][0]
+              // entityCreate.entityLoading = true
+              // entityCreate.createEntity(false)
+              //   .then(() => {
+              //     if (this.questionPanel < this.answerBook.answer_sheet_info.list.length) {
+              //       this.changeQuestion(this.questionPanel + 1)
+              //     } else if (this.questionPanel === this.answerBook.answer_sheet_info.list.length) {
+              //       this.confirmAnswers()
+              //     }
+              //     entityCreate.entityLoading = false
+              //   })
+              //   .catch(() => {
+              //     entityCreate.entityLoading = false
+              //   })
             },
             },
             col: 'col-12 flex justify-end'
             col: 'col-12 flex justify-end'
           }
           }
@@ -165,6 +180,45 @@ export default {
         this.questionInputs.push(inputs)
         this.questionInputs.push(inputs)
       })
       })
     },
     },
+    sendAnswer (answerSheetIndex) {
+      return new Promise((resolve, reject) => {
+        const answerSheetItem = this.answerBook.answer_sheet_info.list[answerSheetIndex]
+        const hasChoise = Array.isArray(answerSheetItem.test_question_info.question_info.choices) && answerSheetItem.test_question_info.question_info.choices.length > 0
+        const answerText = FormBuilderAssist.getInputsByName(this.questionInputs[answerSheetIndex], 'answer_text').value
+        if (!answerText && !hasChoise) {
+          this.$q.notify({
+            type: 'negative',
+            message: 'لطفا متن پاسخ را کامل کنید.'
+          })
+          reject()
+          return
+        }
+        if (hasChoise && isNaN(answerSheetItem.answer_choice_index)) {
+          this.$q.notify({
+            type: 'negative',
+            message: 'لطفا یک گزینه را انتخاب.'
+          })
+          reject()
+          return
+        }
+        const entityCreate = this.$refs['entityCreate_' + answerSheetIndex.toString()][0]
+        entityCreate.entityLoading = true
+        entityCreate.createEntity(false)
+          .then(() => {
+            if (this.questionPanel < this.answerBook.answer_sheet_info.list.length) {
+              // this.changeQuestion(this.questionPanel + 1)
+            } else if (this.questionPanel === this.answerBook.answer_sheet_info.list.length) {
+              this.confirmAnswers()
+            }
+            entityCreate.entityLoading = false
+            resolve()
+          })
+          .catch(() => {
+            entityCreate.entityLoading = false
+            reject()
+          })
+      })
+    },
     confirmAnswers () {
     confirmAnswers () {
       this.$bus.emit('event-confirmation-step-test-sent-answer-sending')
       this.$bus.emit('event-confirmation-step-test-sent-answer-sending')
       APIGateway.answerBook.confirmAnswers(this.answerBook.id)
       APIGateway.answerBook.confirmAnswers(this.answerBook.id)