FeedBackScreen.jsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { Div, Button, Image, Text, Avatar } from 'react-native-magnus';
  4. import { ScrollView } from 'react-native-gesture-handler';
  5. import { InputItem, TextareaItem } from '@ant-design/react-native';
  6. import { useRequest, useCreation } from '@umijs/hooks';
  7. import { useTranslation } from 'react-i18next';
  8. import useModel from 'flooks';
  9. import User from '../../flooks/User'; // detail模块通用方法
  10. import Toast from '../../flooks/Toast'; // detail模块通用方法
  11. import ImagePicker from '../../components/ImagePicker';
  12. import Header from '../../components/Header';
  13. import request from '../../Utils/RequestUtils';
  14. import { alertWithoutCancel } from '../../Utils/TotastUtils';
  15. function saveRequest(data) {
  16. return request.post('/feedback/save', {
  17. data,
  18. });
  19. }
  20. export default function FeedBackScreen({ navigation }) {
  21. const { t } = useTranslation();
  22. const { userInfo } = useModel(User, ['id']);
  23. const { warnning, success } = useModel(Toast, []);
  24. const [name, setname] = React.useState('');
  25. const [phone, setphone] = React.useState('');
  26. const [content, setcontent] = React.useState('');
  27. const [imgList, setimgList] = React.useState(['']);
  28. function changeImg(img, index) {
  29. const list = [...imgList];
  30. if (!img) {
  31. list.splice(index, 1);
  32. } else {
  33. list.splice(index, 1, img);
  34. }
  35. if (index === list.length - 1 && list.length < 4) {
  36. list.push('');
  37. }
  38. setimgList(list);
  39. }
  40. function deleteImg(index) {
  41. const list = [...imgList];
  42. if (!list[index]) {
  43. return null;
  44. } else {
  45. return () => changeImg('', index);
  46. }
  47. }
  48. const allpyRequest = useRequest((data) => saveRequest(data), {
  49. manual: true,
  50. onError: (e) => {
  51. warnning(e.error);
  52. },
  53. onSuccess: () => {
  54. alertWithoutCancel('', t('fankui1'), false, () => {
  55. navigation.goBack();
  56. });
  57. },
  58. });
  59. const img = useCreation(() => {
  60. const list = imgList.filter((item) => {
  61. return !!item;
  62. });
  63. return list.join(',');
  64. }, [imgList]);
  65. const canSubmit = useCreation(() => {
  66. if (content) {
  67. return true;
  68. } else {
  69. return false;
  70. }
  71. }, [name, phone, content, img]);
  72. return (
  73. <>
  74. <Header title="意见反馈" />
  75. <ScrollView
  76. contentContainerStyle={{
  77. backgroundColor: '#fff',
  78. flexGrow: 1,
  79. }}
  80. >
  81. <Text px={15} py={10} fontSize="sm" color="gray500">
  82. {t('fankui2')}
  83. </Text>
  84. <Div px={15}>
  85. <TextareaItem
  86. rows={4}
  87. placeholder={t('zui-duo-500-zi')}
  88. count={500}
  89. style={{
  90. backgroundColor: '#eee',
  91. fontSize: 14,
  92. paddingTop: 10,
  93. borderRadius: 3,
  94. }}
  95. onChange={(text) => setcontent(text)}
  96. />
  97. </Div>
  98. <Div row py={10} px={15}>
  99. {imgList.map((item, index) => {
  100. return (
  101. <ImagePicker
  102. key={index}
  103. img={item}
  104. setImg={(img1) => changeImg(img1, index)}
  105. cancelEvent={deleteImg(index)}
  106. />
  107. );
  108. })}
  109. </Div>
  110. <Text px={15} pt={10} fontSize="sm">
  111. {t('qing-shu-ru-lian-xi-xin-xi-xuan-tian')}
  112. </Text>
  113. <InputItem
  114. clear
  115. type="phone"
  116. value={name}
  117. onChange={setname}
  118. placeholder={t('shu-ru-lian-xi-ren')}
  119. style={{
  120. fontSize: 14,
  121. backgroundColor: '#eee',
  122. paddingLeft: 10,
  123. borderRadius: 3,
  124. }}
  125. last
  126. >
  127. <Text fontSize="sm">{t('xing-ming')}</Text>
  128. </InputItem>
  129. <InputItem
  130. clear
  131. type="phone"
  132. value={phone}
  133. onChange={setphone}
  134. placeholder={t('shu-ru-lian-xi-dian-hua')}
  135. style={{
  136. fontSize: 14,
  137. backgroundColor: '#eee',
  138. paddingLeft: 10,
  139. borderRadius: 3,
  140. }}
  141. last
  142. >
  143. <Text fontSize="sm">{t('lian-xi-dian-hua')}</Text>
  144. </InputItem>
  145. <Text fontSize="xs" color="gray500" pl={85}>
  146. {t('tips8')}
  147. </Text>
  148. <Button
  149. my={30}
  150. mx={130}
  151. fontSize="sm"
  152. block
  153. bg="brand500"
  154. disabled={!canSubmit}
  155. onPress={() => {
  156. allpyRequest.run({
  157. name,
  158. phone,
  159. content,
  160. img,
  161. userId: userInfo.id,
  162. });
  163. }}
  164. >
  165. {t('ti-jiao-fan-kui')}
  166. </Button>
  167. </ScrollView>
  168. </>
  169. );
  170. }