PayCom.jsx 3.1 KB

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