Rating.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /**
  2. * 充电评价页面
  3. * @邠心vbe on 2021/04/30
  4. */
  5. import React from 'react';
  6. import { Image, ScrollView, StyleSheet, Text, TextInput, View } from 'react-native';
  7. import apiUser from '../../api/apiUser';
  8. import Button from '../../components/Button';
  9. import Dialog from '../../components/Dialog';
  10. import { PageList } from '../Router';
  11. export default class Rating extends React.Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. amenitiesNearby: 0,
  16. chargingExperience: 0,
  17. locationOfStation: 0,
  18. other: '',
  19. sitePk: 0,
  20. stationInfo: this.props.route.params
  21. }
  22. }
  23. componentDidMount() {
  24. if (this.state.stationInfo.id) {
  25. this.setState({
  26. sitePk: this.state.stationInfo.id
  27. });
  28. }
  29. }
  30. submit() {
  31. //console.log(this.state);
  32. if (this.state.locationOfStation == 0) {
  33. toastShort('Please rate \'Location of Station\'');
  34. return;
  35. }
  36. if (this.state.amenitiesNearby == 0) {
  37. toastShort('Please rate \'Amenities Nearby\'');
  38. return;
  39. }
  40. if (this.state.chargingExperience == 0) {
  41. toastShort('Please rate \'Charging Experience\'');
  42. return;
  43. }
  44. this.rating();
  45. }
  46. rating() {
  47. Dialog.showProgressDialog();
  48. apiUser.rateCharge(this.state).then(res => {
  49. Dialog.dismissLoading();
  50. startPage(PageList.home)
  51. }).catch((err) => {
  52. Dialog.dismissLoading();
  53. toastShort(err);
  54. });
  55. }
  56. render() {
  57. return (
  58. <ScrollView
  59. style={styles.container}
  60. keyboardShouldPersistTaps={'handled'}
  61. contentInsetAdjustmentBehavior={'automatic'}>
  62. <View style={styles.stationInfoView}>
  63. <Image
  64. style={styles.stationIcon}
  65. source={require('../../images/charge/icon-station-no.png')}/>
  66. <View style={styles.stationInfo}>
  67. <Text
  68. numberOfLines={1}
  69. ellipsizeMode={'tail'}
  70. style={styles.stationName}>{this.state.stationInfo?.name}</Text>
  71. <Text style={styles.stationAddress}>{this.state.stationInfo?.address}</Text>
  72. </View>
  73. </View>
  74. <View style={styles.ratingView}>
  75. <Text style={styles.ratingTitle}>Location of Station</Text>
  76. <StarView
  77. rating={this.state.locationOfStation}
  78. onChange={value => {
  79. this.setState({
  80. locationOfStation: value
  81. });
  82. }}
  83. />
  84. <Text style={styles.ratingTitle}>Amenities Nearby</Text>
  85. <StarView
  86. rating={this.state.amenitiesNearby}
  87. onChange={value => {
  88. this.setState({
  89. amenitiesNearby: value
  90. });
  91. }}
  92. />
  93. <Text style={styles.ratingTitle}>Charging Experience</Text>
  94. <StarView
  95. rating={this.state.chargingExperience}
  96. onChange={value => {
  97. this.setState({
  98. chargingExperience: value
  99. });
  100. }}
  101. />
  102. <Text style={styles.ratingTitle}>Others</Text>
  103. <TextInput
  104. style={styles.otherText}
  105. multiline={true}
  106. maxLength={500}
  107. numberOfLines={4}
  108. scrollEnabled={true}
  109. textAlignVertical='top'
  110. onChangeText={t => {
  111. this.setState({
  112. other: t
  113. });
  114. }}
  115. />
  116. </View>
  117. <Button
  118. style={styles.button}
  119. text='Submit Rating'
  120. onClick={() => {
  121. this.submit();
  122. }}
  123. />
  124. </ScrollView>
  125. );
  126. }
  127. }
  128. const StarView = ({rating, onChange}) => {
  129. const arr = [1,2,3,4,5];
  130. return (
  131. <View style={styles.starGroupView}>
  132. { arr.map((item, index) => {
  133. return (
  134. <AntDesign
  135. key={index}
  136. style={styles.starView}
  137. name={'star'}
  138. size={34}
  139. color={rating >= item ? colorAccent : '#eee'}
  140. onPress={() => {
  141. onChange(item);
  142. }}/>
  143. );
  144. })
  145. }
  146. </View>
  147. );
  148. }
  149. const styles = StyleSheet.create({
  150. container: {
  151. flex: 1
  152. },
  153. stationInfoView: {
  154. padding: 16,
  155. alignItems: 'center',
  156. flexDirection: 'row',
  157. backgroundColor: colorLight
  158. },
  159. stationIcon: {
  160. width: 40,
  161. height: 40
  162. },
  163. stationInfo: {
  164. flex: 1,
  165. paddingLeft: 16
  166. },
  167. stationName: {
  168. color: '#000',
  169. fontSize: 16
  170. },
  171. stationAddress: {
  172. color: '#999',
  173. fontSize: 12
  174. },
  175. ratingView: {
  176. padding: 16,
  177. marginTop: 16,
  178. backgroundColor: colorLight
  179. },
  180. ratingTitle: {
  181. color: '#000',
  182. fontSize: 14
  183. },
  184. starGroupView: {
  185. paddingTop: 16,
  186. paddingBottom: 20,
  187. alignItems: 'center',
  188. flexDirection: 'row'
  189. },
  190. starView: {
  191. marginRight: 10
  192. },
  193. otherText: {
  194. color: textPrimary,
  195. minHeight: 120,
  196. marginTop: 16,
  197. borderWidth: 1,
  198. borderColor: '#999',
  199. borderRadius: 6,
  200. paddingLeft: 10,
  201. paddingRight: 10,
  202. backgroundColor: '#F5F5F5'
  203. },
  204. button: {
  205. elevation: 1.5,
  206. marginTop: 32,
  207. marginLeft: 16,
  208. marginRight: 16,
  209. marginBottom: 32
  210. }
  211. });