import { Component, ViewChild, Injector, Output, EventEmitter} from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { AddressesServiceProxy, CreateOrEditAddressDto, UpdateAddressInput, PostalCodeServiceProxy, PickupDetailInput, CreatePostalCodeInput } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; import { AddressFormComponent } from '@app/shared/layout/form/address-form.component'; import { ViewOrderComponent } from './view-order.component'; @Component({ selector: 'updateAddressModalComponent', templateUrl: './update-address-modal.component.html' }) export class UpdateOrderAddressModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @ViewChild(AddressFormComponent, {static:false}) addressForm; @Output() modalSave: EventEmitter = new EventEmitter(); @Output() viewOrder = new EventEmitter(); active = false; saving = false; address: CreateOrEditAddressDto = new CreateOrEditAddressDto(); address2: UpdateAddressInput = new UpdateAddressInput(); postalCodeInput: CreatePostalCodeInput = new CreatePostalCodeInput(); postalCodeValue = ''; addressTypeName : any; postalCodeId : number; postalCodeCountry : string; router: any; stateFeature:boolean; constructor( injector: Injector, private _addressesServiceProxy: AddressesServiceProxy, private _postalCodeServiceProxy: PostalCodeServiceProxy ) { super(injector); } ngOnInit(){ this.stateFeature = abp.features.isEnabled('App.StateFeature'); } show(addressId?: number): void { if (!addressId) { this.address = new CreateOrEditAddressDto(); this.address.id = addressId; this.postalCodeValue = ''; this.addressTypeName = ''; this.address.latitude this.active = true; this.modal.show(); } else { this._addressesServiceProxy.getAddressForEdit(addressId).subscribe(result => { console.log(result) this.address = result.address; this.address.latitude = result.geocodeLatitude; this.address.longitude = result.geocodeLongitude; this.postalCodeId = this.address.postalCodeId; this._postalCodeServiceProxy.getPostalCode(result.address.postalCodeId, undefined, undefined, undefined, undefined, undefined, undefined, undefined) .subscribe(result => { this.addressForm.city = result.items[0].city this.addressForm.state = result.items[0].state this.addressForm.value = result.items[0].value this.addressForm.country = result.items[0].country }) this.postalCodeValue = result.postalCodeValue; this.addressTypeName = result.addressTypeName; this.active = true; this.modal.show(); }); } } save(): void { this.saving = true; this.address = this.addressForm.address; // this.address.postalCodeId = Number((document.getElementById('postalSelectInput')).value); this.address.addressTypeId = Number((document.getElementById('addressTypeSelectInput')).value); this.address.latitude = Number((document.getElementById('Address_GeocodeLatitude')).value); this.address.longitude = Number((document.getElementById('Address_GeocodeLongitude')).value); this.postalCodeInput.city = this.addressForm.city // this.postalCodeInput.state = this.addressForm.state if(!this.stateFeature){ this.postalCodeInput.state = ""; } else{ this.postalCodeInput.state = this.addressForm.state; } this.postalCodeInput.value = this.addressForm.value this.postalCodeInput.country = this.addressForm.country this._postalCodeServiceProxy.createPostalCode(this.postalCodeInput) .pipe() .subscribe(result => { this.address.postalCodeId = result this._addressesServiceProxy.createOrEdit(this.address) .pipe(finalize(() => { this.saving = false;})) .subscribe(( ) => { this.passParent(); this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); }); } setPostalCodeIdNull() { this.address.postalCodeId = null; this.postalCodeValue = ''; } setGeocodeIdNull() { this.address.geocodeId = null; this.address.latitude = 0; this.address.longitude = 0; } setAddressTypeIdNull() { this.address.addressTypeId = null; this.addressTypeName = ''; } close(): void { this.active = false; this.modal.hide(); } passParent(){ this.viewOrder.emit(true); } }