import { Component, OnInit } from '@angular/core'; import { SelectItem, DynamicDialogRef, DynamicDialogConfig } from 'primeng/api'; import { GeneralService } from '../../../services/general/general.service'; import { CookieService } from 'ngx-cookie-service'; import { IDimensionRate } from '../../../core/shipping/IDimensionRate'; import { IDimensionRange } from '../../../core/shipping/IDimensionRange'; @Component({ selector: 'app-add-dimension-based-rate', templateUrl: './add-dimension-based-rate.component.html', styleUrls: ['./add-dimension-based-rate.component.scss'] }) export class AddDimensionBasedRateComponent implements OnInit { packages:SelectItem[]=[]; lengths:SelectItem[]=[]; currencyType: string; companyId: number; newRange: IDimensionRange; dimensionBased:IDimensionRate; rangeId:number; constructor(private generalService: GeneralService, private cookieService: CookieService,public refer: DynamicDialogRef, public config: DynamicDialogConfig) { } ngOnInit() { this.getPackages(); this.getLengths(); this.companyId = +this.cookieService.get('CompanyId') this.newRange = { Id:0, Length: 0, RangeAmount: 0, Width: 0, Height:0,DimensionType:2,DimensionTypeStr:'CM' } this.dimensionBased = {Id:0,IsDefault:false,Name:null,RangeList:null,ShippingProfileId:0,PackageType:null} this.dimensionBased.RangeList = []; // get dimensionBased if (this.config.data.dimensionBased) { this.dimensionBased = this.config.data.dimensionBased; if(this.config.data.rangeId){ this.rangeId = this.config.data.rangeId; } if(this.dimensionBased.RangeList!=undefined && this.dimensionBased.RangeList.length>0){ this.dimensionBased.RangeList.forEach(element => { element.DimensionTypeStr = this.lengths.find(x=>x.value == element.DimensionType).label; if(element.Id == this.rangeId){ this.newRange = element; } }); } else{ this.dimensionBased.RangeList = []; } } //Get general settings this.getCurrencyFormat(); } getPackages(){ this.packages = [ {label:'Box', value:1}, {label:'Envelope', value:2}, {label:'Soft Package', value:3} ] } getLengths(){ this.lengths = [ {label:'MM', value:1}, {label:'CM', value:2}, {label:'M', value:3} ] } //Get general settings getCurrencyFormat() { this.generalService.GetCurrencyFormat(this.companyId).subscribe(data => { if (data.CustomCurrency != null && data.CustomCurrency != undefined && data.CustomCurrency != '') { this.currencyType = data.CustomCurrency } else { this.currencyType = data.StoreCurrencyCode; } }) } // add range AddRange() { if (this.newRange.Length > 0 && this.newRange.Width > 0 && this.newRange.Height > 0 ) { this.newRange.DimensionTypeStr = this.lengths.find(x=>x.value == this.newRange.DimensionType).label; if(this.newRange.Id>0){ this.dimensionBased.RangeList.forEach(element => { if(element.Id == this.rangeId){ element = this.newRange; } }); } else{ this.dimensionBased.RangeList.push(this.newRange); } this.newRange = { Id:0, Length: 0, RangeAmount: 0, Width: 0, Height:0,DimensionType:2 ,DimensionTypeStr:'CM'} } } // save save(){ this.refer.close(this.dimensionBased); } // cancel cancel(){ this.refer.close(this.dimensionBased); } }