/** * 首页地图工具组件 * @邠心vbe on 2021/08/13 */ import React, { Component } from 'react'; import { View, StyleSheet, TouchableOpacity } from 'react-native'; import Button, { ElevationObject } from '../../../components/Button'; import BottomModal from '../../../components/BottomModal'; import Filter from './Filter'; import { PageList } from '../../Router'; import utils from '../../../utils/utils'; import Dialog from '../../../components/Dialog'; import apiStation from '../../../api/apiStation'; export default class MapTool extends Component { constructor(props) { super(props); this.state = { showFilter: false, filterIndex: {}, filterTotal: 0, }; } componentDidUpdate() { if (this.props.count != this.state.filterTotal) { this.setState({ filterTotal: this.props.count }) } } findFilter(data, index) { this.setState({ filterIndex: index }); this.hideFilter(); if (this.props.onFilter) { this.props.onFilter(data); } } showFilter() { this.setState({ showFilter: true }); } hideFilter() { this.setState({ showFilter: false }); } getNearestStation() { navigator.geolocation.getCurrentPosition(location => { let params = { lat: location.coords.latitude, lng: location.coords.longitude } Dialog.showProgressDialog(); apiStation.getNearestSite(params).then(res => { Dialog.dismissLoading(); if (res.data.sitePk) { var station = { id: res.data.sitePk, name: res.data.siteName, address: res.data.address, latitude: res.data.locationLatitude, longitude: res.data.locationLongitude, } setTimeout(() => { utils.directMaps(station.latitude, station.longitude, station.address); }, 500); } else { toastShort("您附近没有充电桩"); } }).catch(err => { toastShort(err); Dialog.dismissLoading(); }); }); } render() { return ( { this.props.mapReady && this.props.onLocation()}> } { this.props.mapReady && { this.showFilter() }}> } { startPage(PageList.scanqr, {actionDetail: true}); }}> {/*