Project: Mall App Client: Maiora
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

outlet-details.page.ts 3.5 KiB

pirms 6 gadiem
pirms 6 gadiem
pirms 6 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { Component, OnInit } from '@angular/core';
  2. import { ActivatedRoute, Router } from '@angular/router';
  3. import { Location } from '@angular/common';
  4. import { ICart } from '../cart/cart.page';
  5. import * as moment from 'moment';
  6. @Component({
  7. selector: 'app-outlet-details',
  8. templateUrl: './outlet-details.page.html',
  9. styleUrls: ['./outlet-details.page.scss'],
  10. })
  11. export class OutletDetailsPage implements OnInit {
  12. show_top_bar: boolean = false;
  13. show_only_veg: boolean = false;
  14. selected_tag: string = null;
  15. show_sort_popup: boolean = false;
  16. selected_sort: string = null;
  17. show_grid: boolean = true;
  18. show_filter_popup: boolean = false;
  19. outlet_details: any;
  20. mallId: number;
  21. userCart: ICart = {
  22. orderedlist: []
  23. };
  24. constructor(
  25. private route: ActivatedRoute,
  26. private router: Router,
  27. private location: Location,
  28. ) { }
  29. ngOnInit() { }
  30. getFormatterDateTime(date: any, format: string) {
  31. return moment(date).format(format);
  32. }
  33. ionViewDidEnter() {
  34. this.outlet_details = JSON.parse(this.route.snapshot.paramMap.get('outlet'));
  35. this.mallId = Number(this.route.snapshot.paramMap.get('mallId'));
  36. this.fetchCartItems();
  37. }
  38. fetchCartItems() {
  39. if (localStorage.userCart) {
  40. this.userCart = JSON.parse(localStorage.userCart);
  41. } else {
  42. localStorage.userCart = JSON.stringify(this.userCart);
  43. }
  44. }
  45. ionViewDidLeave() {
  46. localStorage.userCart = JSON.stringify(this.userCart);
  47. }
  48. addToCart(item: any) {
  49. this.userCart.orderedlist.push({
  50. mall_id: this.mallId,
  51. outlet_id: this.outlet_details.outlet_id,
  52. item_id: item.menuitem_id,
  53. quantity: 1,
  54. pickup_time: moment().add(moment.duration(item.wait_duration).asMinutes(), 'minutes').format(),
  55. take_away: true,
  56. order_status: false,
  57. total_price: item.item_price - item.item_discount,
  58. soft_delete: false
  59. });
  60. }
  61. isItemPresentInCart(itemId: number) {
  62. let item = this.userCart.orderedlist.find((order) => {
  63. return order.item_id === itemId;
  64. });
  65. return item ? true : false;
  66. }
  67. back() {
  68. this.location.back();
  69. }
  70. onScroll(event: any) {
  71. if (event.detail.scrollTop > 100) {
  72. this.show_top_bar = true;
  73. } else {
  74. this.show_top_bar = false;
  75. }
  76. }
  77. sortBy(type: string) {
  78. this.selected_sort = type;
  79. switch(this.selected_sort) {
  80. case 'name': this.outlet_details.menuitems.sort(function(a: any, b: any){
  81. if(a.menu_item_name < b.menu_item_name) { return -1; }
  82. if(a.menu_item_name > b.menu_item_name) { return 1; }
  83. return 0;
  84. });
  85. break;
  86. case 'rating': this.outlet_details.menuitems.sort(function(a: any, b: any){
  87. if(a.rating < b.rating) { return -1; }
  88. if(a.rating > b.rating) { return 1; }
  89. return 0;
  90. }).reverse();
  91. break;
  92. case 'price': this.outlet_details.menuitems.sort(function(a: any, b: any){
  93. if((a.item_price - a.item_discount) < (b.item_price - b.item_discount)) { return -1; }
  94. if((a.item_price - a.item_discount) > (b.item_price - b.item_discount)) { return 1; }
  95. return 0;
  96. });
  97. break;
  98. }
  99. }
  100. goToCart() {
  101. localStorage.userCart = JSON.stringify(this.userCart);
  102. this.router.navigate(['/cart']);
  103. }
  104. }