SearchTool.js 4.9 KB

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