import { Injectable } from '@angular/core';
|
import { _HttpClient } from '@delon/theme/services/http/http.client';
|
// Statics
|
import 'rxjs/add/observable/throw';
|
// Operators
|
import 'rxjs/add/operator/catch';
|
import 'rxjs/add/operator/map';
|
import { Observable } from 'rxjs/Observable';
|
import { environment } from 'environments/environment';
|
|
@Injectable()
|
export class AreacodeService {
|
baseUrl = environment.SERVER_BASH_URL;
|
constructor(private http: _HttpClient) { }
|
getProvinces(): Observable<{label: string, value: string}[]> {
|
return this.http.get( this.baseUrl + '/area/get-provinces' ).map(
|
(res: {code: number, data: any}) => {
|
let provinces = [];
|
if (res !== null && res['code'] === 1 ) {
|
provinces = res['data'].map((item) => {
|
return {label: item.provinceName , value: item.provinceCode };
|
});
|
}
|
return provinces;
|
}
|
);
|
}
|
|
getCities(provinceCode: string): Observable<{label: string, value: string}[]> {
|
return this.http.get( this.baseUrl + '/area/get-cities', {provinceCode: provinceCode}).map(
|
(res: {code: number, data: any}) => {
|
let cities = [];
|
if (res !== null && res['code'] === 1 ) {
|
cities = res['data'].map((item) => {
|
return {label: item.cityName , value: item.cityCode };
|
});
|
}
|
return cities;
|
}
|
);
|
}
|
getAreas(cityCode: string): Observable<{label: string, value: string}[]> {
|
return this.http.get( this.baseUrl + '/area/get-areas', {cityCode: cityCode}).map(
|
(res: {code: number, data: any}) => {
|
let areas = [];
|
if (res !== null && res['code'] === 1 ) {
|
areas = res['data'].map((item) => {
|
return {label: item.areaName , value: item.areaCode , isLeaf: true};
|
});
|
}
|
return areas;
|
}
|
);
|
}
|
}
|