瀏覽代碼

see also #208

ali 3 年之前
父節點
當前提交
e43e793767

+ 28 - 0
src/api/models/Event.js

@@ -2,6 +2,7 @@ import { appApi } from 'src/boot/axios.js'
 import { Invoice } from 'src/models/Invoice.js'
 import APIRepository from '../classes/APIRepository.js'
 import { Event, EventList } from 'src/models/Event.js'
+import { EventRegistration } from 'src/models/EventRegistration'
 
 export default class EventAPI extends APIRepository {
   constructor() {
@@ -11,6 +12,7 @@ export default class EventAPI extends APIRepository {
       byId: (id) => '/ema/events/' + id,
       enroll: (id) => '/ema/events/' + id + '/enroll',
       drop: (id) => '/ema/events/' + id + '/drop',
+      register: (id) => '/ema/events/' + id + '/register',
       members: '/ema/registrations',
       activitySheet: '/ema/registrations/activity_sheet',
       enrollByAdmin: (classroomId, userId) => '/ema/events/' + classroomId + '/enrolll?user_id=' + userId,
@@ -114,6 +116,32 @@ export default class EventAPI extends APIRepository {
     })
   }
 
+  register (id) {
+    return this.sendRequest({
+      apiMethod: 'put',
+      api: this.api,
+      request: this.APIAdresses.register(id),
+      resolveCallback: (response) => {
+        const data = {
+          type: null,
+          model: response.data
+        }
+        if (response.data.status === 'PAYING') {
+          data.type = 'Invoice'
+          data.model = new Invoice(response.data)
+        } else if (response.data.status === 'REGISTERED') {
+          data.type = 'EventRegistration'
+          data.model = new EventRegistration(response.data)
+        }
+
+        return data
+      },
+      rejectCallback: (error) => {
+        return error
+      }
+    })
+  }
+
   createInvoice (id) {
     return this.sendRequest({
       apiMethod: 'put',

+ 2 - 2
src/components/Widgets/Event/ShowEventInfo/ShowEventInfo.vue

@@ -340,8 +340,8 @@ export default {
       return ShamsiDate.getTitledDateTime(dateTime)
     },
     acceptAndContinue () {
-      this.$store.commit('Shop/updateOnRegisterEvent', this.event)
-      this.$router.push({ name: 'UserPanel.ShopCompleteInfo', query: { type: this.acceptClassType } })
+      this.$store.commit('Shop/updateOnRegisterClassroom', this.event)
+      this.$router.push({ name: 'UserPanel.ShopCompleteInfo', query: { type: this.acceptClassType, source: 'event' } })
     },
     onEnrolment () {
       this.acceptClassType = 'enrollment'

+ 48 - 13
src/components/Widgets/Other/Shop/ShopCompleteInfo/ShopCompleteInfo.vue

@@ -232,17 +232,59 @@ export default {
       this.$refs.entityEdit.editEntity(false)
         .then(() => {
           if (this.$route.query.type === 'register') {
-            this.createInvoice()
-              .then(() => {
-                this.$router.push({ name: 'UserPanel.ShopPaymentFromWallet', query: this.$route.query })
-              })
-              .catch(() => {})
+            this.createInvoiceForClassroomOrRegisterEvent()
           } else {
             this.$router.push({ name: 'UserPanel.ShopPaymentFromWallet', query: this.$route.query })
           }
         })
         .catch(() => {})
     },
+    createInvoiceForClassroomOrRegisterEvent () {
+      if (this.$route.query.source === 'event') {
+        this.registerEvent()
+          .then((data) => {
+            if (data === 'Invoice') {
+              this.$router.push({ name: 'UserPanel.ShopPaymentFromWallet', query: this.$route.query })
+            }
+          })
+          .catch(() => {})
+      } else {
+        this.createInvoice()
+          .then(() => {
+            this.$router.push({ name: 'UserPanel.ShopPaymentFromWallet', query: this.$route.query })
+          })
+          .catch(() => {})
+      }
+    },
+    registerEvent () {
+      return new Promise((resolve, reject) => {
+        this.invoice.loading = true
+        APIGateway.event.register(this.classroom.id)
+          .then((data) => {
+            if (data.type === 'Invoice') {
+              this.invoice = new Invoice(data.model)
+              this.invoice.loading = false
+              this.$store.commit('Shop/updateRegisterClassroomInvoice', this.invoice)
+              this.$q.notify({
+                message: 'صورت حساب شما ایجاد شد',
+                type: 'positive'
+              })
+              resolve('Invoice')
+            } else if (data.type === 'EventRegistration') {
+              this.$q.notify({
+                message: 'ثبت نام شما با موفقیت انجام شد.',
+                type: 'positive'
+              })
+              const eventRegistrationId = data.model.id
+              this.$router.push({ name: 'UserPanel.Profile.EventInfo', params: { id: eventRegistrationId } })
+            }
+          })
+          .catch(() => {
+            this.invoice.loading = false
+            reject()
+          })
+      })
+    },
     createInvoice () {
       return new Promise((resolve, reject) => {
         this.invoice.loading = true
@@ -275,14 +317,7 @@ export default {
       this.rulesDialog = true
     },
     getHoldingType (type) {
-      const target = Enums.classroomHoldingTypes.find(item => item.value === type)
-      if (target) {
-        return target.label
-      }
-      return '-'
-    },
-    getAudienceGenderType (type) {
-      const target = Enums.genders.find(item => item.value === type)
+      const target = (new Classroom()).holding_typeEnums.find(item => item.value === type)
       if (target) {
         return target.label
       }