SiteInfo.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Site Information页面
  3. * @邠心vbe on 2021/07/06
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet } from 'react-native';
  7. export default class SiteInfo extends Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. refreshId: 0,
  12. stationInfo: {}
  13. };
  14. }
  15. componentDidMount() {
  16. if (this.props.stationInfo) {
  17. this.setState({
  18. stationInfo: this.props.stationInfo
  19. });
  20. }
  21. }
  22. componentDidUpdate() {
  23. if (this.props.refreshId != this.state.refreshId) {
  24. this.setState({
  25. refreshId: this.props.refreshId,
  26. stationInfo: this.props.stationInfo
  27. });
  28. }
  29. }
  30. getOperatingHours() {
  31. if (this.state.stationInfo.endlessService) {
  32. return "24/7";
  33. } else if (this.state.stationInfo.operatingHours) {
  34. return this.state.stationInfo.operatingHours;
  35. } else {
  36. return 'To be updated';
  37. }
  38. }
  39. getParkingFee() {
  40. if (this.state.stationInfo.parkingFeeFree) {
  41. return "Free";
  42. } else if (this.state.stationInfo.parkingFee) {
  43. return this.state.stationInfo.parkingFee;
  44. } else {
  45. return 'To be updated';
  46. }
  47. }
  48. render() {
  49. return (
  50. <View style={{
  51. paddingLeft: 16,
  52. paddingRight: 16,
  53. ...(this.props.style || {})
  54. }}>
  55. <Text style={styles.title}>Address</Text>
  56. <View style={styles.infoView}>
  57. <Text style={styles.infoText}>{this.state.stationInfo.address}</Text>
  58. </View>
  59. <Text style={styles.title}>Operating Hours</Text>
  60. <View style={styles.infoView}>
  61. <Text style={styles.infoText}>{this.getOperatingHours()}</Text>
  62. </View>
  63. <Text style={styles.title}>Parking Fee</Text>
  64. <View style={styles.infoView}>
  65. <Text style={styles.infoText}>{this.getParkingFee()}</Text>
  66. </View>
  67. <Text style={styles.title}>Additional Information</Text>
  68. <View style={styles.infoView}>
  69. <Text style={styles.infoText}>{this.state.stationInfo.additionalNotes}</Text>
  70. </View>
  71. </View>
  72. );
  73. }
  74. }
  75. const styles = StyleSheet.create({
  76. title: {
  77. color: '#000',
  78. fontSize: 14,
  79. fontWeight: 'bold',
  80. ...$padding(16, 0, 8),
  81. borderBottomColor: '#eee',
  82. borderBottomWidth: 1
  83. },
  84. infoView: {
  85. paddingTop: 8,
  86. paddingBottom: 16
  87. },
  88. infoText: {
  89. color: '#444',
  90. fontSize: 14
  91. }
  92. })