Feedback.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /**
  2. * Feedback 页面
  3. * @邠心vbe on 2021/04/28
  4. */
  5. import React from 'react';
  6. import { View, Text, StyleSheet, ScrollView, TextInput, Image, Pressable, FlatList } from 'react-native';
  7. import Button from '../../components/Button';
  8. import apiUpload from '../../api/apiUpload';
  9. import apiUser from '../../api/apiUser';
  10. import Dialog from '../../components/Dialog';
  11. import ImagePicker from 'react-native-image-crop-picker';
  12. import Dropdown from '../../components/Dropdown';
  13. import Modal from 'react-native-modal';
  14. import { UploadThemes } from '../../components/ThemesConfig';
  15. import apiBase from '../../api/apiBase.js';
  16. import utils from '../../utils/utils';
  17. const options = {
  18. cropping: false,
  19. multiple: false,
  20. minFiles: 1,
  21. maxFiles: 3,
  22. mediaType: 'photo',
  23. writeTempFile: false,
  24. compressImageQuality: 0.8,
  25. compressImageMaxWidth: 720,
  26. compressImageMaxHeight: 1280,
  27. ...UploadThemes
  28. }
  29. export default class Feedback extends React.Component {
  30. constructor(props) {
  31. super(props);
  32. this.state= {
  33. typeList: [],
  34. feedback: '',
  35. searchId: '',
  36. connectorId: '',
  37. chargeBoxId: '',
  38. typeOfFeedback: '',
  39. imageUrl: ['', '', ''],
  40. chargeBoxList: [],
  41. connectorList: [],
  42. showDialog: false,
  43. searching: false
  44. }
  45. }
  46. componentDidMount() {
  47. this.pageShow = true;
  48. this.props.navigation.addListener('blur', () => {
  49. this.pageShow = false;
  50. });
  51. apiUser.getTypeOfFeedback().then(res => {
  52. if (res.success && res.data.length > 0) {
  53. this.setState({
  54. typeList: res.data
  55. });
  56. } else {
  57. if (this.pageShow) {
  58. this.noTypeDialog();
  59. }
  60. }
  61. }).catch(err => {
  62. if (this.pageShow) {
  63. this.noTypeDialog();
  64. }
  65. });
  66. this.getChargeBox("");
  67. }
  68. noTypeDialog() {
  69. setTimeout(() => {
  70. if (this.pageShow) {
  71. Dialog.showResultDialog($t('feedback.errFetchType'), $t('nav.ok'), back => {
  72. goBack();
  73. });
  74. }
  75. }, 500);
  76. }
  77. changeType(type, index) {
  78. this.setState({
  79. typeOfFeedback: type
  80. })
  81. }
  82. listChargeBox(searchId) {
  83. this.setState({
  84. searching: true,
  85. searchId: searchId
  86. }, () => {
  87. setTimeout(() => {
  88. this.getChargeBox(searchId)
  89. }, 300);
  90. });
  91. }
  92. getChargeBox(searchId) {
  93. if (searchId != this.state.searchId) {
  94. return;
  95. }
  96. apiBase.listChargeBox(this.state.searchId).then(res => {
  97. if (res.data) {
  98. this.setState({
  99. chargeBoxList: res.data,
  100. searching: false
  101. })
  102. } else {
  103. this.setState({
  104. chargeBoxList: [],
  105. searching: false,
  106. connectorId: ""
  107. })
  108. }
  109. }).catch(err => {
  110. this.setState({
  111. chargeBoxList: [],
  112. searching: false,
  113. connectorId: ""
  114. })
  115. })
  116. }
  117. listConnector() {
  118. //Dialog.showProgressDialog()
  119. apiBase.listConnector(this.state.chargeBoxId).then(res => {
  120. if (res.data) {
  121. this.setState({
  122. connectorList: res.data
  123. })
  124. } else {
  125. this.setState({
  126. connectorList: []
  127. })
  128. }
  129. }).catch(err => {
  130. this.setState({
  131. connectorList: []
  132. })
  133. })
  134. }
  135. uploadImage(index) {
  136. ImagePicker.openPicker(options).then(image => {
  137. if (image.path) {
  138. apiUpload.uploadImage(image.path, image.mime, 'FEEDBACK').then(res => {
  139. if (res.success && res.data.picturePath) {
  140. let imageUrl = this.state.imageUrl;
  141. imageUrl[index] = res.data.picturePath;
  142. this.setState({
  143. imageUrl: imageUrl
  144. });
  145. toastShort($t('common.uploadSuccess'));
  146. } else {
  147. toastShort($t('common.uploadFailed'));
  148. }
  149. }).catch(err => {
  150. toastShort(err);
  151. });
  152. }
  153. }).catch(err => {
  154. //console.log(err);
  155. });
  156. }
  157. submitFeedback() {
  158. if (this.state.typeOfFeedback == '') {
  159. toastShort($t('feedback.errFeedbackType'));
  160. return;
  161. }
  162. if (this.state.feedback == '') {
  163. toastShort($t('feedback.errFeednackContent'));
  164. return;
  165. }
  166. const params = {
  167. "typeOfFeedback": this.state.typeOfFeedback,
  168. "feedback": this.state.feedback,
  169. "feedbackImgOne": this.state.imageUrl[0],
  170. "feedbackImgTwo": this.state.imageUrl[1],
  171. "feedbackImgThree": this.state.imageUrl[2],
  172. "chargeBoxId": this.state.chargeBoxId,
  173. "connectorId": this.state.connectorId
  174. }
  175. Dialog.showProgressDialog();
  176. apiUser.feedback(params).then(res => {
  177. Dialog.dismissLoading();
  178. Dialog.showResultDialog($t('feedback.sendSuccess'), $t('nav.ok'), back => {
  179. goBack();
  180. });
  181. }).catch(err => {
  182. Dialog.dismissLoading();
  183. toastShort(err);
  184. });
  185. }
  186. changeChargeBox(id) {
  187. if (id) {
  188. this.setState({
  189. showDialog: false,
  190. chargeBoxId: id
  191. }, () => this.listConnector())
  192. } else {
  193. this.setState({
  194. showDialog: false
  195. })
  196. }
  197. }
  198. changeConnector(id) {
  199. this.setState({
  200. connectorId: id
  201. })
  202. }
  203. render() {
  204. return (
  205. <ScrollView
  206. style={styles.container}
  207. keyboardShouldPersistTaps={isIOS ? 'never' : 'handled'}
  208. contentInsetAdjustmentBehavior='automatic'>
  209. <View style={styles.headerView}>
  210. <View style={ui.flex1}>
  211. <Text style={styles.title}>{$t('feedback.tipsSomething')}</Text>
  212. <Text style={styles.content}>{$t('feedback.tipsLetKnow')}</Text>
  213. </View>
  214. <Image
  215. style={styles.headerImage}
  216. resizeMode="contain"
  217. source={require('../../images/top-feedback.png')}/>
  218. </View>
  219. <View style={styles.contentView}>
  220. <Text style={styles.typeTitle}>{$t('feedback.typeOfFeedback')}</Text>
  221. <View style={styles.pickerView}>
  222. <Dropdown
  223. style={styles.pickerViewInfo}
  224. title={$t('feedback.typeOfFeedback')}
  225. list={this.state.typeList}
  226. value={this.state.typeOfFeedback}
  227. nameKey={'value'}
  228. valueKey={'key'}
  229. placeholder={$t('common.select')}
  230. onChange={(value, index) => this.changeType(value, index)}/>
  231. </View>
  232. <Text style={styles.typeTitle}>{$t('feedback.labelContent')}</Text>
  233. <TextInput
  234. style={styles.feedbackInput}
  235. multiline={true}
  236. numberOfLines={8}
  237. maxLength={1000}
  238. textAlignVertical='top'
  239. onChangeText={text => {
  240. this.setState({
  241. feedback: text
  242. });
  243. }}/>
  244. <Text style={styles.typeTitle}>{$t('feedback.labelUpload')}</Text>
  245. <View
  246. style={styles.uploadGroup}>
  247. { this.state.imageUrl.map((item, index) => {
  248. return (
  249. <Pressable
  250. key={index}
  251. style={styles.uploadView}
  252. onPress={() => {
  253. this.uploadImage(index)
  254. }}>
  255. { item == ''
  256. ? <Image
  257. style={styles.uploadIcon}
  258. source={require('../../images/icon/ic-add-photo.png')}/>
  259. : <Image
  260. style={styles.uploadIcon}
  261. defaultSource={require('../../images/icon/icon-upload-default.png')}
  262. source={{uri: utils.getImageUrl(item)}}/>
  263. }
  264. </Pressable>
  265. );
  266. })
  267. }
  268. </View>
  269. {this.state.typeOfFeedback == "csf" && <>
  270. <Text style={styles.typeTitle}>{$t('feedback.labelStation')}</Text>
  271. <Pressable
  272. style={[styles.pickerView, styles.stationView]}
  273. android_ripple={ripple}
  274. onPress={() => this.setState({showDialog: true})}>
  275. <MaterialIcons
  276. name="search"
  277. size={24}
  278. color="#00638C"
  279. />
  280. <Text style={styles.textStation}>{this.state.chargeBoxId}</Text>
  281. </Pressable>
  282. <Text style={styles.typeTitle}>{$t('feedback.labelConnector')}</Text>
  283. <View style={styles.pickerView}>
  284. <Dropdown
  285. style={styles.pickerViewInfo}
  286. title={$t('feedback.selectConnector')}
  287. list={this.state.connectorList}
  288. value={this.state.connectorId}
  289. placeholder={$t('common.select')}
  290. onChange={value => this.changeConnector(value)}/>
  291. </View>
  292. </>}
  293. <Button
  294. style={styles.button}
  295. text={$t('feedback.submitFeedback')}
  296. elevation={1.5}
  297. onClick={() => {
  298. this.submitFeedback();
  299. }}/>
  300. </View>
  301. <Modal
  302. style={{zIndex: 900}}
  303. isVisible={this.state.showDialog}
  304. avoidKeyboard={true}
  305. animationIn={"fadeIn"}
  306. animationOut={"fadeOut"}
  307. useNativeDriver={true}
  308. onBackdropPress={() => this.changeChargeBox()}
  309. onBackButtonPress={() => this.changeChargeBox()}>
  310. <View style={Dialog.styles.modalDialog}>
  311. <View style={[styles.pickerView, styles.stationView]}>
  312. <MaterialIcons
  313. name="search"
  314. size={24}
  315. color="#00638C"
  316. />
  317. <TextInput
  318. style={styles.inputView}
  319. maxLength={50}
  320. placeholder={$t('feedback.searchingChargeBox')}
  321. onChangeText={text => this.listChargeBox(text)}
  322. />
  323. </View>
  324. { this.state.searching
  325. ? <View style={[styles.stationList, ui.center]}>
  326. <Image
  327. style={styles.seachingIcon}
  328. source={require('../../images/icon/search-loading.gif')}/>
  329. </View>
  330. : <FlatList
  331. style={styles.stationList}
  332. data={this.state.chargeBoxList}
  333. keyExtractor={(item,index) => index}
  334. renderItem={this.listItem}
  335. ListEmptyComponent={<Text style={styles.noResult}>{$t('home.noSearch')}</Text>}
  336. />
  337. }
  338. </View>
  339. </Modal>
  340. </ScrollView>
  341. );
  342. }
  343. listItem = ({item, index}) => {
  344. return (
  345. <Button
  346. key={index}
  347. text={item}
  348. style={styles.stationItemView}
  349. textStyle={styles.stationItemText}
  350. onClick={() => this.changeChargeBox(item)}
  351. />
  352. )
  353. }
  354. }
  355. const styles = StyleSheet.create({
  356. container: {
  357. flex: 1,
  358. backgroundColor: pageBackground
  359. },
  360. contentView: {
  361. marginTop: -30,
  362. borderTopLeftRadius: 30,
  363. borderTopRightRadius: 30,
  364. ...$padding(8, 16, 16),
  365. backgroundColor: colorLight
  366. },
  367. headerView: {
  368. paddingTop: 16,
  369. paddingLeft: 16,
  370. paddingRight: 8,
  371. paddingBottom: 30,
  372. flexDirection: 'row',
  373. backgroundColor: '#F5F5F5'
  374. },
  375. headerImage: {
  376. width: 123,
  377. height: 101
  378. },
  379. title: {
  380. color: '#056A94',
  381. fontSize: 18,
  382. paddingTop: 16,
  383. paddingBottom: 8
  384. },
  385. content: {
  386. color: '#056A94',
  387. fontSize: 14
  388. },
  389. typeTitle: {
  390. color: '#000',
  391. fontSize: 16,
  392. paddingTop: 16,
  393. fontWeight: 'bold',
  394. paddingBottom: 10
  395. },
  396. stationView: {
  397. paddingLeft: 12,
  398. alignItems: 'center',
  399. flexDirection: 'row'
  400. },
  401. textStation: {
  402. flex: 1,
  403. color: textPrimary,
  404. fontSize: 15,
  405. paddingLeft: 8
  406. },
  407. pickerView: {
  408. //width: $vw(60),
  409. height: 44,
  410. borderWidth: 1,
  411. borderColor: '#999',
  412. borderRadius: 6,
  413. marginTop: 8,
  414. marginBottom: 8,
  415. overflow: 'hidden',
  416. justifyContent: 'center',
  417. backgroundColor: '#F5F5F5'
  418. },
  419. inputView: {
  420. flex: 1,
  421. color: textPrimary,
  422. fontSize: 15
  423. },
  424. pickerViewInfo: {
  425. height: 44,
  426. paddingLeft: 16,
  427. paddingRight: 8,
  428. alignItems: 'center',
  429. flexDirection: 'row'
  430. },
  431. feedbackInput: {
  432. color: textPrimary,
  433. minHeight: 100,
  434. borderWidth: 1,
  435. borderColor: '#999',
  436. borderRadius: 6,
  437. paddingLeft: 10,
  438. paddingRight: 10,
  439. backgroundColor: '#F5F5F5'
  440. },
  441. uploadGroup: {
  442. //paddingTop: 16,
  443. alignItems: 'center',
  444. flexDirection: 'row',
  445. justifyContent: 'center'
  446. },
  447. uploadView: {
  448. flex: 1,
  449. alignItems: 'center'
  450. },
  451. uploadIcon: {
  452. width: $vw(29),
  453. height: $vw(29),
  454. borderRadius: 6
  455. },
  456. button: {
  457. marginTop: 32,
  458. marginBottom: 16,
  459. borderRadius: 4
  460. },
  461. stationList: {
  462. height: $vh(35)
  463. },
  464. noResult: {
  465. color: textCancel,
  466. fontSize: 12,
  467. textAlign: 'center',
  468. paddingTop: 32
  469. },
  470. stationItemView: {
  471. borderRadius: 0,
  472. backgroundColor: colorLight,
  473. borderTopWidth: 1,
  474. borderTopColor: '#F0F0F0'
  475. },
  476. stationItemText: {
  477. flex: 1,
  478. color: textPrimary,
  479. fontSize: 15
  480. },
  481. seachingIcon: {
  482. width: 50,
  483. height: 50,
  484. marginTop: 20
  485. }
  486. })