File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/pages/user-locations/user-locations.page.ts
import { Location } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { UserService } from '../../services/user.service';
@Component({
selector: 'app-user-locations',
templateUrl: './user-locations.page.html',
styleUrls: ['./user-locations.page.scss'],
})
export class UserLocationsPage implements OnInit {
infoConfirmOrder: any = {
address: "",
wayPay: "",
cellphone: "",
observations: "",
point_sale_id: "",
};
listAddressUser: any;
addressUserLastUsed: any;
constructor(
private router: Router,
public userService: UserService,
private location: Location
) { }
ngOnInit() { }
ionViewWillEnter() {
this.getInfoAddressLastUsed();
}
getInfoAddressLastUsed() {
this.userService.getInfoUser().then((resp: any) => {
this.listAddressUser = resp["addresses"];
this.addressUserLastUsed = this.listAddressUser.find(
(addressLastUsed) => addressLastUsed.last_used === 1
);
this.infoConfirmOrder.address = this.addressUserLastUsed.id;
});
}
addNewAddress() {
this.router.navigate(["/address/confirmOrder/true"]);
}
async selectAddress(addressId) {
await this.userService.updateLastUsedAddress(addressId).then(() => {
setTimeout(() => {
console.log('selectAddress');
this.location.back();
}, 500);
});
}
doRefresh(event) {
setTimeout(() => {
event.target.complete();
}, 500);
}
}