AddVehicle.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. 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. <BadgeSelectItem
  89. key={index}
  90. style={styles.ctypeView}
  91. borderColor={textCancel}
  92. checked={index==this.state.connectorIndex}
  93. onPress={() => this.selectConnector(index)}>
  94. <Image
  95. style={styles.typeIcon}
  96. source={item.icon}/>
  97. <Text style={styles.typeName}>{item.name}</Text>
  98. {/* index==this.state.connectorIndex &&
  99. <View style={styles.checkedIcon}>
  100. <ChargeItemSelect size={12} selected={true}/>
  101. </View>
  102. */}
  103. </BadgeSelectItem>
  104. )
  105. })
  106. }
  107. </View>
  108. </View>
  109. <Text style={ui.flex1}></Text>
  110. <View style={styles.buttonView}>
  111. <Button
  112. text='Add Vehicle'
  113. elevation={1.5}
  114. onClick={() => {
  115. this.validate();
  116. }}/>
  117. </View>
  118. </View>
  119. );
  120. }
  121. }
  122. const styles = StyleSheet.create({
  123. container: {
  124. flex: 1,
  125. backgroundColor: pageBackground
  126. },
  127. formView: {
  128. paddingTop: 16,
  129. paddingLeft: 16,
  130. paddingRight: 16,
  131. paddingBottom: 4
  132. },
  133. label: {
  134. color: textPrimary,
  135. fontSize: 14
  136. },
  137. formInput: {
  138. color: textPrimary,
  139. fontSize: 14,
  140. height: 42,
  141. paddingBottom: 2,
  142. borderBottomColor: '#EEE',
  143. borderBottomWidth: 1
  144. },
  145. connectorView: {
  146. paddingTop: 16,
  147. alignItems: 'center',
  148. flexDirection: 'row'
  149. },
  150. ctypeView: {
  151. minWidth: 90,
  152. padding: 8,
  153. borderRadius: 6,
  154. marginRight: 16,
  155. marginBottom: 8,
  156. borderWidth: 1.5,
  157. alignItems: 'center',
  158. textAlign: 'center'
  159. },
  160. typeIcon: {
  161. width: 38,
  162. height: 38
  163. },
  164. checkedIcon: {
  165. width: 12,
  166. height: 12,
  167. top: 4,
  168. right: 4,
  169. position: 'absolute',
  170. },
  171. actived: {
  172. borderColor: colorAccent
  173. },
  174. typeName: {
  175. color: '#000',
  176. fontSize: 15,
  177. textAlign: 'center',
  178. paddingTop: 8
  179. },
  180. buttonView: {
  181. padding: 16,
  182. marginBottom: 16
  183. },
  184. removeButton: {
  185. marginBottom: 16,
  186. backgroundColor: '#EF5B5B'
  187. }
  188. });
  189. export const VehicleStyles = styles