ComplaintNextScreen.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { StyleSheet, View } from 'react-native';
  4. import { Flex, TextareaItem } from '@ant-design/react-native';
  5. import { Div, Button } from 'react-native-magnus';
  6. import { ScrollView } from 'react-native-gesture-handler';
  7. import { useTranslation } from 'react-i18next';
  8. import { useRoute } from '@react-navigation/native';
  9. import { useCreation } from '@umijs/hooks';
  10. import useModel from 'flooks';
  11. import Order from './model'; // Order模块通用方法
  12. import Header from './Header'; // 头部
  13. import Text from '../../components/Text';
  14. import ImagePicker from '../../components/ImagePicker';
  15. const Name = new Map([
  16. ['MERCHANT', '商家'],
  17. ['RIDER', '骑手'],
  18. ]);
  19. export default function ComplaintScreen({ navigation }) {
  20. const { t } = useTranslation();
  21. const { complaintSave } = useModel(Order, []);
  22. const route = useRoute();
  23. const { params } = route;
  24. const { orderId, type, target } = params || {};
  25. const [imgList, setimgList] = React.useState(['']);
  26. const [content, setcontent] = React.useState('');
  27. function changeImg(img, index) {
  28. const list = [...imgList];
  29. if (!img) {
  30. list.splice(index, 1);
  31. } else {
  32. list.splice(index, 1, img);
  33. }
  34. if (index === list.length - 1 && list.length < 4) {
  35. list.push('');
  36. }
  37. setimgList(list);
  38. }
  39. function deleteImg(index) {
  40. const list = [...imgList];
  41. if (!list[index]) {
  42. return null;
  43. } else {
  44. return () => changeImg('', index);
  45. }
  46. }
  47. function submit() {
  48. const img = [...imgList].filter((item) => {
  49. return item;
  50. });
  51. complaintSave(orderId, target, type, content, img.join(',')).then(() => {
  52. navigation.goBack();
  53. });
  54. }
  55. const canSubmit = useCreation(() => {
  56. if (orderId && target && type && content) {
  57. return true;
  58. } else {
  59. return false;
  60. }
  61. }, [orderId, target, type, content, imgList]);
  62. return (
  63. <>
  64. <Header title={t('ding-dan-tou-su')} />
  65. <ScrollView contentContainerStyle={styles.scroll}>
  66. <View style={styles.card}>
  67. <Flex>
  68. <Flex.Item>
  69. <Text size="c2" type="info">
  70. {t('tou-su')}
  71. {Name.get(target)}
  72. </Text>
  73. </Flex.Item>
  74. <Text size="c2">{type || ''}</Text>
  75. </Flex>
  76. <View style={styles.textarea}>
  77. <TextareaItem
  78. rows={4}
  79. placeholder={t('content1')}
  80. style={styles.text}
  81. count={100}
  82. onChange={setcontent}
  83. />
  84. </View>
  85. <Div row>
  86. {imgList.map((item, index) => {
  87. return (
  88. <ImagePicker
  89. key={index}
  90. img={item}
  91. setImg={(img) => changeImg(img, index)}
  92. cancelEvent={deleteImg(index)}
  93. />
  94. );
  95. })}
  96. </Div>
  97. </View>
  98. <Button
  99. block
  100. bg="brand500"
  101. color="white"
  102. my={10}
  103. mx={20}
  104. onPress={submit}
  105. disabled={!canSubmit}
  106. >
  107. {t('ti-jiao')}
  108. </Button>
  109. </ScrollView>
  110. </>
  111. );
  112. }
  113. const styles = StyleSheet.create({
  114. scroll: {
  115. paddingVertical: 10,
  116. },
  117. card: {
  118. paddingHorizontal: 15,
  119. paddingVertical: 20,
  120. backgroundColor: '#fff',
  121. marginBottom: 10,
  122. },
  123. item: {
  124. paddingVertical: 5,
  125. },
  126. main: {
  127. paddingVertical: 5,
  128. },
  129. bottom: {
  130. paddingVertical: 10,
  131. },
  132. textarea: {
  133. marginVertical: 10,
  134. },
  135. text: {
  136. backgroundColor: '#eeeeee',
  137. paddingVertical: 10,
  138. fontSize: 10,
  139. borderBottomWidth: 0,
  140. },
  141. });