EvaluateScreen.jsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { StyleSheet, View } from 'react-native';
  4. import { Div, Button, Image, Text, Tag } from 'react-native-magnus';
  5. import { TextareaItem } from '@ant-design/react-native';
  6. import { ScrollView } from 'react-native-gesture-handler';
  7. import { useRoute } from '@react-navigation/native';
  8. import { useCreation, useRequest, useSet } from '@umijs/hooks';
  9. import { useTranslation } from 'react-i18next';
  10. import useModel from 'flooks';
  11. import Order from './model'; // Order模块通用方法
  12. import Header from './Header'; // 头部
  13. import ImagePicker from '../../components/ImagePicker';
  14. import Choose from '../../components/Choose';
  15. import ChooseMerchant from '../../components/ChooseMerchant';
  16. const map = new Map([
  17. [
  18. 'bad',
  19. [
  20. '不送上楼',
  21. '着装脏乱',
  22. '服务态度差',
  23. '未带保温箱',
  24. '食品凉了',
  25. '额外索取费用',
  26. '配送慢',
  27. '提前点送达',
  28. ],
  29. ],
  30. ['normal', ['味道一般', '速度很慢']],
  31. ['good', ['超好吃', '超级慢']],
  32. ]);
  33. export default function EvaluateScreen({ navigation }) {
  34. const { t } = useTranslation();
  35. const { userAppraisal } = useModel(Order, []);
  36. const route = useRoute();
  37. const { params } = route;
  38. const { orderId } = params || {};
  39. const [orderInfo, setorderInfo] = React.useState({ merchant: {} });
  40. const [choose, setchoose] = React.useState('');
  41. const [chooseMer, setchooseMer] = React.useState('');
  42. const [content, setcontent] = React.useState('');
  43. const [imgList, setimgList] = React.useState(['']);
  44. const [content2, setcontent2] = React.useState('');
  45. function changeImg(img, index) {
  46. const list = [...imgList];
  47. if (!img) {
  48. list.splice(index, 1);
  49. } else {
  50. list.splice(index, 1, img);
  51. }
  52. if (index === list.length - 1 && list.length < 4) {
  53. list.push('');
  54. }
  55. setimgList(list);
  56. }
  57. function deleteImg(index) {
  58. const list = [...imgList];
  59. if (!list[index]) {
  60. return null;
  61. } else {
  62. return () => changeImg('', index);
  63. }
  64. }
  65. const [tags, tagEvent] = useSet([]);
  66. React.useEffect(() => {
  67. tagEvent.reset();
  68. }, [choose]);
  69. const { merShowName, merchantId, riderId, merLogo } = orderInfo;
  70. useRequest(() => `/orderInfo/get/${orderId}`, {
  71. refreshDeps: [orderId],
  72. onSuccess: (result) => {
  73. setorderInfo(result);
  74. },
  75. });
  76. function submit() {
  77. const img = [...imgList].filter((item) => {
  78. return item;
  79. });
  80. const riderScore = [...map.keys()].indexOf(choose);
  81. userAppraisal(
  82. orderId,
  83. merchantId,
  84. riderId,
  85. img,
  86. chooseMer === 'good',
  87. content2,
  88. riderScore,
  89. content + [...Array.from(tags)].join(',')
  90. ).then(() => {
  91. navigation.goBack();
  92. });
  93. }
  94. const canSubmit = useCreation(() => {
  95. if (orderId && choose && chooseMer) {
  96. return true;
  97. } else {
  98. return false;
  99. }
  100. }, [orderId, choose, chooseMer, content, imgList, content2]);
  101. return (
  102. <>
  103. <Header title={t('tip3')} />
  104. <ScrollView contentContainerStyle={styles.scroll}>
  105. <View style={styles.card}>
  106. <Div row alignItems="center">
  107. <Image
  108. h={40}
  109. w={40}
  110. rounded="sm"
  111. source={{
  112. uri: 'https://picsum.photos/700',
  113. }}
  114. />
  115. <Text
  116. fontSize="xl"
  117. fontWeight="bold"
  118. textAlign="left"
  119. flex={1}
  120. mx={8}
  121. >
  122. 猪猪费
  123. </Text>
  124. <Text fontSize="xs" color="gray300" textAlign="left">
  125. {t('tipss4')}
  126. </Text>
  127. </Div>
  128. <Choose chooseValue={choose} changeValue={setchoose} />
  129. {!!choose && (
  130. <Div row flexWrap="wrap" py={14}>
  131. {map.get(choose).map((item, index) => {
  132. const isChoose = tagEvent.has(item);
  133. return (
  134. <Tag
  135. key={index}
  136. ml="sm"
  137. mb="sm"
  138. fontSize="xs"
  139. borderColor={isChoose ? 'white' : 'gray300'}
  140. borderWidth={1}
  141. color={isChoose ? 'white' : 'gray400'}
  142. bg={isChoose ? 'brand500' : 'hide'}
  143. onPress={() => {
  144. if (isChoose) {
  145. tagEvent.remove(item);
  146. } else {
  147. tagEvent.add(item);
  148. }
  149. }}
  150. >
  151. {item}
  152. </Tag>
  153. );
  154. })}
  155. </Div>
  156. )}
  157. <TextareaItem
  158. rows={4}
  159. placeholder={t('content2')}
  160. style={styles.text}
  161. count={100}
  162. onChange={setcontent}
  163. />
  164. </View>
  165. <View style={styles.card}>
  166. <Div row alignItems="center">
  167. <Image
  168. h={40}
  169. w={40}
  170. rounded="sm"
  171. source={{
  172. uri: merLogo,
  173. }}
  174. />
  175. <Text fontSize="xl" fontWeight="bold" flex={1} mx={8}>
  176. {merShowName || ' '}
  177. </Text>
  178. <Text fontSize="xs" color="gray300" textAlign="left">
  179. {t('yi-dui-shang-jia-ni-ming')}
  180. </Text>
  181. </Div>
  182. <ChooseMerchant chooseValue={chooseMer} changeValue={setchooseMer} />
  183. <Div pt={10} />
  184. <TextareaItem
  185. rows={4}
  186. placeholder={t('content2')}
  187. style={styles.text}
  188. count={100}
  189. onChange={setcontent2}
  190. />
  191. <Div row mt={10}>
  192. {imgList.map((item, index) => {
  193. return (
  194. <ImagePicker
  195. key={index}
  196. img={item}
  197. setImg={(img) => changeImg(img, index)}
  198. cancelEvent={deleteImg(index)}
  199. />
  200. );
  201. })}
  202. </Div>
  203. </View>
  204. <Button
  205. block
  206. bg="brand500"
  207. color="white"
  208. my={5}
  209. mx={10}
  210. onPress={submit}
  211. disabled={!canSubmit}
  212. >
  213. {t('ti-jiao')}
  214. </Button>
  215. </ScrollView>
  216. </>
  217. );
  218. }
  219. const styles = StyleSheet.create({
  220. scroll: {
  221. paddingVertical: 10,
  222. },
  223. card: {
  224. paddingHorizontal: 15,
  225. paddingVertical: 20,
  226. backgroundColor: '#fff',
  227. marginBottom: 10,
  228. },
  229. item: {
  230. paddingVertical: 5,
  231. },
  232. main: {
  233. paddingVertical: 5,
  234. },
  235. bottom: {
  236. paddingVertical: 10,
  237. },
  238. textarea: {
  239. marginVertical: 10,
  240. },
  241. text: {
  242. backgroundColor: '#eeeeee',
  243. paddingVertical: 10,
  244. fontSize: 10,
  245. borderBottomWidth: 0,
  246. },
  247. });