SearchTool.js 4.9 KB

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