You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
4.9 KiB

  1. <template>
  2. <main>
  3. <ul class="schedule-grid">
  4. <li
  5. v-for="schedule in schedules"
  6. :key="schedule.fields.Record_ID"
  7. class="grid__row"
  8. >
  9. <div class="grid__field">
  10. <label> Local Airline </label>
  11. <div class="field__content">
  12. {{ schedule.fields.Carrier_Name }}
  13. </div>
  14. </div>
  15. <div class="grid__field">
  16. <label> Days of the Week </label>
  17. <div class="field__content">
  18. <div class="dow-grid">
  19. <div
  20. v-for="day in daysList(schedule.fields.Frequency_Convert)"
  21. :key="day.name"
  22. :class="['dow-grid__day', 'day--' + day.name]"
  23. >
  24. <span> {{ day.name }} </span>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. <div class="grid__field">
  30. <label> Departing </label>
  31. <div class="field__content">
  32. {{ schedule.fields.Departure_TimeL }}
  33. </div>
  34. </div>
  35. <div class="grid__field">
  36. <label> Arriving </label>
  37. <div class="field__content">
  38. {{ schedule.fields.Arrival_TimeL }}
  39. </div>
  40. </div>
  41. <div class="grid__field">
  42. <label> Available Until </label>
  43. <div class="field__content">
  44. {{ schedule.fields.Effective_End }}
  45. </div>
  46. </div>
  47. <div class="grid__field">
  48. <div class="field__content">
  49. {{ schedule.fields.Price_USD }}
  50. </div>
  51. <button class="btn btn--primary" @click="book(schedule)">
  52. {{ schedule.fields.IsExpedia[0] === 'true' ? 'book it!' : 'see flights' }}
  53. </button>
  54. </div>
  55. </li>
  56. </ul>
  57. <div v-if="startingDate">
  58. <DatePicker
  59. :starting-date="startingDate"
  60. :selected-schedule="selectedSchedule"
  61. :selected-days="selectedDays"
  62. />
  63. </div>
  64. </main>
  65. </template>
  66. <script>
  67. export default {
  68. data () {
  69. return {
  70. schedules: [],
  71. startingDate: '',
  72. selectedSchedule: {},
  73. selectedDays: []
  74. }
  75. },
  76. async fetch () {
  77. // console.log(this.$route.params.o)
  78. const scheduleFetchFilterFormula = `AND(Is_Current="Yes",AND(Origin_IATA="${this.$route.params.o}",Destination_IATA="${this.$route.params.d}"))`
  79. const scheduleFetchSort = '&sort[0][field]=DepartureTimeFormatted&sort[0][direction]=asc'
  80. const response = await fetch(`https://api.airtable.com/v0/appiQwfVZixRgRICe/Schedule?filterByFormula=${scheduleFetchFilterFormula}${scheduleFetchSort}`, {
  81. method: 'GET',
  82. headers: {
  83. 'Content-Type': 'application/x-www-form-urlencoded',
  84. Authorization: 'Bearer keyJ2ht64ZSN57AG1'
  85. }
  86. })
  87. const data = await response.json()
  88. // console.log(data)
  89. this.schedules = [...data.records]
  90. },
  91. computed: {
  92. },
  93. methods: {
  94. daysList (days) {
  95. const list = days.split(', ').map((day) => {
  96. const name = day.toLowerCase().slice(0, -1)
  97. let num
  98. switch (name) {
  99. case 'su':
  100. num = 0
  101. break
  102. case 'mo':
  103. num = 1
  104. break
  105. case 'tu':
  106. num = 2
  107. break
  108. case 'we':
  109. num = 3
  110. break
  111. case 'th':
  112. num = 4
  113. break
  114. case 'fr':
  115. num = 5
  116. break
  117. case 'sa':
  118. num = 6
  119. break
  120. default:
  121. break
  122. }
  123. return {
  124. name,
  125. num
  126. }
  127. })
  128. return list.sort(function (a, b) {
  129. return a.num - b.num
  130. })
  131. },
  132. book (schedule) {
  133. if (schedule.fields.IsExpedia[0] === 'true') {
  134. this.startingDate = new Date()
  135. this.selectedSchedule = schedule.fields
  136. this.selectedDays = this.daysList(schedule.fields.Frequency_Convert)
  137. } else {
  138. window.open(schedule.fields['BookingLink (from Carriers_Alaska)'][0])
  139. }
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss">
  145. .schedule-grid {
  146. display: flex;
  147. flex-direction: column;
  148. gap: 1rem;
  149. }
  150. .grid__row {
  151. display: grid;
  152. grid-template-columns: 2fr 2fr 1fr 1fr 2fr 1fr;
  153. grid-template-rows: auto;
  154. gap: 1rem;
  155. }
  156. // .grid__field {
  157. // }
  158. label {
  159. font-size: 0.5rem;
  160. font-weight: 700;
  161. color: gray;
  162. display: block;
  163. }
  164. .field__content {
  165. font-size: 1.5rem;
  166. }
  167. .dow-grid {
  168. width: 200px;
  169. display: grid;
  170. grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
  171. gap: 0.5rem;
  172. }
  173. .dow-grid__day {
  174. font-size: 0.8rem;
  175. border: 1px solid #ccc !important;
  176. display: flex;
  177. align-items: center;
  178. justify-content: center;
  179. border-radius: 3px !important;
  180. text-transform: capitalize;
  181. }
  182. .day--su {
  183. grid-column: 1 / span 1;
  184. }
  185. .day--mo {
  186. grid-column: 2 / span 1;
  187. }
  188. .day--tu {
  189. grid-column: 3 / span 1;
  190. }
  191. .day--we {
  192. grid-column: 4 / span 1;
  193. }
  194. .day--th {
  195. grid-column: 5 / span 1;
  196. }
  197. .day--fr {
  198. grid-column: 6 / span 1;
  199. }
  200. .day--sa {
  201. grid-column: 7 / span 1;
  202. }
  203. </style>