Feedback.js 7.2 KB

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