InvoiceShow.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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!=='PAID_FULL' && invoice.status!=='PAID_IN_INSTALMENT'"
  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">
  63. <div class="col-md-4 col-12">
  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">
  69. <q-img :src="invoice.item_info.thumbnail"
  70. width="100px" />
  71. <q-icon name="isax:user" />
  72. استاد:
  73. {{ invoice.item_info.professor_info.firstname }}
  74. {{ invoice.item_info.professor_info.lastname }}
  75. </div>
  76. <div class="col-md-4 col-12">
  77. <q-img :src="invoice.item_info.thumbnail"
  78. width="100px" />
  79. <q-icon name="isax:card" />
  80. قیمت:
  81. {{ invoice.item_info?.price ? invoice.item_info.price.toLocaleString('fa') : 0 }}
  82. تومان
  83. </div>
  84. </div>
  85. </q-card-section>
  86. </q-card>
  87. <div class="action q-mt-lg">
  88. <q-card v-if="!invoice.loading && invoice.status!=='PAYING' && invoice.status!=='PAID_FULL' && invoice.status!=='PAID_IN_INSTALMENT'"
  89. class="q-mb-md">
  90. <q-card-section>
  91. تنها در صورتی که وضعیت سفارش در حال پرداخت باشد امکان پرداخت با کیف پول وجود دارد
  92. </q-card-section>
  93. </q-card>
  94. <q-card v-if="!invoice.loading && invoice.status!=='PAID_FULL' && invoice.status!=='PAID_IN_INSTALMENT'">
  95. <q-card-section>
  96. پرداخت
  97. </q-card-section>
  98. <q-separator />
  99. <q-card-section>
  100. <invoice-payment-card :wallet="wallet"
  101. :invoice="invoice"
  102. class="payment-card"
  103. @onCancel="onCancel"
  104. @onAccept="onAccept" />
  105. </q-card-section>
  106. </q-card>
  107. </div>
  108. </div>
  109. </template>
  110. <script>
  111. import Assist from 'assets/js/Assist.js'
  112. import { User } from 'src/models/User.js'
  113. import { Wallet } from 'src/models/Wallet.js'
  114. import { Invoice } from 'src/models/Invoice.js'
  115. import { mixinWidget } from 'src/mixin/Mixins.js'
  116. import { APIGateway } from 'src/api/APIGateway.js'
  117. import InvoicePaymentCard from 'src/components/InvoicePaymentCard.vue'
  118. export default {
  119. name: 'InvoiceShow',
  120. components: { InvoicePaymentCard },
  121. mixins: [mixinWidget],
  122. props: {
  123. invoiceId: {
  124. type: Number,
  125. default: null
  126. }
  127. },
  128. data: () => {
  129. return {
  130. user: new User(),
  131. wallet: new Wallet(),
  132. invoice: new Invoice()
  133. }
  134. },
  135. mounted() {
  136. this.loadAuthData()
  137. this.getMyWallet()
  138. this.getInvoice()
  139. },
  140. methods: {
  141. loadAuthData() { // prevent Hydration node mismatch
  142. this.user = this.$store.getters['Auth/user']
  143. },
  144. getDateTime (dateTime) {
  145. return Assist.miladiToShamsi(dateTime)
  146. },
  147. onCancel () {
  148. this.$router.push({ name: 'UserPanel.Invoice.List' })
  149. },
  150. onAccept () {
  151. this.payInvoice()
  152. },
  153. getMyWallet () {
  154. this.wallet.loading = true
  155. APIGateway.wallet.getMyWallet(this.user.id)
  156. .then((wallet) => {
  157. this.wallet = new Wallet(wallet)
  158. this.wallet.loading = false
  159. this.walletLoaded = true
  160. })
  161. .catch(() => {
  162. this.wallet.loading = false
  163. })
  164. },
  165. amountOfDepositWalletNeeded () {
  166. return this.invoice.amount - this.wallet.inventory
  167. },
  168. payInvoice () {
  169. if (this.amountOfDepositWalletNeeded() > 0) {
  170. this.payInvoiceByDepositWallet()
  171. } else {
  172. this.payInvoiceByWallet()
  173. }
  174. },
  175. payInvoiceByWallet () {
  176. this.invoice.loading = true
  177. APIGateway.invoice.pay(this.invoice.id)
  178. .then((message) => {
  179. this.invoice.loading = false
  180. this.getInvoice()
  181. this.$q.notify({
  182. message,
  183. type: 'positive'
  184. })
  185. })
  186. .catch(() => {
  187. this.invoice.loading = false
  188. })
  189. },
  190. payInvoiceByDepositWallet () {
  191. this.invoice.loading = true
  192. APIGateway.wallet.deposit({
  193. amount: this.amountOfDepositWalletNeeded(),
  194. invoice: this.invoice.id
  195. })
  196. .then((url) => {
  197. window.location.href = url
  198. })
  199. .catch(() => {
  200. this.depositLoading = false
  201. })
  202. },
  203. getInvoice () {
  204. this.invoice.loading = true
  205. const invoiceId = this.$route.params.id
  206. APIGateway.invoice.get({ data: { id: invoiceId } })
  207. .then((invoice) => {
  208. this.invoice = new Invoice(invoice)
  209. this.invoice.loading = false
  210. })
  211. .catch(() => {
  212. this.invoice.loading = false
  213. })
  214. }
  215. }
  216. }
  217. </script>
  218. <style scoped lang="scss">
  219. .InvoiceShow {
  220. .title {
  221. font-style: normal;
  222. font-weight: 700;
  223. font-size: 24px;
  224. line-height: 140%;
  225. color: #424242;
  226. margin-bottom: 27px;
  227. display: flex;
  228. flex-flow: row;
  229. position: relative;
  230. .static-title {
  231. }
  232. .dynamic-title {
  233. }
  234. .back-action {
  235. position: absolute;
  236. right: 0;
  237. top: 0;
  238. }
  239. }
  240. .btn-need-installment {
  241. position: absolute;
  242. right: 18px;
  243. top: 8px;
  244. }
  245. }
  246. </style>