AdminInvoiceShow.vue 7.6 KB

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