import { HttpClient } from '@angular/common/http' ; import { Injectable } from '@angular/core' ; @ Injectable ( ) export class CinemasProvider { areas : string [ ] ; brands : string [ ] ; cinemas : any [ ] ; constructor ( public http ) { } getCinemas ( cityId , cinemaArea , cinemaBrand ) { let cinemasUrl = "http://m.maoyan.com/cinemas.json?ci=" + cityId ; this . http . get ( cinemasUrl ) . subscribe ( data => { this . areas = [ "全部" ] ; this . brands = [ "全部" ] ; this . cinemas = [ ] ; let allCinemas = [ ] ; for ( let area in data [ "data" ] ) { this . areas . push ( area ) ; for ( let cinema of data [ "data" ] [ area ] ) { allCinemas . push ( cinema ) ; } } let tempBrands = new Set ( ) ; allCinemas . map ( value => { tempBrands . add ( value [ "brd" ] ) ; } ) ; if ( tempBrands . has ( "其它" ) ) { tempBrands . delete ( "其它" ) ; tempBrands . add ( "其它" ) ; } tempBrands . forEach ( value => { this . brands . push ( value ) ; } ) ; if ( cinemaArea === "全部" && cinemaBrand === "全部" ) { allCinemas . map ( cinema => { this . cinemas . push ( cinema ) ; } ) ; } else if ( cinemaArea !== "全部" && cinemaBrand === "全部" ) { allCinemas . map ( cinema => { if ( cinema [ "area" ] === cinemaArea ) { this . cinemas . push ( cinema ) ; } } ) ; } else if ( cinemaArea === "全部" && cinemaBrand !== "全部" ) { allCinemas . map ( cinema => { if ( cinema [ "brd" ] === cinemaBrand ) { this . cinemas . push ( cinema ) ; } } ) ; } else if ( cinemaArea !== "全部" && cinemaBrand !== "全部" ) { allCinemas . map ( cinema => { if ( cinema [ "area" ] === cinemaArea && cinema [ "brd" ] === cinemaBrand ) { this . cinemas . push ( cinema ) ; } } ) ; } console . log ( "areas" , this . areas ) ; console . log ( "brands" , this . brands ) ; console . log ( "cinemas" , this . cinemas ) ; } ) ; } getCinemaDetail ( cinemaId ) { return new Promise ( resole => { let cinemaDetailUrl = "http://m.maoyan.com/ajax/cinemaDetail?cinemaId=" + cinemaId ; this . http . get ( cinemaDetailUrl ) . subscribe ( data => { resole ( data ) ; } ) ; } ) ; } }