import { Component, Injector, Input, Output, EventEmitter, OnInit, AfterViewInit } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { CreateAddressInput, AddressTypeServiceProxy, PostalCodeServiceProxy, UpdateAddressInput } from '@shared/service-proxies/service-proxies'; import * as countries from '@app/sprintship/countries.json'; @Component({ selector: 'addressForm', templateUrl: './address-form.component.html', styleUrls: ['address-form.component.less'] }) export class AddressFormComponent extends AppComponentBase { @Input() address: UpdateAddressInput = new UpdateAddressInput(); @Input('selectedCountry') selectedCountry: string; @Input('selectedCity') selectedCity: string; @Input('selectedState') selectedState: string; @Input('postalCodeId') selectedPostalCodeId: number; @Input('postalCodeValue') selectedPostalCodeValue: string; // @Input('country') country: string; // @Input('address1Input') address1InputValue:string; // @Input('address2Input') address2InputValue:string; // @Input('addressType') addressTypeValue: string; constructor( injector: Injector, // private _countryService: CountryServiceProxy, // private _cityService: CityServiceProxy, // private _stateService: StateServiceProxy, private _addressTypeService: AddressTypeServiceProxy, private _postalCodeService: PostalCodeServiceProxy, ) { super(injector); } filteredCountries: any = countries.default; filteredCities: any; filteredStates: any; filteredPostal: any; filteredAddressType: any; selectedPostalCode: string; postals:any; postalComplete: any; filterChange = false postalDontExistsFlag : boolean city: string; state: string; country: string; value: string; stateFeature: boolean; ngOnInit() { this.stateFeature = abp.features.isEnabled('App.StateFeature'); // console.log(this.stateFeature) if(!this.stateFeature){ this.state=""; } var that = this; // $('.kt-select2').select2(); let maxcount = 1000; this.filterAddressTypes(maxcount); // this.filterCountries(undefined); // console.log(this.selectedCountry) $("#countrySelectInput").change(function () { that.country = $("#countrySelectInput option:selected").text(); that.country = $.trim(that.country) }) // console.log(this.selectedCountry) // console.log(this.address) } ngAfterViewInit(){ // this.filterCountries(this.selectedPostalCodeValue) // console.log(this.selectedPostalCodeValue) } ngOnChanges(){ // if(this.country){ // $('.kt-select2').select2(); // console.log("change"+this.country) // } // this.filterPostal(); // if(this.selectedPostalCodeValue){ // this.filterCountries(this.selectedPostalCodeValue) // this.filterStates(this.selectedPostalCodeValue) // this.filterCities(this.selectedPostalCodeValue) // } // if(this.country){ // console.log("hello") // } } autoCompletePostal(event){ this._postalCodeService.getAllPostalCodeAutoComplete(this.postalComplete,undefined) .subscribe(result =>{ this.postals = result.items }) } getPostalId(){ if(this.postalComplete.id == undefined){ this.selectedPostalCodeId = null this.postalDontExistsFlag = true }else{ this.postalDontExistsFlag = false this.selectedPostalCodeId = this.postalComplete.id // this.filterCountries(this.postalComplete.value) // this.filterStates(this.postalComplete.value) // this.filterCities(this.postalComplete.value) } } backAutoComplete(){ this.postalDontExistsFlag = false this.postalComplete = null } filterPostal(): void { this._postalCodeService.getDistinctPostalCode( undefined ).subscribe(result => { this.filteredPostal = result.items; }); } filterCountries(postalCode): void { this._postalCodeService.getDistinctCountry( undefined, undefined ).subscribe(result => { this.filteredCountries = result.items; $("#selectedCountry").text(this.filteredCountries[0]['country']); }); } filterStates(postalCode): void { this._postalCodeService.getDistinctState( postalCode, undefined ).subscribe(result => { this.filteredStates = result.items; $("#selectedState").text(this.filteredStates[0]['state']); }); } filterCities(postalCode): void { this._postalCodeService.getDistinctCity( postalCode, undefined ).subscribe(result => { this.filteredCities = result.items; $("#selectedCity").text(this.filteredCities[0]['city']); }); } filterAddressTypes(maxcount): void { this._addressTypeService.getAddressType( undefined, undefined, undefined, undefined, maxcount, undefined ).subscribe(result => { this.filteredAddressType = result.items; }); } }