AddVehicle.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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($t('profile.msgInputBrand'));
  28. return;
  29. }
  30. if (!this.form.model) {
  31. toastShort($t('profile.msgInputModel'));
  32. return;
  33. }
  34. if (!this.form.licensePlate) {
  35. toastShort($t('profile.msgInputPlate'));
  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($t('common.addSuccess'));
  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}>{$t('profile.vehicleBrand')}</Text>
  58. <TextInput
  59. style={styles.formInput}
  60. allowFontScaling={false}
  61. placeholder={$t('common.inputAddText')}
  62. maxLength={25}
  63. placeholderTextColor={textPlacehoder}
  64. onChangeText={text => this.form.brand = text}
  65. />
  66. </View>
  67. <View style={styles.formView}>
  68. <Text style={styles.label}>{$t('profile.vehicleModel')}</Text>
  69. <TextInput
  70. style={styles.formInput}
  71. allowFontScaling={false}
  72. placeholder={$t('common.inputAddText')}
  73. maxLength={50}
  74. placeholderTextColor={textPlacehoder}
  75. onChangeText={text => this.form.model = text}
  76. />
  77. </View>
  78. <View style={styles.formView}>
  79. <Text style={styles.label}>{$t('profile.licensePlate')}</Text>
  80. <TextInput
  81. style={styles.formInput}
  82. placeholder={$t('common.inputAddText')}
  83. maxLength={20}
  84. placeholderTextColor={textPlacehoder}
  85. onChangeText={text => this.form.licensePlate = text}
  86. />
  87. </View>
  88. <View style={styles.formView}>
  89. <Text style={styles.label}>{$t('profile.chooseConnecterType')}</Text>
  90. <View style={styles.connectorView}>
  91. { this.state.connectorType.map((item, index) => {
  92. return (
  93. <BadgeSelectItem
  94. key={index}
  95. style={styles.ctypeView}
  96. borderColor={textCancel}
  97. checked={index==this.state.connectorIndex}
  98. onPress={() => this.selectConnector(index)}>
  99. <Image
  100. style={styles.typeIcon}
  101. source={item.icon}/>
  102. <Text style={styles.typeName}>{item.nameScope ? $t(item.nameScope) : item.name}</Text>
  103. {/* index==this.state.connectorIndex &&
  104. <View style={styles.checkedIcon}>
  105. <ChargeItemSelect size={12} selected={true}/>
  106. </View>
  107. */}
  108. </BadgeSelectItem>
  109. )
  110. })
  111. }
  112. </View>
  113. </View>
  114. <Text style={ui.flex1}></Text>
  115. <View style={styles.buttonView}>
  116. <Button
  117. text={$t('profile.addVehicle')}
  118. elevation={1.5}
  119. onClick={() => {
  120. this.validate();
  121. }}/>
  122. </View>
  123. </View>
  124. );
  125. }
  126. }
  127. const styles = StyleSheet.create({
  128. container: {
  129. flex: 1,
  130. backgroundColor: pageBackground
  131. },
  132. formView: {
  133. paddingTop: 16,
  134. paddingLeft: 16,
  135. paddingRight: 16,
  136. paddingBottom: 4
  137. },
  138. label: {
  139. color: textPrimary,
  140. fontSize: 14
  141. },
  142. formInput: {
  143. color: textPrimary,
  144. fontSize: 14,
  145. height: 42,
  146. paddingBottom: 2,
  147. borderBottomColor: '#EEE',
  148. borderBottomWidth: 1
  149. },
  150. connectorView: {
  151. paddingTop: 16,
  152. alignItems: 'center',
  153. flexDirection: 'row'
  154. },
  155. ctypeView: {
  156. minWidth: 90,
  157. padding: 8,
  158. borderRadius: 6,
  159. marginRight: 16,
  160. marginBottom: 8,
  161. borderWidth: 1.5,
  162. alignItems: 'center',
  163. textAlign: 'center'
  164. },
  165. typeIcon: {
  166. width: 38,
  167. height: 38
  168. },
  169. checkedIcon: {
  170. width: 12,
  171. height: 12,
  172. top: 4,
  173. right: 4,
  174. position: 'absolute',
  175. },
  176. actived: {
  177. borderColor: colorAccent
  178. },
  179. typeName: {
  180. color: '#000',
  181. fontSize: 15,
  182. textAlign: 'center',
  183. paddingTop: 8
  184. },
  185. buttonView: {
  186. padding: 16,
  187. marginBottom: 16
  188. },
  189. removeButton: {
  190. marginBottom: 16,
  191. backgroundColor: '#EF5B5B'
  192. }
  193. });
  194. export const VehicleStyles = styles