瀏覽代碼

event test user side

ali 2 年之前
父節點
當前提交
1f2974646e

+ 12 - 19
src/components/Widgets/Other/Shop/ShopCompleteInfo/ShopCompleteInfo.vue

@@ -128,8 +128,9 @@
           پرسشنامه
         </q-banner>
         <show-event-test v-if="!eventTestAnswerBook.loading"
-                         :answer-book="eventTestAnswerBook"
-                         @sentsuccess="editEntity" />
+                         :answer-book-id="eventTestAnswerBook.id"
+                         @sentsuccess="editEntity"
+                         @sentfailed="sentTestFailed" />
         <div v-else>
           کمی صبر کنید...
         </div>
@@ -142,7 +143,6 @@
 
 <script>
 import { EntityEdit } from 'quasar-crud'
-import { Test } from 'src/models/Test.js'
 import Enums from 'src/assets/Enums/Enums.js'
 import { Invoice } from 'src/models/Invoice.js'
 import { mixinAuth } from 'src/mixin/Mixins.js'
@@ -166,7 +166,6 @@ export default {
     loading: true,
     classroom: new Classroom(),
     invoice: new Invoice(),
-    eventTest: new Test(),
     eventTestAnswerBook: new AnswerBook(),
 
     api: APIGateway.user.APIAdresses.current,
@@ -272,24 +271,14 @@ export default {
   },
   methods: {
     getEventTest () {
-      this.eventTest.loading = true
-      APIGateway.test.index({ event: this.classroom.id })
-        .then(({ list }) => {
-          this.eventTest = new Test(list.list[0])
-          this.eventTest.loading = false
-          this.getEventTestAnswerBook()
-        })
-        .catch(() => {
-          this.eventTest.loading = false
-        })
-    },
-    getEventTestAnswerBook () {
-      if (!this.eventTest.id) {
+      if (this.classroom.tests && this.classroom.tests.length === 0) {
         return
       }
-
+      this.getEventTestAnswerBook(this.classroom.tests[0])
+    },
+    getEventTestAnswerBook (eventTestId) {
       this.eventTestAnswerBook.loading = true
-      APIGateway.answerBook.getOrCreate({ owner: this.user.id, test: this.eventTest.id })
+      APIGateway.answerBook.getOrCreate(this.user.id, eventTestId)
         .then((answerBook) => {
           this.eventTestAnswerBook = new AnswerBook(answerBook)
           this.eventTestAnswerBook.loading = false
@@ -301,6 +290,10 @@ export default {
     loadClassroomFromStore () {
       this.classroom = this.$store.getters['Shop/onRegisterClassroom']
     },
+    sentTestFailed () {
+      debugger
+      this.panel = 'userInfo'
+    },
     editEntity () {
       if (this.eventTestAnswerBook.id && this.panel !== 'eventTest') {
         this.panel = 'eventTest'

+ 60 - 11
src/components/Widgets/Other/Shop/ShopCompleteInfo/components/AllQuestions.vue

@@ -5,21 +5,29 @@
       <q-item v-for="(answerSheet, answerSheetIndex) in answerBook.answer_sheet_info.list"
               :key="answerSheetIndex"
               clickable>
-        <q-item-section v-html="'<span>' + (answerSheetIndex + 1) + ' - </span>' + answerSheet.test_set_question_info.question_info.text" />
+        <q-item-section>
+          <q-item-label v-html="'<span>' + (answerSheetIndex + 1) + ' - </span>' + answerSheet.test_set_question_info.question_info.text" />
+          <q-item-label>
+            <entity-create v-if="mounted"
+                           :ref="'entityCreate_' + answerSheetIndex.toString()"
+                           v-model:value="questionInputs[answerSheetIndex]"
+                           :api="singleQuestionSendAnswerApi"
+                           :default-layout="false"
+                           :show-close-button="false"
+                           :show-edit-button="false"
+                           :show-expand-button="false"
+                           :show-save-button="false"
+                           :show-reload-button="false" />
+          </q-item-label>
+        </q-item-section>
       </q-item>
     </q-list>
     <q-separator class="q-my-lg" />
     <q-card-actions class="flex justify-end AllQuestionsForm">
-      <entity-create v-if="mounted"
-                     ref="entityCreate"
-                     v-model:value="inputs"
-                     :api="api"
-                     :default-layout="false"
-                     :show-close-button="false"
-                     :show-edit-button="false"
-                     :show-expand-button="false"
-                     :show-save-button="false"
-                     :show-reload-button="false" />
+      <q-btn color="primary"
+             @click="confirmAnswers">
+        ارسال پرسشنامه
+      </q-btn>
     </q-card-actions>
   </div>
 </template>
@@ -47,6 +55,8 @@ export default {
   data () {
     return {
       mounted: false,
+      questionInputs: [],
+      singleQuestionSendAnswerApi: APIGateway.answerSheet.APIAdresses.base,
       api: APIGateway.answerBook.APIAdresses.submitOverallAnswer(this.$route.params.answer_book_id),
       inputs: [
         // { type: 'inputEditor', name: 'answer_text', label: 'متن پاسخ', placeholder: ' ', col: 'col-12' },
@@ -65,6 +75,45 @@ export default {
       FormBuilderAssist.setAttributeByName(this.inputs, 'btn', 'atClick', this.sendAnswers)
       FormBuilderAssist.setAttributeByName(this.inputs, 'answer_text', 'value', this.answerBook.overall_answer_text)
       FormBuilderAssist.setAttributeByName(this.inputs, 'answer_attachment', 'value', this.answerBook.overall_answer_attachment)
+
+      this.answerBook.answer_sheet_info.list.forEach((answerSheetItem, answerSheetIndex) => {
+        this.questionInputs.push([
+          { type: 'input', name: 'answer_text', label: 'متن پاسخ', placeholder: ' ', inputType: 'textarea', col: 'col-12' },
+          { type: 'file', name: 'answer_attachment', label: 'فایل پیوست', placeholder: ' ', col: 'col-12' },
+          { type: 'hidden', name: 'answer_book', value: this.answerBook.id },
+          { type: 'hidden', name: 'test_set_question', value: answerSheetItem.test_set_question },
+          {
+            type: BtnControlComp,
+            name: 'btn',
+            responseKey: 'btn',
+            label: 'ثبت پاسخ',
+            placeholder: ' ',
+            atClick: () => {
+              const entityCreate = this.$refs['entityCreate_' + answerSheetIndex.toString()][0]
+              entityCreate.entityLoading = true
+              entityCreate.createEntity(false)
+                .then(() => {
+                  entityCreate.entityLoading = false
+                })
+                .catch(() => {
+                  entityCreate.entityLoading = false
+                })
+            },
+            col: 'col-12 flex justify-end'
+          }
+        ])
+      })
+    },
+    confirmAnswers () {
+      this.$emit('sending')
+      APIGateway.answerBook.confirmAnswers(this.answerBook.id)
+        .then(() => {
+          this.$emit('sentsuccess')
+        })
+        .catch(() => {
+          debugger
+          this.$emit('sentfailed')
+        })
     },
     sendAnswers () {
       const answerText = FormBuilderAssist.getInputsByName(this.inputs, 'answer_text').value

+ 10 - 9
src/components/Widgets/Other/Shop/ShopCompleteInfo/components/ShowEventTest.vue

@@ -1,6 +1,5 @@
 <template>
-  <div class="ShowEventTest"
-       :style="localOptions.style">
+  <div class="ShowEventTest">
     <q-card v-if="!localAnswerBook.loading && localAnswerBook.id">
       <q-card-section class="flex justify-between">
         <div>{{ localAnswerBook.test_info.title }}</div>
@@ -28,9 +27,9 @@ export default {
   name: 'ShowEventTest',
   components: { AllQuestions },
   props: {
-    answerBook: {
-      type: AnswerBook,
-      default: new AnswerBook()
+    answerBookId: {
+      type: Number,
+      default: null
     }
   },
   emits: ['sending', 'sentsuccess', 'sentfailed'],
@@ -38,6 +37,7 @@ export default {
     return {
       mounted: false,
       participateType: null,
+      localAnswerBook: new AnswerBook(),
       participateTypeDialog: false,
       storeAnswerBook: null,
       remainingTime: 0,
@@ -45,7 +45,6 @@ export default {
     }
   },
   mounted () {
-    this.localAnswerBook = this.answerBook
     this.getTestQuestions()
     this.mounted = true
   },
@@ -59,14 +58,16 @@ export default {
       this.localAnswerBook.loading = false
     },
     onAllQuestionsSentFailed () {
+      debugger
       this.$emit('sentfailed')
       this.localAnswerBook.loading = false
     },
     backToClassList () {
+      this.$emit('sentfailed')
     },
     getAnswerBook () {
       this.localAnswerBook.loading = true
-      APIGateway.answerBook.get(this.$route.params.answer_book_id)
+      APIGateway.answerBook.get(this.answerBookId)
         .then((answerBook) => {
           this.localAnswerBook = new AnswerBook(answerBook)
           if (this.localAnswerBook.test_info.test_set_questions_length === 0) {
@@ -83,13 +84,13 @@ export default {
           this.backToClassList()
         })
     },
-    initPageFromAnswerBook (answerBook, setRemainingTime = true) {
+    initPageFromAnswerBook (answerBook) {
       this.localAnswerBook = new AnswerBook(answerBook)
       this.localAnswerBook.loading = false
     },
     getTestQuestions () {
       this.localAnswerBook.loading = true
-      APIGateway.answerBook.getTestQuestions(this.$route.params.answer_book_id)
+      APIGateway.answerBook.getTestQuestions(this.answerBookId)
         .then((answerBook) => {
           this.initPageFromAnswerBook(answerBook)
         })

+ 4 - 0
src/models/Classroom.js

@@ -28,6 +28,10 @@ class Classroom extends Model {
         key: 'professor_info',
         relatedModel: User
       },
+      {
+        key: 'tests',
+        default: []
+      },
       { key: 'unit' },
       {
         key: 'unit_info',

+ 4 - 0
src/models/Event.js

@@ -28,6 +28,10 @@ class Event extends Model {
         key: 'professor_info',
         relatedModel: User
       },
+      {
+        key: 'tests',
+        default: []
+      },
       { key: 'unit' },
       {
         key: 'unit_info',