AddVehicle.js 4.9 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 BadgeSelectItem from '../../components/BadgeSelectItem';
  9. import Dialog from '../../components/Dialog';
  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. placeholderTextColor={textPlacehoder}
  62. maxLength={25}
  63. onChangeText={text => this.form.brand = text}
  64. />
  65. </View>
  66. <View style={styles.formView}>
  67. <Text style={styles.label}>Model</Text>
  68. <TextInput
  69. style={styles.formInput}
  70. placeholder='Add text'
  71. placeholderTextColor={textPlacehoder}
  72. maxLength={50}
  73. onChangeText={text => this.form.model = text}
  74. />
  75. </View>
  76. <View style={styles.formView}>
  77. <Text style={styles.label}>License Plate</Text>
  78. <TextInput
  79. style={styles.formInput}
  80. placeholder='Add text'
  81. placeholderTextColor={textPlacehoder}
  82. maxLength={20}
  83. onChangeText={text => this.form.licensePlate = text}
  84. />
  85. </View>
  86. <View style={styles.formView}>
  87. <Text style={styles.label}>Choose Connecter Type</Text>
  88. <View style={styles.connectorView}>
  89. { this.state.connectorType.map((item, index) => {
  90. return (
  91. <BadgeSelectItem
  92. key={index}
  93. style={styles.ctypeView}
  94. borderColor={textCancel}
  95. checked={index==this.state.connectorIndex}
  96. onPress={() => this.selectConnector(index)}>
  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. </BadgeSelectItem>
  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: pageBackground
  129. },
  130. formView: {
  131. paddingTop: 16,
  132. paddingLeft: 16,
  133. paddingRight: 16,
  134. paddingBottom: 4
  135. },
  136. label: {
  137. color: textPrimary,
  138. fontSize: 14
  139. },
  140. formInput: {
  141. color: textPrimary,
  142. fontSize: 14,
  143. height: 42,
  144. paddingBottom: 2,
  145. borderBottomColor: '#EEE',
  146. borderBottomWidth: 1
  147. },
  148. connectorView: {
  149. paddingTop: 16,
  150. alignItems: 'center',
  151. flexDirection: 'row'
  152. },
  153. ctypeView: {
  154. minWidth: 90,
  155. padding: 8,
  156. borderRadius: 6,
  157. marginRight: 16,
  158. marginBottom: 8,
  159. borderWidth: 1.5,
  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