Bookmarks.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /**
  2. * 充电桩收藏页
  3. * @邠心vbe on 2023/06/28
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, TextInput, FlatList, Image, RefreshControl } from 'react-native';
  7. import apiStation from '../../api/apiStation';
  8. import Dialog from '../../components/Dialog';
  9. import { MyRefreshProps } from '../../components/ThemesConfig';
  10. import utils from '../../utils/utils';
  11. import { PageList } from '../Router';
  12. import ListViewV2 from '../search/ListViewV2';
  13. export default class Bookmarks extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. isSearch: false,
  18. searchResult: [{id:0}],
  19. latlng: {
  20. lat: 0.00001,
  21. lng: 0.00001
  22. }
  23. };
  24. }
  25. componentDidMount() {
  26. this.getGeoLocation();
  27. }
  28. refreshList() {
  29. this.setState({
  30. isSearch: true
  31. });
  32. this.getGeoLocation();
  33. }
  34. getGeoLocation() {
  35. navigator.geolocation.getCurrentPosition(location => {
  36. let latlng = {
  37. lat: location.coords.latitude,
  38. lng: location.coords.longitude
  39. }
  40. this.setState({
  41. latlng: latlng
  42. })
  43. this.searchStation(latlng);
  44. }, error => {
  45. console.info("[Search] getGeoLocation", error);
  46. this.searchStation(this.state.latlng);
  47. });
  48. }
  49. searchStation(latlng, time=500) {
  50. this.setState({
  51. isSearch: true
  52. });
  53. //latlng.siteName = this.searchWorld
  54. apiStation.getBookmarkList(latlng).then(res => {
  55. if (res.data.sites) {
  56. const list = [];
  57. res.data.sites.forEach(item => {
  58. list.push({
  59. id: item.sitePk,
  60. name: item.siteName,
  61. address: item.siteAddress,
  62. latitude: item.locationLatitude,
  63. longitude: item.locationLongitude,
  64. acConnector: item.acConnector,
  65. allConnector: item.allConnector,
  66. dcConnector: item.dcConnector,
  67. siteType: item.siteType,
  68. favorite: item.favorite,
  69. distance: utils.getDistance(item.distance),
  70. serviceProvider: item.serviceProvider
  71. });
  72. });
  73. //setTimeout(() => {
  74. this.setState({
  75. isSearch: false,
  76. searchResult: list
  77. });
  78. //}, time);
  79. }
  80. }).catch(err => {
  81. console.log('searchStation-err', err);
  82. this.setState({
  83. isSearch: false,
  84. searchResult: []
  85. });
  86. });
  87. }
  88. favoriteSite(info) {
  89. if (info?.id) {
  90. Dialog.showProgressDialog();
  91. apiStation.bookmarkSite(info.id).then(res => {
  92. this.searchStation(this.state.latlng);
  93. }).catch(err => {
  94. toastShort(err);
  95. }).finally(() => {
  96. Dialog.dismissLoading();
  97. })
  98. }
  99. }
  100. intoStation(info) {
  101. startPage(PageList.chargeDetailPage, {stationInfo: info, action: "bookmarks"});
  102. }
  103. listItem = (props) => {
  104. return (
  105. <ListViewV2
  106. {...props}
  107. onPress={() => this.intoStation(props.item)}
  108. onFavorite={() => this.favoriteSite(props.item)}/>
  109. )
  110. }
  111. render() {
  112. return (
  113. <View style={styles.container}>
  114. {/* <View style={styles.searchView}>
  115. <Feather
  116. name={'search'}
  117. size={20}
  118. color={'#999'}/>
  119. <TextInput
  120. style={styles.searchInput}
  121. autoFocus={true}
  122. maxLength={50}
  123. numberOfLines={1}
  124. returnKeyType={'search'}
  125. clearButtonMode={'while-editing'}
  126. placeholder={$t('home.searchHint')}
  127. placeholderTextColor={textPlacehoder}
  128. onChangeText={text => {
  129. this.searchWorld = text;
  130. }}
  131. onSubmitEditing={() => {
  132. //this.getGeoLocation();
  133. this.searchStation(this.state.latlng, 1000);
  134. }}/>
  135. </View> */}
  136. <FlatList
  137. style={styles.listView}
  138. data={this.state.searchResult}
  139. renderItem={this.listItem}
  140. keyExtractor={item => item.id}
  141. keyboardShouldPersistTaps="always"
  142. ListEmptyComponent={<Text style={styles.noResult} allowFontScaling={false}>{$t('home.noSearch')}</Text>}
  143. refreshControl={
  144. <RefreshControl
  145. {...MyRefreshProps()}
  146. refreshing={this.state.isSearch}
  147. onRefresh={() => this.refreshList()}
  148. />
  149. }
  150. />
  151. </View>
  152. );
  153. }
  154. }
  155. const styles = StyleSheet.create({
  156. container: {
  157. flex: 1,
  158. backgroundColor: pageBackground
  159. },
  160. searchView: {
  161. marginTop: 16,
  162. marginLeft: 16,
  163. marginRight: 16,
  164. marginBottom: 8,
  165. paddingLeft: 16,
  166. paddingRight: 16,
  167. borderRadius: 60,
  168. borderWidth: 1,
  169. borderColor: '#E5E5E5',
  170. alignItems: 'center',
  171. flexDirection: 'row',
  172. backgroundColor: '#F5F5F5'
  173. },
  174. searchInput: {
  175. flex: 1,
  176. color: textPrimary,
  177. ...$padding(6, 8),
  178. fontSize: 15,
  179. marginLeft: 4,
  180. lineHeight: 20
  181. },
  182. searchingView: {
  183. padding: 16,
  184. alignItems: 'center'
  185. },
  186. seachingIcon: {
  187. width: 60,
  188. height: 60
  189. },
  190. noResult: {
  191. color: '#999',
  192. fontSize: 14,
  193. padding: 20,
  194. textAlign: 'center',
  195. },
  196. listView: {
  197. flex: 1
  198. },
  199. itemView: {
  200. alignItems: 'center',
  201. flexDirection: 'row',
  202. borderBottomWidth: 1,
  203. borderBottomColor: '#eee'
  204. },
  205. stationInfo: {
  206. flex: 1,
  207. padding: 16
  208. },
  209. nameView: {
  210. paddingTop: 3,
  211. alignItems: 'center',
  212. flexDirection: 'row'
  213. },
  214. stationName: {
  215. color: textPrimary,
  216. fontSize: 18,
  217. fontWeight: 'bold'
  218. },
  219. stationAddress: {
  220. color: '#666',
  221. fontSize: 14,
  222. paddingBottom: 8
  223. },
  224. infoStatus: {
  225. fontSize: 10,
  226. paddingTop: 3,
  227. paddingLeft: 8,
  228. paddingRight: 8,
  229. paddingBottom: 3,
  230. borderRadius: 5,
  231. marginLeft: 12,
  232. },
  233. selected: {
  234. color: textPrimary,
  235. backgroundColor: colorAccent
  236. },
  237. available: {
  238. color: textLight,
  239. backgroundColor: '#90DB0A'
  240. },
  241. unavailable: {
  242. color: '#999',
  243. fontSize: 10.5,
  244. paddingTop: 7,
  245. paddingLeft: 9,
  246. paddingRight: 9,
  247. paddingBottom: 7,
  248. backgroundColor: '#CCC'
  249. },
  250. connectView: {
  251. paddingTop: 4,
  252. paddingBottom: 4,
  253. alignItems: 'center',
  254. flexDirection: 'row'
  255. }
  256. });