Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

151 righe
4.4 KiB

  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { IonSlides } from '@ionic/angular';
  3. import * as faker from 'faker';
  4. import * as moment from 'moment';
  5. import { Router } from '@angular/router';
  6. @Component({
  7. selector: 'app-booking',
  8. templateUrl: './booking.page.html',
  9. styleUrls: ['./booking.page.scss'],
  10. })
  11. export class BookingPage implements OnInit {
  12. @ViewChild('slides') slides: IonSlides;
  13. selectedDate: Date;
  14. teams = [{
  15. name: 'RCB',
  16. image: 'https://i.pinimg.com/originals/4f/f9/99/4ff99925fd51296daf76425b11c04195.jpg'
  17. }, {
  18. name: 'MI',
  19. image: 'assets/logos/mi.svg',
  20. }, {
  21. name: 'CSK',
  22. image: 'https://www.searchpng.com/wp-content/uploads/2019/02/Chennai-Super-Kings-Logo-PNG-Image-.png'
  23. }];
  24. stadiums = [{
  25. name: 'Chinnaswamy',
  26. sideView: 'https://www.royalchallengers.com/PRRCB01/public/styles/1061x767_landscape/public/2020-04/275679.jpg?h=61617f72&itok=6xKgHpE-',
  27. topView: 'assets/home-team/stadium-tv.png',
  28. }, {
  29. name: 'IS Bindra',
  30. sideView: 'https://5.imimg.com/data5/VO/UB/MY-3103550/ae-cricket-stadium-lighting-500x500.jpg',
  31. topView: 'assets/home-team/stadium-tv.png'
  32. }, {
  33. name: 'Chidambaram Stadium',
  34. sideView: 'https://sportzwiki.com/wp-content/uploads/2019/03/11.jpg',
  35. topView: 'assets/home-team/stadium-tv.png',
  36. }];
  37. slideOpts = {
  38. slidesPerView: 1.5,
  39. spaceBetween: 15,
  40. initialSlide: 0,
  41. centeredSlides: true,
  42. simulateTouch: false,
  43. followFinger: false,
  44. };
  45. bookingSeatsData: Array<{
  46. dateTime: Date,
  47. staduim: {
  48. name: string,
  49. topView: string,
  50. sideView: string,
  51. },
  52. matchType: string,
  53. matchDetails: {
  54. home: {
  55. name: string,
  56. image: string,
  57. },
  58. away: {
  59. name: string,
  60. image: string,
  61. }
  62. },
  63. seatsAvailable: Array<{
  64. stand: 'Grand' | 'Pavilion' | 'First' | 'Second',
  65. seats: Array<{
  66. id: number | string,
  67. price: number
  68. }>
  69. }>
  70. }> = [];
  71. constructor(
  72. private router: Router
  73. ) { }
  74. getFormattedDateTime(dateTime: Date) {
  75. return moment(dateTime).format('DD MMM');
  76. }
  77. ngOnInit() {
  78. for (let i = 0; i < 3; i += 1) {
  79. this.bookingSeatsData.push({
  80. dateTime: faker.date.future(),
  81. staduim : this.stadiums[i],
  82. matchType: 'T20 League',
  83. matchDetails: {
  84. home: i !==1 ? this.teams[i] : { name: 'KXIP', image: 'assets/home-team/KXIP.svg' },
  85. away: i ===1 ? this.teams[i] : { name: 'KXIP', image: 'assets/home-team/KXIP.svg' }
  86. },
  87. seatsAvailable: [{
  88. stand: 'Grand',
  89. seats: [],
  90. }, {
  91. stand: 'Pavilion',
  92. seats: [],
  93. }, {
  94. stand: 'First',
  95. seats: [],
  96. }, {
  97. stand: 'Second',
  98. seats: [],
  99. }]
  100. });
  101. }
  102. for (let i = 0; i < this.bookingSeatsData.length; i += 1) {
  103. for (let j = 0; j < this.bookingSeatsData[i].seatsAvailable.length; j += 1) {
  104. let price = faker.commerce.price();
  105. let randomNumber = Math.random() * (15 - 0);
  106. for (let k = 0; k < randomNumber; k += 1) {
  107. this.bookingSeatsData[i].seatsAvailable[j].seats.push({
  108. id: this.bookingSeatsData[i].seatsAvailable[j].stand + '##' + k.toString(),
  109. price
  110. });
  111. }
  112. }
  113. }
  114. this.selectedDate = this.bookingSeatsData[0].dateTime;
  115. }
  116. getEventDateTime(dateTime: Date) {
  117. return moment(dateTime).format('ddd, MMM DD YYYY hh:mm a');
  118. }
  119. selectMatchDate() {
  120. this.slides.getActiveIndex().then((index) => this.selectedDate = this.bookingSeatsData[index].dateTime);
  121. }
  122. selectMatchCard(index: number) {
  123. this.slides.slideTo(index);
  124. }
  125. showBookingDetails(matchData) {
  126. this.router.navigate(['/booking-details' , { matchData: JSON.stringify(matchData) }]);
  127. }
  128. }