ApplayCancelScreen.jsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { Platform } from 'react-native';
  4. import { Div, Button, Text, Icon } from 'react-native-magnus';
  5. import { ScrollView } from 'react-native-gesture-handler';
  6. import { TextareaItem } from '@ant-design/react-native';
  7. import { useTranslation } from 'react-i18next';
  8. import { PullPicker } from 'teaset';
  9. import { useRoute } from '@react-navigation/native';
  10. import { useCreation } from '@umijs/hooks';
  11. import useModel from 'flooks';
  12. import Order from './model'; // Order模块通用方法
  13. import Header from '../../components/Header';
  14. import ImagePicker from '../../components/ImagePicker';
  15. import { reasonMap } from '../../Utils/OrderUtils';
  16. export default function ApplayCancelScreen({ navigation }) {
  17. const { t } = useTranslation();
  18. const { cancelOrder } = useModel(Order, []);
  19. const [imgList, setimgList] = React.useState(['']);
  20. const [content, setcontent] = React.useState('');
  21. const [chooseReason, setchooseReason] = React.useState('');
  22. const route = useRoute();
  23. const { params } = route;
  24. const { orderId } = params || {};
  25. const canSubmit = useCreation(() => {
  26. if (orderId && chooseReason && content) {
  27. return true;
  28. } else {
  29. return false;
  30. }
  31. }, [orderId, chooseReason, content, imgList]);
  32. function changeImg(img, index) {
  33. const list = [...imgList];
  34. if (!img) {
  35. list.splice(index, 1);
  36. } else {
  37. list.splice(index, 1, img);
  38. }
  39. if (index === list.length - 1 && list.length < 4) {
  40. list.push('');
  41. }
  42. setimgList(list);
  43. }
  44. function deleteImg(index) {
  45. const list = [...imgList];
  46. if (!list[index]) {
  47. return null;
  48. } else {
  49. return () => changeImg('', index);
  50. }
  51. }
  52. const onSubmit = () => {
  53. cancelOrder(orderId, chooseReason, content, imgList.join(',')).then(() => {
  54. navigation.goBack();
  55. });
  56. };
  57. return (
  58. <>
  59. <Header title={t('shen-qing-qu-xiao-ding-dan')} />
  60. <ScrollView
  61. contentContainerStyle={{
  62. flexGrow: 1,
  63. backgroundColor: '#eee',
  64. }}
  65. >
  66. <Div p={15} bg="white">
  67. <Text fontSize="xs" color="gray500">
  68. {t('tips1')}
  69. </Text>
  70. <Button
  71. fontSize="xs"
  72. bg="white"
  73. borderWidth={1}
  74. borderColor="brand500"
  75. color="black"
  76. mt={13}
  77. >
  78. {t('lian-xi-shang-jia')}
  79. </Button>
  80. </Div>
  81. <Div bg="white" mt={2} p={15}>
  82. <Text color="gray500" fontSize="xs">
  83. {t('nin-ru-guo-que-ding-qu-xiao')},
  84. <Text color="red500" fontSize="xs">
  85. {t('qing-wu-bi-tian-xie-zhen-shi-yuan-yin')}
  86. </Text>
  87. ,{t('yi-shi-wo-men-ke-yi-geng-hao-di-bang-nin-jie-jue-wen-ti')}。
  88. </Text>
  89. <Button
  90. block
  91. bg="white"
  92. px={0}
  93. my={5}
  94. onPress={() => {
  95. if (Platform.OS !== 'web') {
  96. const list = [...reasonMap.keys()];
  97. PullPicker.show(
  98. t('qu-xiao-yuan-yin'),
  99. list,
  100. chooseReason ? list.indexOf(chooseReason) : '',
  101. (item) => {
  102. setchooseReason(item);
  103. },
  104. {
  105. getItemText: (item) => {
  106. return reasonMap.get(item).name;
  107. },
  108. }
  109. );
  110. }
  111. }}
  112. >
  113. <Div flex={1} row>
  114. <Text color="gray500" fontSize="xs">
  115. {t('qu-xiao-yuan-yin')}
  116. </Text>
  117. <Text flex={1} textAlign="right" fontSize="xs" mx={10}>
  118. {chooseReason ? reasonMap.get(chooseReason).name : ''}
  119. </Text>
  120. <Icon name="right" />
  121. </Div>
  122. </Button>
  123. <Div borderWidth={1} borderColor="gray200" rounded="xs">
  124. <TextareaItem
  125. last
  126. rows={4}
  127. placeholder={t('tips2')}
  128. count={50}
  129. style={{
  130. backgroundColor: '#fff',
  131. paddingVertical: 10,
  132. fontSize: 10,
  133. borderBottomWidth: 0,
  134. }}
  135. onChange={setcontent}
  136. />
  137. </Div>
  138. <Div row py={10}>
  139. {imgList.map((item, index) => {
  140. return (
  141. <ImagePicker
  142. key={index}
  143. img={item}
  144. setImg={(img) => changeImg(img, index)}
  145. cancelEvent={deleteImg(index)}
  146. />
  147. );
  148. })}
  149. </Div>
  150. <Button
  151. w={160}
  152. color="black"
  153. fontSize="xs"
  154. borderWidth={1}
  155. borderColor="brand500"
  156. bg="white"
  157. alignSelf="center"
  158. disabled={!canSubmit}
  159. onPress={onSubmit}
  160. >
  161. {t('shen-qing-qu-xiao')}
  162. </Button>
  163. </Div>
  164. </ScrollView>
  165. </>
  166. );
  167. }