ali 3 vuotta sitten
vanhempi
commit
154cd5c8ce

+ 1 - 1
src/api/models/Invoice.js

@@ -4,7 +4,7 @@ import { Invoice, InvoiceList } from 'src/models/Invoice.js'
 
 export default class InvoiceAPI extends APIRepository {
   constructor() {
-    super('invoice', appApi)
+    super('invoice', appApi, '/accounting/invoices', Invoice)
     this.APIAdresses = {
       base: '/accounting/invoices',
       byId: (id) => '/accounting/invoices/' + id,

+ 16 - 10
src/components/Widgets/Invoice/InvoiceShow/InvoiceShow.vue

@@ -133,6 +133,8 @@ export default {
       wallet: new Wallet(),
       invoice: new Invoice(),
       defaultOptions: {
+        invoice: null,
+        invoiceId: null,
         canAction: true,
         showBackBtn: true,
         showNeedInstallmentBtn: true
@@ -227,16 +229,20 @@ export default {
       return this.localOptions.invoiceId || this.$route.params.id
     },
     getInvoice () {
-      this.invoice.loading = true
-      const invoiceId = this.getInvoiceId()
-      APIGateway.invoice.get({ data: { id: invoiceId } })
-        .then((invoice) => {
-          this.invoice = new Invoice(invoice)
-          this.invoice.loading = false
-        })
-        .catch(() => {
-          this.invoice.loading = false
-        })
+      if (this.localOptions.invoice) {
+        this.invoice = new Invoice(this.localOptions.invoice)
+      } else {
+        this.invoice.loading = true
+        const invoiceId = this.getInvoiceId()
+        APIGateway.invoice.get({ data: { id: invoiceId } })
+          .then((invoice) => {
+            this.invoice = new Invoice(invoice)
+            this.invoice.loading = false
+          })
+          .catch(() => {
+            this.invoice.loading = false
+          })
+      }
     }
   }
 }

+ 38 - 5
src/components/Widgets/Invoice/InvoiceThankyou/InvoiceThankyou.vue

@@ -19,23 +19,32 @@
         </q-card>
       </div>
     </div>
-    <div v-if="$route.query.invoice"
+    <div v-if="$route.query.invoice && !invoice.loading"
          class="row justify-center items-center">
       <div class="col-md-6 q-mt-lg">
-        <invoice-show :options="{invoiceId: $route.query.invoice}" />
+        <invoice-show :options="{invoiceId: $route.query.invoice, invoice: invoice}" />
       </div>
     </div>
-    <div class="flex justify-center">
-      <q-btn color="primary"
+    <div v-if="!invoice.loading"
+         class="flex justify-center">
+      <q-btn v-if="invoice.type === 'CLASSROOM'"
+             color="primary"
              :to="{name: 'UserPanel.Profile.AllClassrooms'}">
         مشاهده دوره های من
       </q-btn>
+      <q-btn v-if="invoice.type === 'EVENT'"
+             color="primary"
+             :to="{name: 'UserPanel.Profile.AllEvents'}">
+        مشاهده رویدادهای من
+      </q-btn>
     </div>
   </div>
 </template>
 
 <script>
+import { Invoice } from 'src/models/Invoice.js'
 import { mixinWidget } from 'src/mixin/Mixins.js'
+import { APIGateway } from 'src/api/APIGateway.js'
 import InvoiceShow from 'src/components/Widgets/Invoice/InvoiceShow/InvoiceShow.vue'
 
 export default {
@@ -43,6 +52,30 @@ export default {
   components: {
     InvoiceShow
   },
-  mixins: [mixinWidget]
+  mixins: [mixinWidget],
+  data () {
+    return {
+      invoice: new Invoice()
+    }
+  },
+  created() {
+    this.invoice.loading = true
+  },
+  mounted() {
+    this.getInvoice()
+  },
+  methods: {
+    getInvoice () {
+      this.invoice.loading = true
+      APIGateway.invoice.get({ data: { id: this.$route.query.invoice } })
+        .then(invoice => {
+          this.invoice = invoice
+          this.invoice.loading = false
+        })
+        .catch(() => {
+          this.invoice.loading = false
+        })
+    }
+  }
 }
 </script>