/** * Add Vehicle页面 * @邠心vbe on 2021/05/08 */ import React, { Component } from 'react'; import { View, Text, StyleSheet, Pressable, Image, TextInput } from 'react-native'; import apiUser from '../../api/apiUser'; import BadgeSelectItem from '../../components/BadgeSelectItem'; import Dialog from '../../components/Dialog'; import { TypeImageList } from '../charge/Charging'; export default class AddVehicle extends Component { constructor(props) { super(props); this.state = { connectorIndex: 0, connectorType: TypeImageList }; this.form = {} } selectConnector(index) { this.setState({ connectorIndex: index }); } validate() { if (!this.form.brand) { toastShort($t('profile.msgInputBrand')); return; } if (!this.form.model) { toastShort($t('profile.msgInputModel')); return; } if (!this.form.licensePlate) { toastShort($t('profile.msgInputPlate')); return; } const params = this.form; params.connectorType = this.state.connectorType[this.state.connectorIndex].key this.addVehicle(params) } addVehicle(params) { Dialog.showProgressDialog(); apiUser.addVehicle(params).then(res => { Dialog.dismissLoading(); toastShort($t('common.addSuccess')); goBack(); }).catch((err) => { Dialog.dismissLoading(); toastShort(err); }); } render() { return ( {$t('profile.vehicleBrand')} this.form.brand = text} /> {$t('profile.vehicleModel')} this.form.model = text} /> {$t('profile.licensePlate')} this.form.licensePlate = text} /> {$t('profile.chooseConnecterType')} { this.state.connectorType.map((item, index) => { return ( this.selectConnector(index)}> {item.nameScope ? $t(item.nameScope) : item.name} {/* index==this.state.connectorIndex && */} ) }) }