/** * Feedback 页面 * @邠心vbe on 2021/04/28 */ import React from 'react'; import { View, Text, StyleSheet, ScrollView, TextInput, Image, Pressable } from 'react-native'; import Button from '../../components/Button'; import apiUpload from '../../api/apiUpload'; import { host } from '../../api/http'; import apiUser from '../../api/apiUser'; import Dialog from '../../components/Dialog'; import ImagePicker from 'react-native-image-crop-picker'; import Dropdown from '../../components/Dropdown'; import { UploadThemes } from '../../components/ThemesConfig'; 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: '', typeOfFeedback: '', imageUrl: ['', '', ''] } } 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(); } }); } noTypeDialog() { setTimeout(() => { if (this.pageShow) { Dialog.showResultDialog('Can not fetch feedback type!', 'OK', back => { goBack(); }); } }, 500); } 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 }); } else { toastShort('Upload failed, please retry'); } }).catch(err => { toastShort(err); }); } }).catch(err => { //console.log(err); }); } submitFeedback() { if (this.state.typeOfFeedback == '') { toastShort('Please select type of feedback'); return; } if (this.state.feedback == '') { toastShort('Please type feedback content'); 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] } Dialog.showProgressDialog(); apiUser.feedback(params).then(res => { Dialog.dismissLoading(); Dialog.showResultDialog('Send feedback successfully!', 'OK', back => { goBack(); }); }).catch(err => { Dialog.dismissLoading(); toastShort(err); }); } render() { return ( Have something to tell us? Please let us know below! Type of Feedback { this.setState({ typeOfFeedback: value }) }}/> Please fill in here (500 words) { this.setState({ feedback: text }); }}/> { this.state.imageUrl.map((item, index) => { return ( { this.uploadImage(index) }}> { item == '' ? : } ); }) }