PayCom.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { Div, Button, Text, Icon } from 'react-native-magnus';
  4. import { Modal, Portal } from 'react-native-paper';
  5. import { useTranslation } from 'react-i18next';
  6. import useModel from 'flooks';
  7. import Detail from '../Detail/model';
  8. const payMap = new Map([
  9. [
  10. 'ALI_PAY',
  11. {
  12. name: '支付宝',
  13. icon: 'alipay-square',
  14. iconColor: 'blue500',
  15. },
  16. ],
  17. [
  18. 'CASH_DELIVERY',
  19. {
  20. name: '货到付款',
  21. icon: 'wallet',
  22. iconColor: 'green500',
  23. },
  24. ],
  25. [
  26. 'CREDIT_CARD',
  27. {
  28. name: '信用卡',
  29. icon: 'creditcard',
  30. iconColor: 'red500',
  31. },
  32. ],
  33. ]);
  34. const PayImtem = ({ mapKey, isChoose, changePay }) => {
  35. const info = payMap.get(mapKey);
  36. return (
  37. <>
  38. <Div h={1} bg="gray200" />
  39. <Button block bg="white" p="none" onPress={() => changePay(mapKey)}>
  40. <Div row flex={1} alignItems="center" h={54}>
  41. <Icon name={info.icon} color={info.iconColor} fontSize="5xl" />
  42. <Text textAlign="left" flex={1} ml={20}>
  43. {info.name}
  44. </Text>
  45. <Icon
  46. name="checkcircle"
  47. color={isChoose ? 'brand500' : 'gray200'}
  48. size={16}
  49. />
  50. </Div>
  51. </Button>
  52. </>
  53. );
  54. };
  55. export default function PayCom() {
  56. const { t } = useTranslation();
  57. const [visible, changeVisible] = React.useState(false);
  58. const { payMethod, merchantInfo, changePay } = useModel(Detail, [
  59. 'payMethod',
  60. 'merchantInfo',
  61. ]);
  62. const { showName } = merchantInfo;
  63. return (
  64. <>
  65. <Button block bg="white" p="none" onPress={() => changeVisible(true)}>
  66. <Div row flex={1} alignItems="center" h={40}>
  67. <Text fontSize="xl" textAlign="left">
  68. {t('zhi-fu-fang-shi')}
  69. </Text>
  70. <Div flex={1} />
  71. <Text color="brand500" fontSize="xl" mr={5} textAlign="left">
  72. {payMap.has(payMethod)
  73. ? payMap.get(payMethod).name
  74. : t('qing-xuan-ze')}
  75. </Text>
  76. <Icon name="right" color="#000" />
  77. </Div>
  78. </Button>
  79. <Portal>
  80. <Modal
  81. visible={visible}
  82. onDismiss={() => changeVisible(false)}
  83. contentContainerStyle={{
  84. position: 'absolute',
  85. left: 0,
  86. right: 0,
  87. bottom: 0,
  88. maxHeight: '70%',
  89. zIndex: 2,
  90. justifyContent: 'flex-end',
  91. }}
  92. >
  93. <Div bg="white" px={15} mt={56} pb={80}>
  94. <Div py={15}>
  95. <Text textAlign="center">{showName}</Text>
  96. </Div>
  97. {[...payMap.keys()].map((item) => {
  98. return (
  99. <PayImtem
  100. key={item}
  101. mapKey={item}
  102. isChoose={item === payMethod}
  103. changePay={(method) => {
  104. changePay(method);
  105. changeVisible(false);
  106. }}
  107. />
  108. );
  109. })}
  110. </Div>
  111. </Modal>
  112. </Portal>
  113. </>
  114. );
  115. }