CouponScreen.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { Div, Button, Image, Text, Avatar } from 'react-native-magnus';
  4. import { TouchableRipple } from 'react-native-paper';
  5. import { ScrollView } from 'react-native-gesture-handler';
  6. import { useNavigation } from '@react-navigation/native';
  7. import { useRequest } from '@umijs/hooks';
  8. import useModel from 'flooks';
  9. import userCoupon from './model'; // 优惠券模块
  10. import Header from '../../components/Header';
  11. const counpon = {
  12. amount: 18,
  13. enabled: true,
  14. endDate: '2022-12-11',
  15. fullAmount: 50,
  16. id: 744,
  17. merchantId: 189,
  18. name: '六一优惠',
  19. startDate: '2022-12-08',
  20. };
  21. const CounponItem = ({ info, isEnd }) => {
  22. const navigation = useNavigation();
  23. return (
  24. <Div mt={10} mx={5}>
  25. <TouchableRipple
  26. disabled={isEnd}
  27. onPress={() => navigation.navigate('Home', { screen: 'Home' })}
  28. >
  29. <Div row bg="white" alignItems="center" py={15} pr={15}>
  30. <Div minW={80} alignItems="center">
  31. <Text color={isEnd ? 'gray400' : 'red500'} fontSize="xl">
  32. ¥{counpon.amount}
  33. </Text>
  34. {counpon.fullAmount > 0 && (
  35. <Text fontSize="xs" color="gray300" textAlign="left">
  36. 满{counpon.fullAmount}元可用
  37. </Text>
  38. )}
  39. {counpon.fullAmount === 0 && (
  40. <Text fontSize="xs" color="gray300" textAlign="left">
  41. 无金额门槛
  42. </Text>
  43. )}
  44. </Div>
  45. <Div flex={1}>
  46. <Text
  47. color={isEnd ? 'gray400' : 'black'}
  48. fontSize="xl"
  49. fontWeight="bold"
  50. >
  51. {counpon.name}
  52. </Text>
  53. <Text fontSize="xs" color="gray300" textAlign="left">
  54. 限{counpon.startDate}至{counpon.endDate}使用
  55. </Text>
  56. </Div>
  57. {isEnd ? (
  58. <Text color="gray500" fontSize="sm" textAlign="left">
  59. 已过期
  60. </Text>
  61. ) : (
  62. <Text color="gray500" fontSize="sm" textAlign="left">
  63. 去使用
  64. </Text>
  65. )}
  66. </Div>
  67. </TouchableRipple>
  68. </Div>
  69. );
  70. };
  71. export default function CouponScreen() {
  72. const {
  73. userCouponList,
  74. userCouponListHis,
  75. init,
  76. getBadList,
  77. } = useModel(userCoupon, ['userCouponList', 'userCouponListHis']);
  78. useRequest(init, {});
  79. useRequest(getBadList, {});
  80. return (
  81. <>
  82. <Header title="红包卡券" />
  83. <ScrollView>
  84. {userCouponList.map((item) => {
  85. return <CounponItem key={item.id} info={item} />;
  86. })}
  87. {userCouponList.length === 0 && userCouponListHis.length === 0 && (
  88. <Div p={10} alignItems="center">
  89. <Text>暂无数据</Text>
  90. </Div>
  91. )}
  92. {userCouponListHis.map((item) => {
  93. return <CounponItem key={item.id} info={item} isEnd />;
  94. })}
  95. </ScrollView>
  96. </>
  97. );
  98. }