AddVehicle.js 4.8 KB

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