AddVehicle.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**
  2. * Add Vehicle页面
  3. * @邠心vbe on 2021/05/08
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, Pressable, Image, TextInput } from 'react-native';
  7. import apiUser from '../../api/apiUser';
  8. import Dialog from '../../components/Dialog';
  9. import { TypeImageList } from '../charge/Charging';
  10. export default class AddVehicle extends Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. connectorIndex: 0,
  15. connectorType: TypeImageList
  16. };
  17. this.form = {}
  18. }
  19. selectConnector(index) {
  20. this.setState({
  21. connectorIndex: index
  22. });
  23. }
  24. validate() {
  25. if (!this.form.brand) {
  26. toastShort('Please type brand');
  27. return;
  28. }
  29. if (!this.form.model) {
  30. toastShort('Please type model');
  31. return;
  32. }
  33. if (!this.form.licensePlate) {
  34. toastShort('Please type license plate');
  35. return;
  36. }
  37. const params = this.form;
  38. params.connectorType = this.state.connectorType[this.state.connectorIndex].key
  39. this.addVehicle(params)
  40. }
  41. addVehicle(params) {
  42. Dialog.showProgressDialog();
  43. apiUser.addVehicle(params).then(res => {
  44. Dialog.dismissLoading();
  45. toastShort('Add vehicle successfully');
  46. goBack();
  47. }).catch(err => {
  48. Dialog.dismissLoading();
  49. toastShort(err);
  50. });
  51. }
  52. render() {
  53. return (
  54. <View style={styles.container}>
  55. <View style={styles.formView}>
  56. <Text style={styles.label}>Brand</Text>
  57. <TextInput
  58. style={styles.formInput}
  59. placeholder='Add text'
  60. maxLength={25}
  61. onChangeText={text => this.form.brand = text}
  62. />
  63. </View>
  64. <View style={styles.formView}>
  65. <Text style={styles.label}>Model</Text>
  66. <TextInput
  67. style={styles.formInput}
  68. placeholder='Add text'
  69. maxLength={50}
  70. onChangeText={text => this.form.model = text}
  71. />
  72. </View>
  73. <View style={styles.formView}>
  74. <Text style={styles.label}>License Plate</Text>
  75. <TextInput
  76. style={styles.formInput}
  77. placeholder='Add text'
  78. maxLength={20}
  79. onChangeText={text => this.form.licensePlate = text}
  80. />
  81. </View>
  82. <View style={styles.formView}>
  83. <Text style={styles.label}>Choose Connecter Type</Text>
  84. <View style={styles.connectorView}>
  85. { this.state.connectorType.map((item, index) => {
  86. return (
  87. <Pressable
  88. key={index}
  89. style={[
  90. styles.ctypeView,
  91. index==this.state.connectorIndex && styles.actived
  92. ]}
  93. onPress={() => {
  94. this.selectConnector(index);
  95. }}>
  96. <Image
  97. style={styles.typeIcon}
  98. source={item.icon}/>
  99. <Text style={styles.typeName}>{item.name}</Text>
  100. { index==this.state.connectorIndex &&
  101. <Image
  102. style={styles.checkedIcon}
  103. source={require('../../images/charge/charge-item-select.png')}/>
  104. }
  105. </Pressable>
  106. )
  107. })
  108. }
  109. </View>
  110. </View>
  111. <Text style={ui.flex1}></Text>
  112. <View style={styles.buttonView}>
  113. <Button
  114. text='Add Vehicle'
  115. elevation={1.5}
  116. onClick={() => {
  117. this.validate();
  118. }}/>
  119. </View>
  120. </View>
  121. );
  122. }
  123. }
  124. const styles = StyleSheet.create({
  125. container: {
  126. flex: 1,
  127. backgroundColor: 'white'
  128. },
  129. formView: {
  130. paddingTop: 16,
  131. paddingLeft: 16,
  132. paddingRight: 16,
  133. paddingBottom: 4
  134. },
  135. label: {
  136. color: '#333',
  137. fontSize: 14
  138. },
  139. formInput: {
  140. color: '#333',
  141. fontSize: 14,
  142. paddingBottom: 2,
  143. borderBottomColor: '#EEE',
  144. borderBottomWidth: 1
  145. },
  146. connectorView: {
  147. paddingTop: 16,
  148. alignItems: 'center',
  149. flexDirection: 'row'
  150. },
  151. ctypeView: {
  152. minWidth: 90,
  153. padding: 8,
  154. borderRadius: 6,
  155. marginRight: 16,
  156. marginBottom: 8,
  157. borderWidth: 1.5,
  158. borderColor: '#999',
  159. alignItems: 'center',
  160. textAlign: 'center'
  161. },
  162. typeIcon: {
  163. width: 38,
  164. height: 38
  165. },
  166. checkedIcon: {
  167. width: 12,
  168. height: 12,
  169. top: 4,
  170. right: 4,
  171. position: 'absolute',
  172. },
  173. actived: {
  174. borderColor: colorAccent
  175. },
  176. typeName: {
  177. color: '#000',
  178. fontSize: 15,
  179. textAlign: 'center',
  180. paddingTop: 8
  181. },
  182. buttonView: {
  183. padding: 16,
  184. marginBottom: 16
  185. },
  186. removeButton: {
  187. marginBottom: 16,
  188. backgroundColor: '#EF5B5B'
  189. }
  190. });
  191. export const VehicleStyles = styles