Feedback.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. style={styles.pickerViewInfo}
  136. title='Type of Feedback'
  137. list={this.state.typeList}
  138. value={this.state.typeOfFeedback}
  139. nameKey={'value'}
  140. valueKey={'key'}
  141. placeholder='Select'
  142. onChange={(value, index)=> {
  143. this.setState({
  144. typeOfFeedback: value
  145. })
  146. }}/>
  147. </View>
  148. <Text style={styles.typeTitle}>Please fill in here (500 words)</Text>
  149. <TextInput
  150. style={styles.feedbackInput}
  151. multiline={true}
  152. numberOfLines={8}
  153. textAlignVertical='top'
  154. onChangeText={text => {
  155. this.setState({
  156. feedback: text
  157. });
  158. }}/>
  159. <View
  160. style={styles.uploadGroup}>
  161. { this.state.imageUrl.map((item, index) => {
  162. return (
  163. <Pressable
  164. key={index}
  165. style={styles.uploadView}
  166. onPress={() => {
  167. this.uploadImage(index)
  168. }}>
  169. { item == ''
  170. ? <Image
  171. style={styles.uploadIcon}
  172. source={require('../../images/icon/ic-add-photo.png')}/>
  173. : <Image
  174. style={styles.uploadIcon}
  175. defaultSource={require('../../images/icon/icon-upload-default.png')}
  176. source={{uri: host + item}}/>
  177. }
  178. </Pressable>
  179. );
  180. })
  181. }
  182. </View>
  183. <Button
  184. style={styles.button}
  185. text='Submit Feedback'
  186. elevation={1.5}
  187. onClick={() => {
  188. this.submitFeedback();
  189. }}/>
  190. </View>
  191. </ScrollView>
  192. );
  193. }
  194. }
  195. const styles = StyleSheet.create({
  196. container: {
  197. flex: 1,
  198. backgroundColor: pageBackground
  199. },
  200. contentView: {
  201. marginTop: -30,
  202. borderTopLeftRadius: 30,
  203. borderTopRightRadius: 30,
  204. ...$padding(8, 16, 16),
  205. backgroundColor: colorLight
  206. },
  207. headerView: {
  208. paddingTop: 16,
  209. paddingLeft: 16,
  210. paddingRight: 8,
  211. paddingBottom: 30,
  212. flexDirection: 'row',
  213. backgroundColor: '#F5F5F5'
  214. },
  215. headerImage: {
  216. width: 123,
  217. height: 101
  218. },
  219. title: {
  220. color: '#056A94',
  221. fontSize: 18,
  222. paddingTop: 16,
  223. paddingBottom: 8
  224. },
  225. content: {
  226. color: '#056A94',
  227. fontSize: 14
  228. },
  229. typeTitle: {
  230. color: '#000',
  231. fontSize: 16,
  232. paddingTop: 16,
  233. fontWeight: 'bold',
  234. paddingBottom: 10
  235. },
  236. pickerView: {
  237. //width: $vw(60),
  238. height: 44,
  239. borderWidth: 1,
  240. borderColor: '#999',
  241. borderRadius: 6,
  242. marginTop: 8,
  243. marginBottom: 8,
  244. overflow: 'hidden',
  245. justifyContent: 'center',
  246. backgroundColor: '#F5F5F5'
  247. },
  248. pickerViewInfo: {
  249. height: 44,
  250. paddingLeft: 16,
  251. paddingRight: 32,
  252. alignItems: 'center',
  253. flexDirection: 'row'
  254. },
  255. feedbackInput: {
  256. color: textPrimary,
  257. minHeight: 100,
  258. borderWidth: 1,
  259. borderColor: '#999',
  260. borderRadius: 6,
  261. paddingLeft: 10,
  262. paddingRight: 10,
  263. backgroundColor: '#F5F5F5'
  264. },
  265. uploadGroup: {
  266. paddingTop: 16,
  267. alignItems: 'center',
  268. flexDirection: 'row',
  269. justifyContent: 'center'
  270. },
  271. uploadView: {
  272. flex: 1,
  273. alignItems: 'center'
  274. },
  275. uploadIcon: {
  276. width: $vw(29),
  277. height: $vw(29),
  278. borderRadius: 6
  279. },
  280. button: {
  281. marginTop: 32,
  282. marginBottom: 16,
  283. borderRadius: 4
  284. }
  285. })