MapTool.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /**
  2. * 首页地图工具组件
  3. * @邠心vbe on 2021/08/13
  4. */
  5. import React, { Component } from 'react';
  6. import { View, StyleSheet, TouchableOpacity } from 'react-native';
  7. import Button, { ElevationObject } from '../../../components/Button';
  8. import BottomModal from '../../../components/BottomModal';
  9. import Filter from './Filter';
  10. import { PageList } from '../../Router';
  11. import utils from '../../../utils/utils';
  12. import Dialog from '../../../components/Dialog';
  13. import apiStation from '../../../api/apiStation';
  14. export default class MapTool extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. showFilter: false,
  19. filterIndex: {},
  20. filterTotal: 0,
  21. };
  22. }
  23. componentDidUpdate() {
  24. if (this.props.count != this.state.filterTotal) {
  25. this.setState({
  26. filterTotal: this.props.count
  27. })
  28. }
  29. }
  30. findFilter(data, index) {
  31. this.setState({
  32. filterIndex: index
  33. });
  34. this.hideFilter();
  35. if (this.props.onFilter) {
  36. this.props.onFilter(data);
  37. }
  38. }
  39. showFilter() {
  40. this.setState({
  41. showFilter: true
  42. });
  43. }
  44. hideFilter() {
  45. this.setState({
  46. showFilter: false
  47. });
  48. }
  49. getNearestStation() {
  50. navigator.geolocation.getCurrentPosition(location => {
  51. let params = {
  52. lat: location.coords.latitude,
  53. lng: location.coords.longitude
  54. }
  55. Dialog.showProgressDialog();
  56. apiStation.getNearestSite(params).then(res => {
  57. Dialog.dismissLoading();
  58. if (res.data.sitePk) {
  59. var station = {
  60. id: res.data.sitePk,
  61. name: res.data.siteName,
  62. address: res.data.address,
  63. latitude: res.data.locationLatitude,
  64. longitude: res.data.locationLongitude,
  65. }
  66. setTimeout(() => {
  67. utils.directMaps(station.latitude, station.longitude, station.address);
  68. }, 500);
  69. } else {
  70. toastShort("您附近没有充电桩");
  71. }
  72. }).catch(err => {
  73. toastShort(err);
  74. Dialog.dismissLoading();
  75. });
  76. });
  77. }
  78. render() {
  79. return (
  80. <View>
  81. <View style={styles.mapToolView}>
  82. { this.props.mapReady &&
  83. <TouchableOpacity
  84. style={styles.mapIcon}
  85. activeOpacity={0.7}
  86. onPress={() => this.props.onLocation()}>
  87. <MaterialIcons
  88. name='my-location'
  89. size={26}
  90. color={colorAccent}/>
  91. </TouchableOpacity>
  92. }
  93. { this.props.mapReady &&
  94. <TouchableOpacity
  95. style={styles.mapIcon}
  96. activeOpacity={0.7}
  97. onPress={() => {
  98. this.showFilter()
  99. }}>
  100. <FontAwesome
  101. name='filter'
  102. size={26}
  103. color={colorAccent}/>
  104. </TouchableOpacity>
  105. }
  106. <TouchableOpacity
  107. style={styles.mapIcon}
  108. activeOpacity={0.7}
  109. onPress={() => {
  110. startPage(PageList.scanqr, {actionDetail: true});
  111. }}>
  112. <FontAwesome
  113. name='qrcode'
  114. size={25}
  115. color={colorAccent}/>
  116. </TouchableOpacity>
  117. </View>
  118. {/* <View style={styles.bottomView}>
  119. <Button
  120. style={styles.bottomButton}
  121. textSize={17}
  122. text='Go to Nearest Charging Station'
  123. onClick={() => {
  124. this.getNearestStation();
  125. }
  126. }/>
  127. </View> */}
  128. <BottomModal
  129. visible={this.state.showFilter}
  130. onHide={() => {
  131. this.hideFilter()
  132. }}>
  133. <Filter
  134. index={this.state.filterIndex}
  135. count={this.state.filterTotal}
  136. onDone={(data, index) => this.findFilter(data, index)}
  137. onHide={() => this.hideFilter()}/>
  138. </BottomModal>
  139. </View>
  140. );
  141. }
  142. }
  143. const styles = StyleSheet.create({
  144. mapIcon: {
  145. width: 50,
  146. height: 50,
  147. marginTop: 10,
  148. borderRadius: 56,
  149. alignItems: 'center',
  150. backgroundColor: '#333',
  151. justifyContent: 'center',
  152. ...ElevationObject(1),
  153. shadowColor: '#cccccc'
  154. },
  155. mapToolView: {
  156. right: 24,
  157. zIndex: 10,
  158. bottom: 112,
  159. width: 56,
  160. position: 'absolute',
  161. alignItems: 'center'
  162. },
  163. bottomView: {
  164. left: 0,
  165. right: 0,
  166. bottom: 32,
  167. zIndex: 210,
  168. alignItems: 'center',
  169. position: 'absolute',
  170. },
  171. bottomButton: {
  172. elevation: 1.5,
  173. paddingLeft: 32,
  174. paddingRight: 32,
  175. borderRadius: 54,
  176. overflow: 'hidden',
  177. justifyContent: 'center'
  178. },
  179. nearStation: {
  180. flex: 1,
  181. paddingLeft: 32,
  182. paddingRight: 32,
  183. ...ElevationObject(2),
  184. justifyContent: 'center',
  185. backgroundColor: colorAccent
  186. },
  187. })