import React, { Component } from 'react';
import { NavBar, SearchBar, WhiteSpace, List, Toast, Icon } from 'antd-mobile';
import { SearchMask, IndexNav, Indicator, PositionCity, SearchArea } from '../../components';
import { getLocalCity } from '../../services/locationServices';
import {
LASTEST_CITY,
getAllCities,
saveLocalStorageCity,
getLocalStorageCity,
searchCityByName,
transformCityMenuData
} from '../../services/cityServices';
import { throttle } from '../../utils';
import './city.css';
const Item = List.Item;
const searchCity = throttle(searchCityByName);
class City extends Component {
constructor(props) {
super(props);
this.state = {
localCity: '北京',
hotCity: [],
latestCity: [],
city: {},
labels: [],
searchCities: [],
moving: false,
indicator: '',
loading: false,
searchArea: false
};
}
componentDidMount = () => {
this.setState(() => {
Toast.loading('Loading...');
return { loading: true };
});
Promise.all([getLocalCity(), getAllCities(), getLocalStorageCity(LASTEST_CITY)]).then(result => {
const localCity = result[0] && result[0].replace(/市/, '');
const city = result[1].afterFilterAllCity.allCity;
const labels = result[1].afterFilterAllCity.validateLetters;
const hotCity = result[1].hotCity;
const latestCity = result[2];
this.setState(() => {
Toast.hide();
return {
localCity,
city,
hotCity,
labels,
latestCity,
loading: false
};
});
});
}
onSearchInput = async value => {
if (!value) {
this.hideMenuDialog();
return;
}
const { labels, city } = this.state;
const cities = await searchCity(value, labels, city);
this.setState({
searchArea: true,
searchCities: transformCityMenuData(cities)
});
}
hideMenuDialog = () => {
this.setState({
searchArea: false,
searchCities: []
});
}
renderLocalCity = () => {
const { localCity, latestCity } = this.state;
return