InvoiceShow.vue 8.5 KB

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