/** * 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 Dialog from '../../components/Dialog'; import ChargeItemSelect from '../../icons/ChargeItemSelect'; 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('Please type brand'); return; } if (!this.form.model) { toastShort('Please type model'); return; } if (!this.form.licensePlate) { toastShort('Please type license plate'); 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('Add vehicle successfully'); goBack(); }).catch(err => { Dialog.dismissLoading(); toastShort(err); }); } render() { return ( Brand this.form.brand = text} /> Model this.form.model = text} /> License Plate this.form.licensePlate = text} /> Choose Connecter Type { this.state.connectorType.map((item, index) => { return ( { this.selectConnector(index); }}> {item.name} { index==this.state.connectorIndex && } ) }) }