InvoiceShow.vue 7.3 KB

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