/** * Feedback 页面 * @邠心vbe on 2021/04/28 */ import React from 'react'; import { View, Text, StyleSheet, ScrollView, TextInput, Image, Pressable, FlatList } from 'react-native'; import Button from '../../components/Button'; import apiUpload from '../../api/apiUpload'; import apiUser from '../../api/apiUser'; import Dialog from '../../components/Dialog'; import ImagePicker from 'react-native-image-crop-picker'; import Dropdown from '../../components/Dropdown'; import Modal from 'react-native-modal'; import { UploadThemes } from '../../components/ThemesConfig'; import apiBase from '../../api/apiBase.js'; import utils from '../../utils/utils'; import MyModal from '../../components/MyModal'; import VbeSkeleton from '../../components/VbeSkeleton'; const options = { cropping: false, multiple: false, minFiles: 1, maxFiles: 3, mediaType: 'photo', writeTempFile: false, compressImageQuality: 0.8, compressImageMaxWidth: 720, compressImageMaxHeight: 1280, ...UploadThemes } export default class Feedback extends React.Component { constructor(props) { super(props); this.state= { typeList: [], feedback: '', searchId: '', connectorId: '', chargeBoxId: '', typeOfFeedback: '', imageUrl: ['', '', ''], chargeBoxList: [], connectorList: [], showDialog: false, searching: false } } componentDidMount() { this.pageShow = true; this.props.navigation.addListener('blur', () => { this.pageShow = false; }); apiUser.getTypeOfFeedback().then(res => { if (res.success && res.data.length > 0) { this.setState({ typeList: res.data }); } else { if (this.pageShow) { this.noTypeDialog(); } } }).catch(err => { if (this.pageShow) { this.noTypeDialog(); } }); this.getChargeBox(""); } noTypeDialog() { setTimeout(() => { if (this.pageShow) { Dialog.showResultDialog($t('feedback.errFetchType'), $t('nav.ok'), back => { goBack(); }); } }, 500); } changeType(type, index) { this.setState({ typeOfFeedback: type }) } listChargeBox(searchId) { this.setState({ searching: true, searchId: searchId }, () => { setTimeout(() => { this.getChargeBox(searchId) }, 300); }); } getChargeBox(searchId) { if (searchId != this.state.searchId) { return; } apiBase.listChargeBox(this.state.searchId).then(res => { if (res.data) { this.setState({ chargeBoxList: res.data, searching: false }) } else { this.setState({ chargeBoxList: [], searching: false, connectorId: "" }) } }).catch(err => { this.setState({ chargeBoxList: [], searching: false, connectorId: "" }) }) } listConnector() { //Dialog.showProgressDialog() apiBase.listConnector(this.state.chargeBoxId).then(res => { if (res.data) { this.setState({ connectorList: res.data }) } else { this.setState({ connectorList: [] }) } }).catch(err => { this.setState({ connectorList: [] }) }) } uploadImage(index) { ImagePicker.openPicker(options).then(image => { if (image.path) { apiUpload.uploadImage(image.path, image.mime, 'FEEDBACK').then(res => { if (res.success && res.data.picturePath) { let imageUrl = this.state.imageUrl; imageUrl[index] = res.data.picturePath; this.setState({ imageUrl: imageUrl }); toastShort($t('common.uploadSuccess')); } else { toastShort($t('common.uploadFailed')); } }).catch(err => { toastShort(err); }); } }).catch(err => { //console.log(err); }); } submitFeedback() { if (this.state.typeOfFeedback == '') { toastShort($t('feedback.errFeedbackType')); return; } if (this.state.feedback == '') { toastShort($t('feedback.errFeednackContent')); return; } const params = { "typeOfFeedback": this.state.typeOfFeedback, "feedback": this.state.feedback, "feedbackImgOne": this.state.imageUrl[0], "feedbackImgTwo": this.state.imageUrl[1], "feedbackImgThree": this.state.imageUrl[2], "chargeBoxId": this.state.chargeBoxId, "connectorId": this.state.connectorId } Dialog.showProgressDialog(); apiUser.feedback(params).then(res => { Dialog.dismissLoading(); Dialog.showResultDialog($t('feedback.sendSuccess'), $t('nav.ok'), back => { goBack(); }); }).catch(err => { Dialog.dismissLoading(); toastShort(err); }); } changeChargeBox(id) { if (id) { this.setState({ showDialog: false, chargeBoxId: id }, () => this.listConnector()) } else { this.setState({ showDialog: false }) } } changeConnector(id) { this.setState({ connectorId: id }) } render() { return ( {$t('feedback.tipsSomething')} {$t('feedback.tipsLetKnow')} {$t('feedback.typeOfFeedback')} this.changeType(value, index)}/> {$t('feedback.labelContent')} { this.setState({ feedback: text }); }}/> {$t('feedback.labelUpload')} { this.state.imageUrl.map((item, index) => { return ( { this.uploadImage(index) }}> { item == '' ? : } ); }) } {this.state.typeOfFeedback == "csf" && <> {$t('feedback.labelStation')} {$t('feedback.labelConnector')} this.changeConnector(value)}/> }