Feedback.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /**
  2. * Feedback 页面
  3. * @邠心vbe on 2021/04/28
  4. */
  5. import React from 'react';
  6. import { View, Text, StyleSheet, ScrollView, TextInput, Image, Pressable } from 'react-native';
  7. import Button from '../../components/Button';
  8. import apiUpload from '../../api/apiUpload';
  9. import { host } from '../../api/http';
  10. import apiUser from '../../api/apiUser';
  11. import Dialog from '../../components/Dialog';
  12. import ImagePicker from 'react-native-image-crop-picker';
  13. import Dropdown from '../../components/Dropdown';
  14. const options = {
  15. cropping: false,
  16. multiple: false,
  17. minFiles: 1,
  18. maxFiles: 3,
  19. mediaType: 'photo',
  20. writeTempFile: false,
  21. compressImageQuality: 0.8,
  22. compressImageMaxWidth: 720,
  23. compressImageMaxHeight: 1280,
  24. cropperStatusBarColor: colorAccent,
  25. cropperToolbarColor: colorAccent,
  26. cropperActiveWidgetColor: colorAccent
  27. }
  28. export default class Feedback extends React.Component {
  29. constructor(props) {
  30. super(props);
  31. this.state= {
  32. typeList: [],
  33. feedback: '',
  34. typeOfFeedback: '',
  35. imageUrl: ['', '', '']
  36. }
  37. }
  38. componentDidMount() {
  39. this.pageShow = true;
  40. this.props.navigation.addListener('blur', () => {
  41. this.pageShow = false;
  42. console.log('blur', this.pageShow);
  43. });
  44. apiUser.getTypeOfFeedback().then(res => {
  45. if (res.success && res.data.length > 0) {
  46. this.setState({
  47. typeList: res.data
  48. });
  49. } else {
  50. if (this.pageShow) {
  51. this.noTypeDialog();
  52. }
  53. }
  54. }).catch(err => {
  55. if (this.pageShow) {
  56. this.noTypeDialog();
  57. }
  58. });
  59. }
  60. noTypeDialog() {
  61. setTimeout(() => {
  62. if (this.pageShow) {
  63. Dialog.showResultDialog('Can not fetch feedback type!', 'OK', back => {
  64. goBack();
  65. });
  66. }
  67. }, 500);
  68. }
  69. uploadImage(index) {
  70. ImagePicker.openPicker(options).then(image => {
  71. if (image.path) {
  72. apiUpload.uploadImage(image.path, image.mime, 'FEEDBACK').then(res => {
  73. if (res.success && res.data.picturePath) {
  74. let imageUrl = this.state.imageUrl;
  75. imageUrl[index] = res.data.picturePath;
  76. this.setState({
  77. imageUrl: imageUrl
  78. });
  79. } else {
  80. toastShort('Upload failed, please retry');
  81. }
  82. }).catch(err => {
  83. toastShort(err);
  84. });
  85. }
  86. }).catch(err => {
  87. //console.log(err);
  88. });
  89. }
  90. submitFeedback() {
  91. if (this.state.typeOfFeedback == '') {
  92. toastShort('Please select type of feedback');
  93. return;
  94. }
  95. if (this.state.feedback == '') {
  96. toastShort('Please type feedback content');
  97. return;
  98. }
  99. const params = {
  100. "typeOfFeedback": this.state.typeOfFeedback,
  101. "feedback": this.state.feedback,
  102. "feedbackImgOne": this.state.imageUrl[0],
  103. "feedbackImgTwo": this.state.imageUrl[1],
  104. "feedbackImgThree": this.state.imageUrl[2]
  105. }
  106. Dialog.showProgressDialog();
  107. apiUser.feedback(params).then(res => {
  108. Dialog.dismissLoading();
  109. Dialog.showResultDialog('Send feedback successfully!', 'OK', back => {
  110. goBack();
  111. });
  112. }).catch(err => {
  113. Dialog.dismissLoading();
  114. toastShort(err);
  115. });
  116. }
  117. render() {
  118. return (
  119. <ScrollView
  120. style={styles.container}
  121. keyboardShouldPersistTaps='handled'
  122. contentInsetAdjustmentBehavior='automatic'>
  123. <Text style={styles.title}>Have something to tell us?</Text>
  124. <Text style={styles.content}>Please let us know below!</Text>
  125. <Text style={styles.typeTitle}>Type of Feedback</Text>
  126. <View style={styles.pickerView}>
  127. <Dropdown
  128. title='Type of Feedback'
  129. list={this.state.typeList}
  130. value={this.state.typeOfFeedback}
  131. nameKey={'value'}
  132. valueKey={'key'}
  133. placeholder='Select'
  134. onChange={(value, index)=> {
  135. this.setState({
  136. typeOfFeedback: value
  137. })
  138. }}/>
  139. </View>
  140. <Text style={styles.typeTitle}>Please fill in here (500 words)</Text>
  141. <TextInput
  142. style={styles.feedbackInput}
  143. multiline={true}
  144. numberOfLines={8}
  145. textAlignVertical='top'
  146. onChangeText={text => {
  147. this.setState({
  148. feedback: text
  149. });
  150. }}/>
  151. <View
  152. style={styles.uploadGroup}>
  153. { this.state.imageUrl.map((item, index) => {
  154. return (
  155. <Pressable
  156. key={index}
  157. style={styles.uploadView}
  158. onPress={() => {
  159. this.uploadImage(index)
  160. }}>
  161. { item == ''
  162. ? <Image
  163. style={styles.uploadIcon}
  164. source={require('../../images/icon/ic-add-photo.png')}/>
  165. : <Image
  166. style={styles.uploadIcon}
  167. defaultSource={require('../../images/icon/icon-upload-default.png')}
  168. source={{uri: host + item}}/>
  169. }
  170. </Pressable>
  171. );
  172. })
  173. }
  174. </View>
  175. <Button
  176. style={styles.button}
  177. text='Submit Feedback'
  178. elevation={1.5}
  179. onClick={() => {
  180. this.submitFeedback();
  181. }}/>
  182. </ScrollView>
  183. );
  184. }
  185. }
  186. const styles = StyleSheet.create({
  187. container: {
  188. flex: 1,
  189. paddingLeft: 16,
  190. paddingRight: 16,
  191. backgroundColor: 'white'
  192. },
  193. title: {
  194. color: '#000',
  195. fontSize: 18,
  196. paddingTop: 16,
  197. paddingBottom: 10
  198. },
  199. content: {
  200. color: '#333',
  201. fontSize: 14,
  202. paddingBottom: 14
  203. },
  204. typeTitle: {
  205. color: '#000',
  206. fontSize: 14,
  207. paddingTop: 16,
  208. paddingBottom: 10
  209. },
  210. pickerView: {
  211. width: $vw(60),
  212. height: 44,
  213. borderWidth: 1,
  214. borderColor: '#999',
  215. borderRadius: 6,
  216. marginTop: 8,
  217. marginBottom: 8,
  218. overflow: 'hidden',
  219. justifyContent: 'center',
  220. backgroundColor: '#F5F5F5'
  221. },
  222. feedbackInput: {
  223. color: '#333',
  224. minHeight: 100,
  225. borderWidth: 1,
  226. borderColor: '#999',
  227. borderRadius: 6,
  228. paddingLeft: 10,
  229. paddingRight: 10,
  230. backgroundColor: '#F5F5F5'
  231. },
  232. uploadGroup: {
  233. paddingTop: 16,
  234. alignItems: 'center',
  235. flexDirection: 'row',
  236. justifyContent: 'center'
  237. },
  238. uploadView: {
  239. flex: 1,
  240. alignItems: 'center'
  241. },
  242. uploadIcon: {
  243. width: $vw(29),
  244. height: $vw(29),
  245. borderRadius: 6
  246. },
  247. button: {
  248. marginTop: 32,
  249. marginBottom: 16,
  250. borderRadius: 4
  251. }
  252. })