Bookmarks.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. upcoming: item.upcoming,
  70. labels: item.labels,
  71. distance: utils.getDistance(item.distance),
  72. serviceProvider: item.serviceProvider
  73. });
  74. });
  75. //setTimeout(() => {
  76. this.setState({
  77. isSearch: false,
  78. searchResult: list
  79. });
  80. //}, time);
  81. }
  82. }).catch(err => {
  83. console.log('searchStation-err', err);
  84. this.setState({
  85. isSearch: false,
  86. searchResult: []
  87. });
  88. });
  89. }
  90. favoriteSite(info) {
  91. if (info?.id) {
  92. Dialog.showProgressDialog();
  93. apiStation.bookmarkSite(info.id).then(res => {
  94. this.searchStation(this.state.latlng);
  95. }).catch(err => {
  96. toastShort(err);
  97. }).finally(() => {
  98. Dialog.dismissLoading();
  99. })
  100. }
  101. }
  102. intoStation(info) {
  103. if (info.upcoming) {
  104. toastShort($t("home.upcoming"))
  105. } else {
  106. startPage(PageList.chargeDetailPage, {stationInfo: info, action: "bookmarks"});
  107. }
  108. }
  109. listItem = (props) => {
  110. return (
  111. <ListViewV2
  112. {...props}
  113. onPress={() => this.intoStation(props.item)}
  114. onFavorite={() => this.favoriteSite(props.item)}/>
  115. )
  116. }
  117. render() {
  118. return (
  119. <View style={styles.container}>
  120. {/* <View style={styles.searchView}>
  121. <Feather
  122. name={'search'}
  123. size={20}
  124. color={'#999'}/>
  125. <TextInput
  126. style={styles.searchInput}
  127. autoFocus={true}
  128. maxLength={50}
  129. numberOfLines={1}
  130. returnKeyType={'search'}
  131. clearButtonMode={'while-editing'}
  132. placeholder={$t('home.searchHint')}
  133. placeholderTextColor={textPlacehoder}
  134. onChangeText={text => {
  135. this.searchWorld = text;
  136. }}
  137. onSubmitEditing={() => {
  138. //this.getGeoLocation();
  139. this.searchStation(this.state.latlng, 1000);
  140. }}/>
  141. </View> */}
  142. <FlatList
  143. style={styles.listView}
  144. data={this.state.searchResult}
  145. renderItem={this.listItem}
  146. keyExtractor={item => item.id}
  147. keyboardShouldPersistTaps="always"
  148. ListEmptyComponent={<Text style={styles.noResult} allowFontScaling={false}>{$t('home.noSearch')}</Text>}
  149. refreshControl={
  150. <RefreshControl
  151. {...MyRefreshProps()}
  152. refreshing={this.state.isSearch}
  153. onRefresh={() => this.refreshList()}
  154. />
  155. }
  156. />
  157. </View>
  158. );
  159. }
  160. }
  161. const styles = StyleSheet.create({
  162. container: {
  163. flex: 1,
  164. backgroundColor: pageBackground
  165. },
  166. searchView: {
  167. marginTop: 16,
  168. marginLeft: 16,
  169. marginRight: 16,
  170. marginBottom: 8,
  171. paddingLeft: 16,
  172. paddingRight: 16,
  173. borderRadius: 60,
  174. borderWidth: 1,
  175. borderColor: '#E5E5E5',
  176. alignItems: 'center',
  177. flexDirection: 'row',
  178. backgroundColor: '#F5F5F5'
  179. },
  180. searchInput: {
  181. flex: 1,
  182. color: textPrimary,
  183. ...$padding(6, 8),
  184. fontSize: 15,
  185. marginLeft: 4,
  186. lineHeight: 20
  187. },
  188. searchingView: {
  189. padding: 16,
  190. alignItems: 'center'
  191. },
  192. seachingIcon: {
  193. width: 60,
  194. height: 60
  195. },
  196. noResult: {
  197. color: '#999',
  198. fontSize: 14,
  199. padding: 20,
  200. textAlign: 'center',
  201. },
  202. listView: {
  203. flex: 1
  204. },
  205. itemView: {
  206. alignItems: 'center',
  207. flexDirection: 'row',
  208. borderBottomWidth: 1,
  209. borderBottomColor: '#eee'
  210. },
  211. stationInfo: {
  212. flex: 1,
  213. padding: 16
  214. },
  215. nameView: {
  216. paddingTop: 3,
  217. alignItems: 'center',
  218. flexDirection: 'row'
  219. },
  220. stationName: {
  221. color: textPrimary,
  222. fontSize: 18,
  223. fontWeight: 'bold'
  224. },
  225. stationAddress: {
  226. color: '#666',
  227. fontSize: 14,
  228. paddingBottom: 8
  229. },
  230. infoStatus: {
  231. fontSize: 10,
  232. paddingTop: 3,
  233. paddingLeft: 8,
  234. paddingRight: 8,
  235. paddingBottom: 3,
  236. borderRadius: 5,
  237. marginLeft: 12,
  238. },
  239. selected: {
  240. color: textPrimary,
  241. backgroundColor: colorAccent
  242. },
  243. available: {
  244. color: textLight,
  245. backgroundColor: '#90DB0A'
  246. },
  247. unavailable: {
  248. color: '#999',
  249. fontSize: 10.5,
  250. paddingTop: 7,
  251. paddingLeft: 9,
  252. paddingRight: 9,
  253. paddingBottom: 7,
  254. backgroundColor: '#CCC'
  255. },
  256. connectView: {
  257. paddingTop: 4,
  258. paddingBottom: 4,
  259. alignItems: 'center',
  260. flexDirection: 'row'
  261. }
  262. });