InvoiceShow.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <div class="InvoiceShow"
  3. :style="localOptions.style">
  4. <div class="title q-pb-lg">
  5. <div class="static-title" />
  6. <div class="dynamic-title" />
  7. <div class="back-action">
  8. <q-btn flat
  9. :to="{name: 'UserPanel.Invoice.List'}"
  10. color="grey">
  11. بازگشت
  12. >
  13. </q-btn>
  14. </div>
  15. </div>
  16. <q-card v-if="invoice.item_info"
  17. class="q-mt-lg">
  18. <q-linear-progress v-if="invoice.loading"
  19. indeterminate />
  20. <q-card-section>
  21. صورتحساب شناسه
  22. {{ invoice.id }}
  23. <q-btn v-if="!invoice.loading && invoice.status === 'PAYING'"
  24. outline
  25. color="primary"
  26. class="btn-need-installment"
  27. :to="{name: 'UserPanel.Invoice.Ticket.Create', query: {source_type: 'INVOICE', source_id: invoice.id}}">
  28. درخواست مساعدت
  29. </q-btn>
  30. </q-card-section>
  31. <q-separator />
  32. <q-card-section>
  33. <div class="row">
  34. <div class="col-md-3 col-12">
  35. <q-banner>
  36. <q-icon name="isax:stickynote" />
  37. {{ getDateTime(invoice.creation_time) }}
  38. </q-banner>
  39. </div>
  40. <div class="col-md-3 col-12">
  41. <q-banner>
  42. {{ (invoice.amount ? invoice.amount.toLocaleString('fa') : 0) }}
  43. تومان
  44. </q-banner>
  45. </div>
  46. <div class="col-md-3 col-12">
  47. <q-banner>
  48. شماره پیگیری
  49. {{ invoice.id }}
  50. </q-banner>
  51. </div>
  52. <div class="col-md-3 col-12">
  53. <q-banner>
  54. وضعیت:
  55. {{ invoice.status_info.label }}
  56. </q-banner>
  57. </div>
  58. </div>
  59. </q-card-section>
  60. <q-separator />
  61. <q-card-section>
  62. <div class="row q-col-gutter-lg">
  63. <div class="col-md-4 col-12 flex items-center justify-start">
  64. <q-img :src="invoice.item_info.thumbnail"
  65. width="100px" />
  66. {{ invoice.item_info.title }}
  67. </div>
  68. <div class="col-md-4 col-12 flex items-center justify-start">
  69. <q-icon name="isax:user" />
  70. استاد:
  71. {{ invoice.item_info.professor_info.firstname }}
  72. {{ invoice.item_info.professor_info.lastname }}
  73. </div>
  74. <div class="col-md-4 col-12 flex items-center justify-start">
  75. <q-icon name="isax:card" />
  76. قیمت:
  77. {{ invoice.item_info?.price ? invoice.item_info.price.toLocaleString('fa') : 0 }}
  78. تومان
  79. </div>
  80. </div>
  81. </q-card-section>
  82. </q-card>
  83. <div class="action q-mt-lg">
  84. <q-card v-if="!invoice.loading && invoice.status!=='PAYING' && invoice.status!=='PAID_FULL' && invoice.status!=='PAID_IN_INSTALMENT'"
  85. class="q-mb-md">
  86. <q-card-section>
  87. تنها در صورتی که وضعیت سفارش در حال پرداخت باشد امکان پرداخت با کیف پول وجود دارد
  88. </q-card-section>
  89. </q-card>
  90. <q-card v-if="!invoice.loading && (invoice.status==='PAYING' || invoice.status==='PAYING_IN_INSTALMENT')">
  91. <q-card-section>
  92. پرداخت
  93. </q-card-section>
  94. <q-separator />
  95. <q-card-section>
  96. <invoice-payment-card :wallet="wallet"
  97. :invoice="invoice"
  98. class="payment-card"
  99. @onCancel="onCancel"
  100. @onAccept="onAccept" />
  101. </q-card-section>
  102. </q-card>
  103. </div>
  104. </div>
  105. </template>
  106. <script>
  107. import Assist from 'assets/js/Assist.js'
  108. import { User } from 'src/models/User.js'
  109. import { Wallet } from 'src/models/Wallet.js'
  110. import { Invoice } from 'src/models/Invoice.js'
  111. import { mixinWidget } from 'src/mixin/Mixins.js'
  112. import { APIGateway } from 'src/api/APIGateway.js'
  113. import InvoicePaymentCard from 'src/components/InvoicePaymentCard.vue'
  114. export default {
  115. name: 'InvoiceShow',
  116. components: { InvoicePaymentCard },
  117. mixins: [mixinWidget],
  118. props: {
  119. invoiceId: {
  120. type: Number,
  121. default: null
  122. }
  123. },
  124. data: () => {
  125. return {
  126. user: new User(),
  127. wallet: new Wallet(),
  128. invoice: new Invoice()
  129. }
  130. },
  131. mounted() {
  132. this.loadAuthData()
  133. this.getMyWallet()
  134. this.getInvoice()
  135. },
  136. methods: {
  137. loadAuthData() { // prevent Hydration node mismatch
  138. this.user = this.$store.getters['Auth/user']
  139. },
  140. getDateTime (dateTime) {
  141. return Assist.miladiToShamsi(dateTime)
  142. },
  143. onCancel () {
  144. this.$router.push({ name: 'UserPanel.Invoice.List' })
  145. },
  146. onAccept () {
  147. this.payInvoice()
  148. },
  149. getMyWallet () {
  150. this.wallet.loading = true
  151. APIGateway.wallet.getMyWallet(this.user.id)
  152. .then((wallet) => {
  153. this.wallet = new Wallet(wallet)
  154. this.wallet.loading = false
  155. this.walletLoaded = true
  156. })
  157. .catch(() => {
  158. this.wallet.loading = false
  159. })
  160. },
  161. amountOfDepositWalletNeeded () {
  162. return this.invoice.amount - this.wallet.inventory
  163. },
  164. payInvoice () {
  165. if (this.amountOfDepositWalletNeeded() > 0) {
  166. this.payInvoiceByDepositWallet()
  167. } else {
  168. this.payInvoiceByWallet()
  169. }
  170. },
  171. payInvoiceByWallet () {
  172. this.invoice.loading = true
  173. APIGateway.invoice.pay(this.invoice.id)
  174. .then((message) => {
  175. this.invoice.loading = false
  176. this.getInvoice()
  177. this.$q.notify({
  178. message,
  179. type: 'positive'
  180. })
  181. })
  182. .catch(() => {
  183. this.invoice.loading = false
  184. })
  185. },
  186. payInvoiceByDepositWallet () {
  187. this.invoice.loading = true
  188. APIGateway.wallet.deposit({
  189. amount: this.amountOfDepositWalletNeeded(),
  190. invoice: this.invoice.id
  191. })
  192. .then((url) => {
  193. window.location.href = url
  194. })
  195. .catch(() => {
  196. this.depositLoading = false
  197. })
  198. },
  199. getInvoice () {
  200. this.invoice.loading = true
  201. const invoiceId = this.$route.params.id
  202. APIGateway.invoice.get({ data: { id: invoiceId } })
  203. .then((invoice) => {
  204. this.invoice = new Invoice(invoice)
  205. this.invoice.loading = false
  206. })
  207. .catch(() => {
  208. this.invoice.loading = false
  209. })
  210. }
  211. }
  212. }
  213. </script>
  214. <style scoped lang="scss">
  215. .InvoiceShow {
  216. .title {
  217. font-style: normal;
  218. font-weight: 700;
  219. font-size: 24px;
  220. line-height: 140%;
  221. color: #424242;
  222. margin-bottom: 27px;
  223. display: flex;
  224. flex-flow: row;
  225. position: relative;
  226. .static-title {
  227. }
  228. .dynamic-title {
  229. }
  230. .back-action {
  231. position: absolute;
  232. right: 0;
  233. top: 0;
  234. }
  235. }
  236. .btn-need-installment {
  237. position: absolute;
  238. right: 18px;
  239. top: 8px;
  240. }
  241. }
  242. </style>