Project: Mall App Client: Maiora
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.

mall-details.page.ts 3.4 KiB

пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 6 година
пре 6 година
пре 6 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { Component, OnInit } from '@angular/core';
  2. import { ActivatedRoute, Router } from '@angular/router';
  3. import { Location } from '@angular/common';
  4. import { MallService } from '../services/mall.service';
  5. @Component({
  6. selector: 'app-mall-details',
  7. templateUrl: './mall-details.page.html',
  8. styleUrls: ['./mall-details.page.scss'],
  9. })
  10. export class MallDetailsPage implements OnInit {
  11. mallDetails: any;
  12. selected_tab: string = 'food';
  13. show_top_bar: boolean = false;
  14. show_sort_popup: boolean = false;
  15. selected_sort: string = null;
  16. constructor(
  17. private route: ActivatedRoute,
  18. private router: Router,
  19. private location: Location,
  20. private mallService: MallService
  21. ) { }
  22. ngOnInit() {
  23. this.mallDetails = JSON.parse(this.route.snapshot.paramMap.get('mall'));
  24. }
  25. toggleOutletBookmark(outlet) {
  26. outlet.is_bookmarked = !outlet.is_bookmarked;
  27. this.mallService.updateOutlet(outlet);
  28. }
  29. toggleMallBookmark() {
  30. this.mallDetails.mall.is_bookmarked = !this.mallDetails.mall.is_bookmarked;
  31. console.log(this.mallDetails);
  32. this.mallService.updateMallData(this.mallDetails);
  33. }
  34. back() {
  35. this.location.back();
  36. }
  37. shareMallDetails(mallData) {
  38. if (window.navigator && window.navigator['share']) {
  39. const shareData = {
  40. title: mallData.mall.mall_name,
  41. text: mallData.mall.description,
  42. url: 'https://maps.google.com/?q=' + mallData.latitude + ',' + mallData.longitude
  43. }
  44. window.navigator['share'](shareData);
  45. }
  46. }
  47. shareOutletDetails(outlet) {
  48. if (window.navigator && window.navigator['share']) {
  49. const shareData = {
  50. title: this.mallDetails.mall.mall_name + ',' + outlet.outlet_name,
  51. text: outlet.description,
  52. url: 'https://maps.google.com/?q=' + this.mallDetails.latitude + ',' + this.mallDetails.longitude
  53. }
  54. window.navigator['share'](shareData);
  55. }
  56. }
  57. onScroll(event: any) {
  58. if (event.detail.scrollTop > 100) {
  59. this.show_top_bar = true;
  60. } else {
  61. this.show_top_bar = false;
  62. }
  63. }
  64. outletDetails(outlet: any) {
  65. this.router.navigate(['/outlet-details', {
  66. outlet: JSON.stringify(outlet),
  67. mallId: this.mallDetails.mall.mall_id,
  68. mallData: JSON.stringify({
  69. title: this.mallDetails.mall.mall_name,
  70. text: this.mallDetails.mall.description,
  71. url: 'https://maps.google.com/?q=' + this.mallDetails.latitude + ',' + this.mallDetails.longitude
  72. })
  73. }]);
  74. }
  75. sortBy(type: string) {
  76. this.selected_sort = type;
  77. switch(this.selected_sort) {
  78. case 'name': this.mallDetails.mall.outlet.sort(function(a: any, b: any){
  79. if(a.outlet_name < b.outlet_name) { return -1; }
  80. if(a.outlet_name > b.outlet_name) { return 1; }
  81. return 0;
  82. });
  83. break;
  84. case 'rating': this.mallDetails.mall.outlet.sort(function(a: any, b: any){
  85. if(a.rating < b.rating) { return -1; }
  86. if(a.rating > b.rating) { return 1; }
  87. return 0;
  88. }).reverse();
  89. break;
  90. }
  91. }
  92. togglePopup() {
  93. this.show_sort_popup = !this.show_sort_popup;
  94. }
  95. }