SubmitScreen.jsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { Div, Button, Image, Text, Avatar, Icon } from 'react-native-magnus';
  4. import { ScrollView } from 'react-native-gesture-handler';
  5. import { Picker } from '@ant-design/react-native';
  6. import Constants from 'expo-constants';
  7. import { useCreation, useRequest } from '@umijs/hooks';
  8. import { useRoute, useNavigation } from '@react-navigation/native';
  9. import useModel from 'flooks';
  10. import Detail from './model';
  11. import AddressModel from '../Address/model';
  12. import Order from '../Order/model';
  13. import Header from './DetailHeader';
  14. import TablewareCom from './TablewareCom'; //餐具
  15. import AddressCom from '../Address/AddressCom';
  16. import PayCom from '../Pay/PayCom';
  17. import Time from '../../Utils/TimeUtils';
  18. import { accAdd, accMul } from '../../Utils/NumberUtils';
  19. const Cart = ({ info }) => {
  20. const { goods } = info;
  21. return (
  22. <Div row py={5}>
  23. <Image w={40} h={40} source={{ uri: goods.img }} />
  24. <Div flex={1} ml={10}>
  25. <Div row>
  26. <Text>{goods.name}</Text>
  27. <Div flex={1} />
  28. <Text>X{info.num}</Text>
  29. <Text ml={10}>{info.goodsRealPrice}</Text>
  30. </Div>
  31. <Text fontSize="xs" color="gray300" textAlign="left">
  32. {info.specification}
  33. </Text>
  34. </Div>
  35. </Div>
  36. );
  37. };
  38. export default function SubmitScreen() {
  39. const {
  40. merchantInfo,
  41. getCart,
  42. remark,
  43. payMethod,
  44. cartRefreash,
  45. cartMoneyInfo,
  46. } = useModel(Detail, [
  47. 'merchantInfo',
  48. 'remark',
  49. 'payMethod',
  50. 'cartMoneyInfo',
  51. ]);
  52. const { chooseAddressId } = useModel(AddressModel, ['chooseAddressId']);
  53. const { submitOrder, payOrder } = useModel(Order, []);
  54. const route = useRoute();
  55. const navigation = useNavigation();
  56. const { params } = route;
  57. const {
  58. deliveryAmount,
  59. fullReduction,
  60. packingPrice,
  61. firstBuy,
  62. realAmount,
  63. } = cartMoneyInfo;
  64. const { banner, preparationTime, showName } = merchantInfo;
  65. const [cartList, setcartList] = React.useState([]);
  66. const [chooseTime, setChooseTime] = React.useState([]);
  67. const pickerRef = React.createRef();
  68. const cartRequest = useRequest(getCart, {
  69. refreshDeps: [params],
  70. onSuccess: (result) => {
  71. const value = result || [];
  72. setcartList(value);
  73. },
  74. });
  75. const time = useCreation(() => {
  76. return new Time().addTime(preparationTime / 60, 'HH:mm');
  77. }, [preparationTime]);
  78. const timeList = useCreation(() => {
  79. return [
  80. {
  81. label: `立即送出约(${time})`,
  82. value: time,
  83. },
  84. ].concat(
  85. new Time().nextList().map((item) => {
  86. return { value: item, label: item };
  87. })
  88. );
  89. }, [preparationTime, time]);
  90. const canSub = useCreation(() => {
  91. if (chooseAddressId && cartList.length > 0) {
  92. return true;
  93. } else {
  94. return false;
  95. }
  96. }, [cartList, chooseAddressId]);
  97. return (
  98. <>
  99. <Header noRight noTab />
  100. <ScrollView
  101. contentContainerStyle={{ flexGrow: 1, backgroundColor: '#eee' }}
  102. >
  103. <Image
  104. position="absolute"
  105. left={0}
  106. top={0}
  107. right={0}
  108. h={118 + Constants.statusBarHeight}
  109. source={{ uri: banner }}
  110. />
  111. <Div mx={15} mt={90} px={10} bg="white" rounded="sm">
  112. <AddressCom />
  113. <Div row alignItems="center" h={35}>
  114. <Text fontSize="xl" textAlign="left">
  115. {chooseTime.length > 0 && chooseTime[0] !== time
  116. ? '指定时间'
  117. : '立即送出'}
  118. </Text>
  119. <Div flex={1} />
  120. <Picker
  121. ref={pickerRef}
  122. data={timeList}
  123. cols={1}
  124. value={chooseTime}
  125. onChange={setChooseTime}
  126. itemStyle={{ paddingVertical: 10 }}
  127. >
  128. <Button bg="white" color="brand500" fontSize="xl" mr={5}>
  129. {chooseTime.length > 0 && chooseTime[0] !== time
  130. ? `${chooseTime[0]}送达`
  131. : `约${time}到达`}
  132. </Button>
  133. </Picker>
  134. <Icon name="right" color="#000" />
  135. </Div>
  136. <Div h={1} bg="gray200" />
  137. <PayCom />
  138. </Div>
  139. <Div mx={15} my={10} px={10} bg="white" rounded="sm">
  140. <Div row alignItems="center" h={46}>
  141. <Text fontSize="xl" fontWeight="bold" textAlign="left">
  142. {showName}
  143. </Text>
  144. </Div>
  145. <Div h={1} bg="gray200" mb={5} />
  146. {cartList.map((item) => {
  147. return <Cart key={item.id} info={item} />;
  148. })}
  149. <Div row mt={10}>
  150. <Text fontSize="xs" color="gray300" textAlign="left">
  151. 包装费 餐盒
  152. </Text>
  153. <Div flex={1} />
  154. <Text fontSize="xs" color="gray300" textAlign="left">
  155. ¥{packingPrice}
  156. </Text>
  157. </Div>
  158. <Div row mt={10}>
  159. <Text fontSize="xs" color="gray300" textAlign="left">
  160. 配送费
  161. </Text>
  162. <Div flex={1} />
  163. <Text fontSize="xs" color="gray300" textAlign="left">
  164. ¥{deliveryAmount}
  165. </Text>
  166. </Div>
  167. <Div row mt={10}>
  168. <Text fontSize="xs" color="gray300" textAlign="left">
  169. 满减
  170. </Text>
  171. <Div flex={1} />
  172. <Text fontSize="xs" color="red500" textAlign="left">
  173. -¥{fullReduction}
  174. </Text>
  175. </Div>
  176. {firstBuy !== 0 && (
  177. <Div row mt={10}>
  178. <Text fontSize="xs" color="gray300" textAlign="left">
  179. 首单
  180. </Text>
  181. <Div flex={1} />
  182. <Text fontSize="xs" color="red500" textAlign="left">
  183. -¥{firstBuy}
  184. </Text>
  185. </Div>
  186. )}
  187. <Div h={1} bg="gray200" mt={5} />
  188. <Button
  189. block
  190. p="none"
  191. bg="hide"
  192. onPress={() => navigation.navigate('OrderCoupon')}
  193. >
  194. <Div flex={1} row py={10} alignItems="center">
  195. <Text color="gray500" fontSize="xl" textAlign="left">
  196. 红包
  197. </Text>
  198. <Div flex={1} />
  199. <Text fontSize="xs" color="gray300" mr={15} textAlign="left">
  200. 暂无可用
  201. </Text>
  202. <Icon name="right" color="#000" />
  203. </Div>
  204. </Button>
  205. <Div h={1} bg="gray200" />
  206. <Div row pt={10} pb={20}>
  207. <Div flex={1} />
  208. <Text fontSize="xl" textAlign="left">
  209. 小计
  210. </Text>
  211. <Text fontSize="xl" ml={20} textAlign="left">
  212. ¥{realAmount}
  213. </Text>
  214. </Div>
  215. </Div>
  216. <Div bg="white" mx={15} my={10} px={10} rounded="sm">
  217. <Button
  218. bg="hide"
  219. block
  220. p="none"
  221. onPress={() => navigation.navigate('OrderMessage')}
  222. >
  223. <Div row flex={1} py={10} alignItems="center">
  224. <Text fontSize="xl">订单备注</Text>
  225. <Text
  226. fontSize="sm"
  227. ml={10}
  228. color="gray300"
  229. textAlign="right"
  230. flex={1}
  231. numberOfLines={1}
  232. ellipsizeMode="tail"
  233. >
  234. {remark}
  235. </Text>
  236. <Icon name="right" />
  237. </Div>
  238. </Button>
  239. <TablewareCom />
  240. </Div>
  241. <Button
  242. disabled={!canSub}
  243. bg="brand500"
  244. color="white"
  245. block
  246. mx={15}
  247. mt={10}
  248. my={20}
  249. onPress={() => {
  250. const ids = cartList.map((item) => {
  251. return item.shoppingCartId;
  252. });
  253. submitOrder(ids[0], chooseAddressId, payMethod, remark)
  254. .then((res) => {
  255. cartRefreash();
  256. return payOrder(res.id).then(() => {
  257. return Promise.resolve(res.id);
  258. });
  259. })
  260. .then((id) => {
  261. navigation.replace('OrderDetail', { orderId: id });
  262. });
  263. }}
  264. >
  265. 支付
  266. </Button>
  267. </ScrollView>
  268. </>
  269. );
  270. }