From 1d0fcaacf18df497a40fb67d01090f75c31e66e5 Mon Sep 17 00:00:00 2001 From: kj1352 Date: Fri, 31 Jan 2020 13:40:00 +0530 Subject: [PATCH] Cart page Partial UI Completed --- src/app/cart/cart.page.html | 74 +++++------ src/app/cart/cart.page.ts | 116 +++++++++++++++++- src/app/malls/malls.page.ts | 2 +- src/app/outlet-details/outlet-details.page.ts | 20 +-- 4 files changed, 156 insertions(+), 56 deletions(-) diff --git a/src/app/cart/cart.page.html b/src/app/cart/cart.page.html index 86f1b13..f8b4920 100644 --- a/src/app/cart/cart.page.html +++ b/src/app/cart/cart.page.html @@ -1,4 +1,4 @@ - -
+ - Pay Now + -
+ -
+
- Add On + Add On
-
{{ item.wait_duration }} min
@@ -128,7 +130,7 @@
-
{{ item.name }}
+
{{ item.menu_item_name }}
{{ item.wait_duration }} min
@@ -136,8 +138,8 @@
- ₹ {{ calculateDiscount(item.price, item.discount) }} -
@@ -146,4 +148,4 @@
- --> + diff --git a/src/app/cart/cart.page.ts b/src/app/cart/cart.page.ts index 060f87f..1aba7a2 100644 --- a/src/app/cart/cart.page.ts +++ b/src/app/cart/cart.page.ts @@ -3,6 +3,7 @@ import { Location } from '@angular/common'; import { MallService } from '../services/mall.service'; import { Router } from '@angular/router'; import { ToastController } from '@ionic/angular'; +import * as moment from 'moment'; export type ICart = { orderedlist: Array<{ @@ -25,13 +26,124 @@ export type ICart = { }) export class CartPage implements OnInit { + userCart: ICart = { + orderedlist: [] + }; + show_order_details: boolean = false; + cart_outlets: any = []; + allMalls: any = []; + tempPickupTime: any; + showInstantMenu: boolean = false; + temp_outlet_details: any; + constructor( private location: Location, - private mallService: MallService, private router: Router, - public toastController: ToastController + public toastController: ToastController, + private mallService: MallService ) { } ngOnInit() {} + ionViewDidEnter() { + this.fetchCartItems(); + this.allMalls = JSON.parse(localStorage.allMalls); + } + + fetchCartItems() { + this.cart_outlets = []; + + if (localStorage.userCart) { + this.userCart = JSON.parse(localStorage.userCart); + } else { + localStorage.userCart = JSON.stringify(this.userCart); + } + + // this.cart_malls = this.userCart.orderedlist.map(order => order.mall_id); + + for (let i = 0; i < this.userCart.orderedlist.length; i += 1) { + let tempOutlet = this.cart_outlets.find((outlet) => { + return outlet.outlet_id === this.userCart.orderedlist[i].outlet_id && + outlet.mall_id === this.userCart.orderedlist[i].mall_id + }); + + if (!tempOutlet) { + this.cart_outlets.push({ + outlet_id: this.userCart.orderedlist[i].outlet_id, + mall_id: this.userCart.orderedlist[i].mall_id + }) + } + } + } + + hideMenuButton() { + document.querySelector('.menu-icon-holder').classList.add('hide'); + } + + showMenuButton() { + setTimeout(() => { + document.querySelector('.menu-icon-holder').classList.remove('hide'); + }, 1000); + } + + checkIfTimeFeasible(oldTime, newTime) { + return moment(newTime) > moment(oldTime); + } + + getOutletDetails(cartOutlet: any) { + let mall, outlet; + mall = this.allMalls.find((mall) => { + return mall.mall.mall_id === cartOutlet.mall_id; + }); + + if (mall) { + return outlet = mall.mall.outlet.find((outlet) => { + return outlet.outlet_id === cartOutlet.outlet_id; + }); + } + } + + getMallDetails(mallId: number) { + return this.allMalls.find((mall) => { + return mall.mall.mall_id === mallId; + }); + } + + getItemDetails(item) { + let mall, outlet, outletitem; + mall = this.allMalls.find((mall) => { + return mall.mall.mall_id === item.mall_id; + }); + + if (mall) { + outlet = mall.mall.outlet.find((outlet) => { + return outlet.outlet_id === item.outlet_id; + }); + } + + if (outlet) { + return outletitem = outlet.menuitems.find((menu) => { + return menu.menuitem_id === item.item_id; + }); + } + } + + ionViewDidLeave() { + localStorage.userCart = JSON.stringify(this.userCart); + } + + getFormatterDateTime(date: any, format: string) { + return moment(date).format(format); + } + + back() { + this.location.back(); + } + + openInstantMenu(outlet) { + this.showInstantMenu = true; + this.temp_outlet_details = this.getOutletDetails(outlet); + console.log(this.temp_outlet_details); + } + } diff --git a/src/app/malls/malls.page.ts b/src/app/malls/malls.page.ts index 612382f..d6e6779 100644 --- a/src/app/malls/malls.page.ts +++ b/src/app/malls/malls.page.ts @@ -54,7 +54,7 @@ export class MallsPage implements OnInit { this.allMalls = JSON.parse(localStorage.allMalls); this.tempMalls = JSON.parse(localStorage.allMalls); }, (error) => { - console.log(error) + console.log(error); }); } diff --git a/src/app/outlet-details/outlet-details.page.ts b/src/app/outlet-details/outlet-details.page.ts index 130e1a8..3af950f 100644 --- a/src/app/outlet-details/outlet-details.page.ts +++ b/src/app/outlet-details/outlet-details.page.ts @@ -9,6 +9,7 @@ import * as moment from 'moment'; templateUrl: './outlet-details.page.html', styleUrls: ['./outlet-details.page.scss'], }) + export class OutletDetailsPage implements OnInit { show_top_bar: boolean = false; show_only_veg: boolean = false; @@ -62,7 +63,7 @@ export class OutletDetailsPage implements OnInit { pickup_time: moment().add(moment.duration(item.wait_duration).asMinutes(), 'minutes').format(), take_away: true, order_status: false, - total_price: item.item_price, + total_price: item.item_price - item.item_discount, soft_delete: false }); } @@ -87,22 +88,6 @@ export class OutletDetailsPage implements OnInit { } } - // filterByTag(tag: string) { - // if (this.selected_tag === tag) { - // this.selected_tag = null; - // this.temp_outlet_details.menu_items = JSON.parse(JSON.stringify(this.outlet_details.menu_items)); - // } else { - // this.selected_tag = tag; - // let menu_items: Array = []; - // for (let i = 0; i < this.outlet_details.menu_items.length; i += 1) { - // if (this.outlet_details.menu_items[i].tags.includes(tag)) { - // menu_items.push(this.outlet_details.menu_items[i]); - // } - // } - // this.temp_outlet_details.menu_items = menu_items; - // } - // } - sortBy(type: string) { this.selected_sort = type; switch(this.selected_sort) { @@ -128,6 +113,7 @@ export class OutletDetailsPage implements OnInit { } goToCart() { + localStorage.userCart = JSON.stringify(this.userCart); this.router.navigate(['/cart']); }