Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. <template>
  2. <q-page class="container" v-if="loaded">
  3. <flight-toolbar
  4. :departure="departureCity"
  5. :arrival="arrivalCity"
  6. />
  7. <q-page-sticky position="top-right" :offset="[15, 13]">
  8. <q-fab flat icon="tune" direction="left">
  9. <q-fab-action color="secondary" icon="attach_money" glossy>
  10. <q-popup-edit
  11. @save="setPrice"
  12. title="Max Price filter"
  13. buttons
  14. v-model="maxPriceFilter"
  15. >
  16. <q-slider
  17. color="secondary"
  18. :min="minimumPrice"
  19. :max="maximumPrice"
  20. label
  21. label-always
  22. v-model="maxPriceFilter"
  23. />
  24. </q-popup-edit>
  25. </q-fab-action>
  26. <q-fab-action color="secondary" icon="schedule" glossy>
  27. <q-popup-edit title="Schedule filter">
  28. <q-datetime
  29. type="time"
  30. format24h
  31. format="HH:mm"
  32. format-model="date"
  33. placeholder="Depart at"
  34. clearable
  35. @input="setDeparture"
  36. v-model="departureTimeFilter"
  37. />
  38. <q-datetime
  39. type="time"
  40. format24h
  41. format="HH:mm"
  42. format-model="date"
  43. placeholder="Arrive by"
  44. clearable
  45. @input="setArrival"
  46. v-model="arrivalTimeFilter"
  47. />
  48. </q-popup-edit>
  49. </q-fab-action>
  50. <q-fab-action
  51. color="secondary"
  52. icon="cancel"
  53. @click="filteredFlights = flights"
  54. glossy
  55. />
  56. </q-fab>
  57. </q-page-sticky>
  58. <div class="heading">
  59. <div class="q-headline text-primary text-center">Select your flight</div>
  60. </div>
  61. <div class="flight__results">
  62. <router-link
  63. :to="{
  64. name: 'selectedFlight',
  65. params: { id: flight.flightNumber, flight: flight }
  66. }"
  67. v-for="flight in filteredFlights"
  68. :key="flight.id"
  69. >
  70. <flight :details="flight" />
  71. </router-link>
  72. </div>
  73. </q-page>
  74. </template>
  75.  
  76. <script>
  77. import { mapState } from "vuex";
  78. import FlightToolbar from "../components/FlightToolbar";
  79. import Flight from "../components/Flight";
  80.  
  81. import { priceFilter, scheduleFilter } from "../mixins/filters";
  82. import { priceSorter, scheduleSorter } from "../mixins/sorters";
  83.  
  84. export default {
  85. name: "FlightResults",
  86.  
  87. components: {
  88. Flight,
  89. FlightToolbar
  90. },
  91.  
  92. mixins: [priceFilter, scheduleFilter, priceSorter, scheduleSorter],
  93.  
  94. created() {
  95. this.$store.dispatch("catalog/fetch");
  96. },
  97.  
  98. data() {
  99. return {
  100. filteredFlights: [],
  101. departureTimeFilter: "",
  102. arrivalTimeFilter: "",
  103. maxPriceFilter: 500
  104. };
  105. },
  106.  
  107. methods: {
  108. setPrice() {
  109. let flights = this.filterByMaxPrice(this.flights, this.maxPriceFilter);
  110. flights = this.sortByPrice(flights);
  111. this.filteredFlights = flights;
  112. },
  113.  
  114. setDeparture() {
  115. let flights = this.filterBySchedule(this.flights, {
  116. departure: this.departureTimeFilter
  117. });
  118.  
  119. flights = this.sortByDeparture(flights);
  120.  
  121. this.filteredFlights = flights;
  122. },
  123.  
  124. setArrival() {
  125. this.filteredFlights = this.filterBySchedule(this.flights, {
  126. arrival: this.arrivalTimeFilter
  127. });
  128. }
  129. },
  130.  
  131. computed: {
  132. ...mapState({
  133. flights: state => state.catalog.flights
  134. }),
  135.  
  136. loaded: function() {
  137. if (this.flights.length) {
  138. this.$q.loading.hide();
  139. } else {
  140. this.$q.loading.show();
  141. }
  142.  
  143. // this.filteredFlights = this.sortByDeparture(this.flights);
  144. this.filteredFlights = this.flights;
  145.  
  146. return !!this.flights;
  147. },
  148.  
  149. departureCity: function() {
  150. // if (this.flights) {
  151. // return this.flights.departureCity;
  152. // }
  153.  
  154. return null;
  155. },
  156.  
  157. arrivalCity: function() {
  158. // if (this.flights) {
  159. // return this.flights.departureCity;
  160. // }
  161.  
  162. return null;
  163. },
  164.  
  165. maximumPrice: function() {
  166. return Math.max(...this.flights.map(filter => filter.ticketPrice), 1);
  167. },
  168.  
  169. minimumPrice: function() {
  170. return Math.min(...this.flights.map(filter => filter.ticketPrice), 1);
  171. }
  172. }
  173. };
  174. </script>
  175.  
  176. <style lang="stylus" scoped>
  177. @import '~variables'
  178.  
  179. .heading
  180. margin-top 5.5rem
  181. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement