FeedBackScreen.jsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 useModel from 'flooks';
  8. import User from '../../flooks/User'; // detail模块通用方法
  9. import Toast from '../../flooks/Toast'; // detail模块通用方法
  10. import ImagePicker from '../../components/ImagePicker';
  11. import Header from '../../components/Header';
  12. import request from '../../Utils/RequestUtils';
  13. import { alertWithoutCancel } from '../../Utils/TotastUtils';
  14. function saveRequest(data) {
  15. return request.post('/feedback/save', {
  16. data,
  17. });
  18. }
  19. export default function FeedBackScreen({ navigation }) {
  20. const { userInfo } = useModel(User, ['id']);
  21. const { warnning, success } = useModel(Toast, []);
  22. const [name, setname] = React.useState('');
  23. const [phone, setphone] = React.useState('');
  24. const [content, setcontent] = React.useState('');
  25. const [imgList, setimgList] = React.useState(['']);
  26. function changeImg(img, index) {
  27. const list = [...imgList];
  28. if (!img) {
  29. list.splice(index, 1);
  30. } else {
  31. list.splice(index, 1, img);
  32. }
  33. if (index === list.length - 1 && list.length < 4) {
  34. list.push('');
  35. }
  36. setimgList(list);
  37. }
  38. function deleteImg(index) {
  39. const list = [...imgList];
  40. if (!list[index]) {
  41. return null;
  42. } else {
  43. return () => changeImg('', index);
  44. }
  45. }
  46. const allpyRequest = useRequest((data) => saveRequest(data), {
  47. manual: true,
  48. onError: (e) => {
  49. warnning(e.error);
  50. },
  51. onSuccess: () => {
  52. alertWithoutCancel(
  53. '',
  54. '感谢您的反馈,我们将根据您的反馈优化产品或服务,为您提供更好的使用体验',
  55. false,
  56. () => {
  57. navigation.goBack();
  58. }
  59. );
  60. },
  61. });
  62. const img = useCreation(() => {
  63. const list = imgList.filter((item) => {
  64. return !!item;
  65. });
  66. return list.join(',');
  67. }, [imgList]);
  68. const canSubmit = useCreation(() => {
  69. if (content) {
  70. return true;
  71. } else {
  72. return false;
  73. }
  74. }, [name, phone, content, img]);
  75. return (
  76. <>
  77. <Header title="意见反馈" />
  78. <ScrollView
  79. contentContainerStyle={{
  80. backgroundColor: '#fff',
  81. flexGrow: 1,
  82. }}
  83. >
  84. <Text px={15} py={10} fontSize="sm" color="gray500">
  85. 您对我们有什么意见或建议,或者遇到的问题反馈给我们,以
  86. 便我们为您提供更好的服务(必填)
  87. </Text>
  88. <Div px={15}>
  89. <TextareaItem
  90. rows={4}
  91. placeholder="最多500字"
  92. count={500}
  93. style={{
  94. backgroundColor: '#eee',
  95. fontSize: 14,
  96. paddingTop: 10,
  97. borderRadius: 3,
  98. }}
  99. onChange={(text) => setcontent(text)}
  100. />
  101. </Div>
  102. <Div row py={10} px={15}>
  103. {imgList.map((item, index) => {
  104. return (
  105. <ImagePicker
  106. key={index}
  107. img={item}
  108. setImg={(img1) => changeImg(img1, index)}
  109. cancelEvent={deleteImg(index)}
  110. />
  111. );
  112. })}
  113. </Div>
  114. <Text px={15} pt={10} fontSize="sm">
  115. 请输入联系信息(选填)
  116. </Text>
  117. <InputItem
  118. clear
  119. type="phone"
  120. value={name}
  121. onChange={setname}
  122. placeholder="输入联系人"
  123. style={{
  124. fontSize: 14,
  125. backgroundColor: '#eee',
  126. paddingLeft: 10,
  127. borderRadius: 3,
  128. }}
  129. last
  130. >
  131. <Text fontSize="sm">姓名</Text>
  132. </InputItem>
  133. <InputItem
  134. clear
  135. type="phone"
  136. value={phone}
  137. onChange={setphone}
  138. placeholder="输入联系电话"
  139. style={{
  140. fontSize: 14,
  141. backgroundColor: '#eee',
  142. paddingLeft: 10,
  143. borderRadius: 3,
  144. }}
  145. last
  146. >
  147. <Text fontSize="sm">联系电话</Text>
  148. </InputItem>
  149. <Text fontSize="xs" color="gray500" pl={85}>
  150. 联系人信息将为您加密传输,保护您的隐私
  151. </Text>
  152. <Button
  153. my={30}
  154. mx={130}
  155. fontSize="sm"
  156. block
  157. bg="brand500"
  158. disabled={!canSubmit}
  159. onPress={() => {
  160. allpyRequest.run({
  161. name,
  162. phone,
  163. content,
  164. img,
  165. userId: userInfo.id,
  166. });
  167. }}
  168. >
  169. 提交反馈
  170. </Button>
  171. </ScrollView>
  172. </>
  173. );
  174. }