沈斌
2018-07-12 1dfc8bc300a6ae0822514ddf2e1399d4762fa1b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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;
       }
    );
   }
}