SearchTool.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. <BackButton
  93. style={styles.mapIcon}
  94. onPress={() => this.showFilter()}>
  95. <FontAwesome
  96. name='filter'
  97. size={26}
  98. color={colorPrimary}/>
  99. </BackButton>
  100. <BackButton
  101. style={styles.mapIcon}
  102. onPress={() => this.props.onLocation()}>
  103. <MaterialIcons
  104. name='my-location'
  105. size={26}
  106. color={colorPrimary}/>
  107. </BackButton>
  108. {/* <View style={styles.mapToolView}>
  109. <TouchableOpacity
  110. style={styles.mapIcon}
  111. activeOpacity={0.7}
  112. onPress={() => {
  113. startPage(PageList.scanqr, {actionDetail: true});
  114. }}>
  115. <FontAwesome
  116. name='qrcode'
  117. size={25}
  118. color={colorPrimary}/>
  119. </TouchableOpacity>
  120. </View> */}
  121. </View>
  122. <BottomModal
  123. visible={this.state.showFilter}
  124. onHide={() => {
  125. this.hideFilter()
  126. }}>
  127. <Filter
  128. index={this.state.filterIndex}
  129. count={this.state.filterTotal}
  130. onDone={(data, index) => this.findFilter(data, index)}
  131. onHide={() => this.hideFilter()}/>
  132. </BottomModal>
  133. </View>
  134. );
  135. }
  136. }
  137. const styles = StyleSheet.create({
  138. searchView: {
  139. alignItems: 'center',
  140. flexDirection: 'row',
  141. ...$padding(8, 16, 16),
  142. backgroundColor: colorThemes
  143. },
  144. searchInput: {
  145. flex: 1,
  146. alignItems: 'center',
  147. borderWidth: 1,
  148. borderStyle: 'solid',
  149. borderRadius: 60,
  150. borderColor: '#CCD0E7',
  151. flexDirection: 'row',
  152. paddingLeft: 16,
  153. paddingRight: 16,
  154. backgroundColor: 'rgba(255, 255, 255, 0.5)'
  155. },
  156. searchText: {
  157. flex: 1,
  158. color: '#444',
  159. padding: 8,
  160. fontSize: 15
  161. },
  162. mapIcon: {
  163. width: 32,
  164. height: 32,
  165. marginLeft: 16,
  166. alignItems: 'center',
  167. justifyContent: 'center',
  168. },
  169. mapToolView: {
  170. right: 24,
  171. zIndex: 10,
  172. bottom: 112,
  173. width: 56,
  174. position: 'absolute',
  175. alignItems: 'center'
  176. },
  177. bottomView: {
  178. left: 0,
  179. right: 0,
  180. bottom: 32,
  181. zIndex: 210,
  182. alignItems: 'center',
  183. position: 'absolute',
  184. },
  185. bottomButton: {
  186. elevation: 1.5,
  187. paddingLeft: 32,
  188. paddingRight: 32,
  189. borderRadius: 54,
  190. overflow: 'hidden',
  191. justifyContent: 'center'
  192. }
  193. })