ShopPaymentFromWallet.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <template>
  2. <div class="complete-info">
  3. <q-banner class="banner complete-info-top-banner">
  4. {{ mainTitle }}
  5. </q-banner>
  6. <q-card class="complete-info-steps-card">
  7. <div class="complete-info-step">
  8. <svg xmlns="http://www.w3.org/2000/svg"
  9. width="17.053"
  10. height="19.866"
  11. viewBox="0 0 17.053 19.866">
  12. <g id="Paper"
  13. transform="translate(0 0)">
  14. <path id="Combined_Shape"
  15. data-name="Combined Shape"
  16. d="M4.475,19.866A4.585,4.585,0,0,1,0,15.188V4.491A4.606,4.606,0,0,1,4.57.012h6.271a.758.758,0,0,1,.265,0h.131a.755.755,0,0,1,.541.23l5.065,5.277a.753.753,0,0,1,.209.519V15.2A4.615,4.615,0,0,1,12.6,19.865H4.475ZM1.5,4.509V15.2a3.091,3.091,0,0,0,3.009,3.162h8.064a3.109,3.109,0,0,0,2.979-3.155V6.984h-2.01a3.332,3.332,0,0,1-3.318-3.325V1.512H4.572A3.089,3.089,0,0,0,1.5,4.509Zm10.224-.85a1.828,1.828,0,0,0,1.82,1.824H14.73L11.724,2.353ZM5.387,14.108a.75.75,0,0,1,0-1.5h5.4a.75.75,0,0,1,0,1.5Zm0-3.752a.75.75,0,0,1,0-1.5H8.743a.75.75,0,0,1,0,1.5Z"
  17. transform="translate(0.001 0)"
  18. fill="#5b7a5f" />
  19. </g>
  20. </svg>
  21. <span class="title">
  22. {{ step1Title }}
  23. <svg xmlns="http://www.w3.org/2000/svg"
  24. width="15"
  25. height="15"
  26. viewBox="0 0 15 15">
  27. <g id="Group_11510"
  28. data-name="Group 11510"
  29. transform="translate(-1215 -335)">
  30. <circle id="Ellipse_819"
  31. data-name="Ellipse 819"
  32. cx="7.5"
  33. cy="7.5"
  34. r="7.5"
  35. transform="translate(1215 335)"
  36. fill="#19cb99" />
  37. <path id="Path"
  38. d="M8.615,1.5l-4.75,4.75a.881.881,0,0,1-1.23,0L.255,3.875A.877.877,0,0,1,1.5,2.635l1.75,1.75L7.375.255A.877.877,0,0,1,8.615,1.5"
  39. transform="translate(1218 339)"
  40. fill="#f6f6f6" />
  41. </g>
  42. </svg>
  43. </span>
  44. </div>
  45. <div class="complete-info-step">
  46. <svg xmlns="http://www.w3.org/2000/svg"
  47. width="15.84"
  48. height="19.87"
  49. viewBox="0 0 15.84 19.87">
  50. <g id="Profile"
  51. transform="translate(0 0)">
  52. <path id="Combined_Shape"
  53. data-name="Combined Shape"
  54. d="M0,16.174c0-3.3,4.521-3.677,7.921-3.677,1.958,0,7.919,0,7.919,3.7,0,3.295-4.52,3.677-7.919,3.677C5.962,19.87,0,19.87,0,16.174Zm1.5,0c0,1.458,2.16,2.2,6.421,2.2s6.419-.733,6.419-2.177S12.18,14,7.921,14,1.5,14.729,1.5,16.174Zm6.389-5.555A5.31,5.31,0,0,1,7.921,0a5.31,5.31,0,0,1,0,10.619ZM4.038,5.31A3.873,3.873,0,0,0,7.892,9.192l.029.715V9.192A3.882,3.882,0,1,0,4.038,5.31Z"
  55. transform="translate(0 0)"
  56. fill="#212121" />
  57. </g>
  58. </svg>
  59. <span class="title">
  60. تکمیل اطلاعات
  61. <svg xmlns="http://www.w3.org/2000/svg"
  62. width="15"
  63. height="15"
  64. viewBox="0 0 15 15">
  65. <g id="Group_11510"
  66. data-name="Group 11510"
  67. transform="translate(-1215 -335)">
  68. <circle id="Ellipse_819"
  69. data-name="Ellipse 819"
  70. cx="7.5"
  71. cy="7.5"
  72. r="7.5"
  73. transform="translate(1215 335)"
  74. fill="#19cb99" />
  75. <path id="Path"
  76. d="M8.615,1.5l-4.75,4.75a.881.881,0,0,1-1.23,0L.255,3.875A.877.877,0,0,1,1.5,2.635l1.75,1.75L7.375.255A.877.877,0,0,1,8.615,1.5"
  77. transform="translate(1218 339)"
  78. fill="#f6f6f6" />
  79. </g>
  80. </svg>
  81. </span>
  82. </div>
  83. <div class="complete-info-step">
  84. <svg xmlns="http://www.w3.org/2000/svg"
  85. width="20.639"
  86. height="19.173"
  87. viewBox="0 0 20.639 19.173">
  88. <g id="Wallet"
  89. transform="translate(0)">
  90. <path id="Combined_Shape"
  91. data-name="Combined Shape"
  92. d="M6,19.173a6,6,0,0,1-6-6V6A6,6,0,0,1,6,0h8.645a6,6,0,0,1,6,6v7.178a6,6,0,0,1-6,6ZM1.5,6v7.178a4.5,4.5,0,0,0,4.5,4.5h8.645a4.5,4.5,0,0,0,4.5-4.5V12.9h-3.3a3.441,3.441,0,1,1,0-6.881h3.3V6a4.5,4.5,0,0,0-4.5-4.5H6A4.5,4.5,0,0,0,1.5,6ZM13.9,9.455a1.945,1.945,0,0,0,1.942,1.94h3.3V7.513h-3.3A1.946,1.946,0,0,0,13.9,9.455Zm2.088.688a.75.75,0,0,1,0-1.5H16.3a.75.75,0,0,1,0,1.5ZM5.286,6.038a.75.75,0,0,1,0-1.5h5.4a.75.75,0,1,1,0,1.5Z"
  93. transform="translate(0 0)"
  94. fill="#212121" />
  95. </g>
  96. </svg>
  97. <span class="title">
  98. پرداخت
  99. </span>
  100. </div>
  101. </q-card>
  102. <div v-if="isRegisterPage"
  103. class="info-column">
  104. <q-skeleton v-if="invoice.loading"
  105. height="200px"
  106. width="100%"
  107. square />
  108. <invoice-info v-if="!invoice.loading"
  109. :invoice="invoice"
  110. :classroom="classroom"
  111. class="invoice-info" />
  112. <invoice-payment-card v-if="!invoice.loading"
  113. :wallet="wallet"
  114. :invoice="invoice"
  115. class="payment-card"
  116. @onCancel="onCancel"
  117. @onAccept="onAccept" />
  118. </div>
  119. <div v-if="isEnrollmentPage"
  120. class="text-center">
  121. <q-btn color="primary"
  122. :loading="enrolmentLoading"
  123. @click="enrollClassroom">
  124. تایید و پیش ثبت نام
  125. </q-btn>
  126. </div>
  127. <template v-if="false">
  128. <q-banner class="banner complete-info-pay-banner">
  129. پرداخت
  130. </q-banner>
  131. <q-card class="complete-info-pay-form-card">
  132. <q-card-section>
  133. <div class="complete-info-pay-form-card-title">
  134. مبلغ قابل پرداخت:
  135. </div>
  136. <q-card>
  137. <q-card-section v-if="classroom"
  138. class="product-item">
  139. <div class="product-item-title">
  140. <div class="product-item-icon">
  141. <svg xmlns="http://www.w3.org/2000/svg"
  142. width="23.771"
  143. height="16.991"
  144. viewBox="0 0 23.771 16.991">
  145. <path id="import_contacts_FILL0_wght400_GRAD0_opsz48"
  146. d="M7.618,21.506a11.7,11.7,0,0,1,2.823.338,12.529,12.529,0,0,1,2.688,1.013V11.322A10.276,10.276,0,0,0,10.5,10.066a9.542,9.542,0,0,0-2.877-.446,7.957,7.957,0,0,0-2.012.257,19.465,19.465,0,0,0-1.985.635h0V22.235h0a7.623,7.623,0,0,1,1.9-.554A12.88,12.88,0,0,1,7.618,21.506Zm7.131,1.351A13.593,13.593,0,0,1,17.4,21.844a10.9,10.9,0,0,1,2.755-.338,14.467,14.467,0,0,1,2.12.162,10.571,10.571,0,0,1,1.877.432h0V10.512h0A8.027,8.027,0,0,0,22.2,9.837a9.94,9.94,0,0,0-2.053-.216,9.031,9.031,0,0,0-2.823.446,10.525,10.525,0,0,0-2.58,1.256Zm-.81,2.134a1.745,1.745,0,0,1-.392-.041.766.766,0,0,1-.311-.149,11.392,11.392,0,0,0-2.7-1.216,10.041,10.041,0,0,0-2.917-.432,7.778,7.778,0,0,0-1.945.243,19.068,19.068,0,0,0-1.891.594,1.157,1.157,0,0,1-1.2-.081A1.214,1.214,0,0,1,2,22.83V10.323a1.494,1.494,0,0,1,.189-.743,1.29,1.29,0,0,1,.567-.527,10.442,10.442,0,0,1,2.364-.8A12.192,12.192,0,0,1,7.618,8a11.986,11.986,0,0,1,3.309.459,10.558,10.558,0,0,1,3.012,1.4,10.255,10.255,0,0,1,2.958-1.4A11.6,11.6,0,0,1,20.152,8a12,12,0,0,1,2.485.257,10.487,10.487,0,0,1,2.35.8,1.376,1.376,0,0,1,.581.527,1.417,1.417,0,0,1,.2.743V22.83a1.28,1.28,0,0,1-.608,1.148,1.035,1.035,0,0,1-1.2.014,12.862,12.862,0,0,0-1.864-.608,8.211,8.211,0,0,0-1.945-.23,9.683,9.683,0,0,0-2.863.432A11.018,11.018,0,0,0,14.642,24.8a.766.766,0,0,1-.311.149A1.745,1.745,0,0,1,13.939,24.991ZM8.375,16.4Z"
  147. transform="translate(-2 -8)"
  148. fill="#475f4a" />
  149. </svg>
  150. </div>
  151. {{ classroom.title }}
  152. {{ classroom.unit_info.title }}
  153. ویژه
  154. {{ getAudienceGenderType(classroom.audience_gender_type) }}
  155. به صورت
  156. {{ getHoldingType(classroom.holding_type) }}
  157. {{ getTerm(classroom) }}
  158. </div>
  159. <div class="product-item-price">
  160. <svg xmlns="http://www.w3.org/2000/svg"
  161. width="22"
  162. height="16"
  163. viewBox="0 0 22 16">
  164. <g id="Group_11468"
  165. data-name="Group 11468"
  166. transform="translate(240 -290) rotate(90)">
  167. <g id="Rectangle_2935"
  168. data-name="Rectangle 2935"
  169. transform="translate(290 218)"
  170. fill="none"
  171. stroke="#aaa095"
  172. stroke-width="1.5">
  173. <rect width="16"
  174. height="22"
  175. rx="5"
  176. stroke="none" />
  177. <rect x="0.75"
  178. y="0.75"
  179. width="14.5"
  180. height="20.5"
  181. rx="4.25"
  182. fill="none" />
  183. </g>
  184. <line id="Line_737"
  185. data-name="Line 737"
  186. y1="2"
  187. transform="translate(294 233.5)"
  188. fill="none"
  189. stroke="#aaa095"
  190. stroke-linecap="round"
  191. stroke-width="2" />
  192. <line id="Line_738"
  193. data-name="Line 738"
  194. y1="2"
  195. transform="translate(302 222.5)"
  196. fill="none"
  197. stroke="#aaa095"
  198. stroke-linecap="round"
  199. stroke-width="2" />
  200. <g id="Ellipse_892"
  201. data-name="Ellipse 892"
  202. transform="translate(295 226)"
  203. fill="#fff"
  204. stroke="#aaa095"
  205. stroke-width="1.5">
  206. <circle cx="3"
  207. cy="3"
  208. r="3"
  209. stroke="none" />
  210. <circle cx="3"
  211. cy="3"
  212. r="2.25"
  213. fill="none" />
  214. </g>
  215. </g>
  216. </svg>
  217. {{ classroom.price }}
  218. ریال
  219. </div>
  220. </q-card-section>
  221. </q-card>
  222. </q-card-section>
  223. </q-card>
  224. <div class="flex justify-end section-edit-btn">
  225. <q-btn color="primary"
  226. @click="register">
  227. تایید و ادامه
  228. <svg xmlns="http://www.w3.org/2000/svg"
  229. width="18.387"
  230. height="11.502"
  231. viewBox="0 0 18.387 11.502">
  232. <path id="Combined_Shape"
  233. data-name="Combined Shape"
  234. d="M-9.338,11.408a.748.748,0,0,0,.388-.656V6.5h8.2A.751.751,0,0,0,0,5.75.75.75,0,0,0-.75,5h-8.2V.75A.751.751,0,0,0-9.338.093.769.769,0,0,0-9.7,0a.735.735,0,0,0-.4.115l-7.938,5a.747.747,0,0,0-.35.635.742.742,0,0,0,.35.634l7.938,5a.751.751,0,0,0,.4.116A.746.746,0,0,0-9.338,11.408ZM-10.45,9.392l-5.78-3.641,5.78-3.642Z"
  235. transform="translate(18.387)"
  236. fill="#fff" />
  237. </svg>
  238. </q-btn>
  239. </div>
  240. </template>
  241. </div>
  242. </template>
  243. <script>
  244. import { User } from 'src/models/User.js'
  245. import Enums from 'src/assets/Enums/Enums.js'
  246. import { Wallet } from 'src/models/Wallet.js'
  247. import { Invoice } from 'src/models/Invoice.js'
  248. // import API_ADDRESS from 'src/api/Addresses.js'
  249. import ShamsiDate from 'src/assets/ShamsiDate.js'
  250. import { APIGateway } from 'src/api/APIGateway.js'
  251. import { Classroom } from 'src/models/Classroom.js'
  252. import InvoiceInfo from './components/InvoiceInfo.vue'
  253. import InvoicePaymentCard from 'src/components/InvoicePaymentCard/InvoicePaymentCard.vue'
  254. export default {
  255. name: 'PaymentFromWallet',
  256. components: { InvoiceInfo, InvoicePaymentCard },
  257. data: () => ({
  258. step: false,
  259. enrolmentLoading: false,
  260. user: new User(),
  261. wallet: new Wallet(),
  262. invoice: new Invoice(),
  263. classroom: new Classroom(),
  264. rulesAccept: false,
  265. rulesDialog: false,
  266. loading: true
  267. }),
  268. computed: {
  269. mainTitle () {
  270. if (this.$route.query.source === 'event') {
  271. return 'ثبت نام در رویداد'
  272. } else {
  273. return 'ثبت نام در دوره آموزشی'
  274. }
  275. },
  276. step1Title () {
  277. if (this.$route.query.source === 'event') {
  278. return 'مشاهده جزییات و قوانین رویداد'
  279. } else {
  280. return 'مشاهده جزییات و قوانین دوره'
  281. }
  282. },
  283. isRegisterPage () {
  284. return this.$route.query.type === 'register'
  285. },
  286. isEnrollmentPage () {
  287. return this.$route.query.type === 'enrollment'
  288. }
  289. },
  290. mounted () {
  291. this.loadAuthData()
  292. this.loadClassroomFromStore()
  293. this.checkStoreClassroom()
  294. this.getInvoiceFromStore()
  295. this.getMyWallet()
  296. },
  297. methods: {
  298. enrollClassroom () {
  299. this.enrolmentLoading = true
  300. APIGateway.classroom.enrollByUser(this.classroom.id)
  301. .then(() => {
  302. this.enrolmentLoading = false
  303. this.$route.push({ name: 'UserPanel.Profile.ClassroomInfo', params: { id: this.classroom.id } })
  304. })
  305. .catch(() => {
  306. this.enrolmentLoading = false
  307. })
  308. },
  309. onCancel () {
  310. this.invoice.loading = true
  311. APIGateway.invoice.cancel(this.invoice.id)
  312. .then(() => {
  313. this.invoice.loading = false
  314. this.$router.push({ name: 'Public.AllClassrooms' })
  315. })
  316. .catch(() => {
  317. this.invoice.loading = false
  318. })
  319. },
  320. onAccept () {
  321. this.payInvoice()
  322. },
  323. amountOfDepositWalletNeeded () {
  324. return this.invoice.amount - this.wallet.inventory
  325. },
  326. payInvoice () {
  327. if (this.amountOfDepositWalletNeeded() > 0) {
  328. this.payInvoiceByDepositWallet()
  329. } else {
  330. this.payInvoiceByWallet()
  331. }
  332. },
  333. payInvoiceByWallet () {
  334. this.invoice.loading = true
  335. APIGateway.invoice.pay(this.invoice.id)
  336. .then((message) => {
  337. this.payMessage = message
  338. this.invoice.loading = false
  339. if (this.$route.query.source === 'event') {
  340. this.$router.push({ name: 'UserPanel.Profile.EventInfo', params: { id: this.classroom.id } })
  341. } else {
  342. this.$router.push({ name: 'UserPanel.Profile.ClassroomInfo', params: { id: this.classroom.id } })
  343. }
  344. })
  345. .catch(() => {
  346. this.invoice.loading = false
  347. })
  348. },
  349. payInvoiceByDepositWallet () {
  350. this.invoice.loading = true
  351. APIGateway.wallet.deposit({
  352. amount: this.amountOfDepositWalletNeeded(),
  353. invoice: this.invoice.id
  354. })
  355. .then((url) => {
  356. window.location.href = url
  357. })
  358. .catch(() => {
  359. this.depositLoading = false
  360. })
  361. },
  362. loadAuthData() { // prevent Hydration node mismatch
  363. this.user = this.$store.getters['Auth/user']
  364. },
  365. getMyWallet () {
  366. this.wallet.loading = true
  367. APIGateway.wallet.getMyWallet(this.user.id)
  368. .then((wallet) => {
  369. this.wallet = new Wallet(wallet)
  370. this.wallet.loading = false
  371. this.walletLoaded = true
  372. })
  373. .catch(() => {
  374. this.wallet.loading = false
  375. })
  376. },
  377. getInvoiceFromStore () {
  378. this.invoice = this.$store.getters['Shop/registerClassroomInvoice']
  379. },
  380. loadClassroomFromStore () {
  381. this.classroom = this.$store.getters['Shop/onRegisterClassroom']
  382. },
  383. checkStoreClassroom () {
  384. if (this.classroom === null || typeof this.classroom.id === 'undefined' || this.classroom.id === null) {
  385. this.$router.push({ name: 'Public.AllClassrooms' })
  386. }
  387. },
  388. register () {
  389. // this.$axios.put(API_ADDRESS.classroom.register(this.classroom.id), {
  390. // classroom: this.classroom.id
  391. // })
  392. // .then(() => {
  393. // this.$router.push({ name: 'UserPanel.PaymentResult' })
  394. // })
  395. },
  396. getHoldingType (type) {
  397. const target = Enums.classroomHoldingTypes.find(item => item.value === type)
  398. if (target) {
  399. return target.label
  400. }
  401. return '-'
  402. },
  403. getAudienceGenderType (type) {
  404. const target = Enums.genders.find(item => item.value === type)
  405. if (target) {
  406. return target.label
  407. }
  408. return '-'
  409. },
  410. getTime (time) {
  411. return ShamsiDate.getDateTime(time)
  412. },
  413. getTerm (classroom) {
  414. if (!classroom.beginning_registration_period) {
  415. return '-'
  416. }
  417. return ShamsiDate.getTerm(classroom.beginning_registration_period)
  418. }
  419. }
  420. }
  421. </script>
  422. <style scoped lang="scss">
  423. .complete-info {
  424. margin-bottom: 102px;
  425. .complete-info-top-banner {
  426. margin-top: 50px;
  427. margin-bottom: 42px;
  428. }
  429. .complete-info-steps-card {
  430. background-color: #F5F5F5;
  431. padding: 35px 0;
  432. border-radius: 8px;
  433. display: flex;
  434. flex-flow: row;
  435. justify-content: center;
  436. margin-bottom: 44px;
  437. .complete-info-step {
  438. display: flex;
  439. flex-flow: row;
  440. position: relative;
  441. width: 20%;
  442. &:first-child
  443. &:nth-child(2) {
  444. .title {
  445. color: #5B7A5F;
  446. }
  447. }
  448. &:after {
  449. content: ' ';
  450. position: absolute;
  451. left: 0;
  452. top: 10px;
  453. width: 95%;
  454. border-top: dotted 2px #5B7A5F;
  455. z-index: 1;
  456. }
  457. &:last-child {
  458. &:after {
  459. width: 0;
  460. }
  461. .title {
  462. //color: #BCBCBC;
  463. }
  464. }
  465. .title {
  466. position: relative;
  467. background-color: #F5F5F5;
  468. z-index: 2;
  469. padding-right: 20px;
  470. }
  471. svg {
  472. width: 17px;
  473. position: relative;
  474. background-color: #F5F5F5;
  475. z-index: 2;
  476. padding-right: 8px;
  477. }
  478. }
  479. }
  480. .info-column {
  481. width: 100%;
  482. display: flex;
  483. flex-flow: column;
  484. justify-content: center;
  485. align-items: center;
  486. .invoice-info {
  487. width: 100%;
  488. max-width: 643px;
  489. margin-bottom: 40px;
  490. }
  491. .payment-card {
  492. width: 100%;
  493. max-width: 643px;
  494. }
  495. }
  496. .complete-info-pay-banner {
  497. margin-bottom: 26px;
  498. }
  499. .complete-info-pay-form-card {
  500. background-color: #F5F5F5;
  501. padding: 30px;
  502. border-radius: 8px;
  503. .complete-info-pay-form-card-title {
  504. margin-bottom: 22px;
  505. }
  506. .product-item {
  507. display: flex;
  508. flex-flow: row;
  509. justify-content: space-between;
  510. .product-item-title {
  511. display: flex;
  512. flex-flow: row;
  513. .product-item-icon {
  514. margin-right: 10px;
  515. }
  516. }
  517. .product-item-price {
  518. svg {
  519. margin-right: 10px;
  520. }
  521. }
  522. }
  523. }
  524. .section-edit-btn {
  525. margin-top: 50px;
  526. margin-bottom: 77px;
  527. }
  528. }
  529. </style>