| import { Injectable } from '@angular/core'; | 
| import { _HttpClient } from '@delon/theme/services/http/http.client'; | 
| 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, isLeaf ?: Boolean): 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: isLeaf === undefined ? true : isLeaf}; | 
|                }); | 
|           } | 
|           return areas; | 
|        } | 
|     ); | 
|    } | 
|     | 
|    getTowns(areaCode: string): Observable<{label: string, value: string}[]> { | 
|     return this.http.get( this.baseUrl + '/area/get-towns', {areaCode: areaCode}).map( | 
|        (res: {code: number, data: any}) => { | 
|           let towns = []; | 
|           if (res !== null && res['code'] === 1 ) { | 
|             towns = res['data'].map((item) => { | 
|                  return {label: item.townName , value: item.townCode}; | 
|                }); | 
|           } | 
|           return towns; | 
|        } | 
|     ); | 
|    } | 
|    getVillages(townCode: string): Observable<{label: string, value: string}[]> { | 
|     return this.http.get( this.baseUrl + '/area/get-villages', {townCode: townCode}).map( | 
|        (res: {code: number, data: any}) => { | 
|           let villages = []; | 
|           if (res !== null && res['code'] === 1 ) { | 
|             villages = res['data'].map((item) => { | 
|                  return {label: item.villageName , value: item.villageCode , isLeaf: true}; | 
|                }); | 
|           } | 
|           return villages; | 
|        } | 
|     ); | 
|    } | 
| } |