Bookmarks.js 6.3 KB

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