OrderCouponScreen.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 { 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 { useTranslation } from 'react-i18next';
  9. import useModel from 'flooks';
  10. import userCoupon from './model'; // 优惠券模块
  11. import Header from '../../components/Header';
  12. const counpon = {
  13. amount: 18,
  14. enabled: true,
  15. endDate: '2022-12-11',
  16. fullAmount: 50,
  17. id: 744,
  18. merchantId: 189,
  19. name: '六一优惠',
  20. startDate: '2022-12-08',
  21. };
  22. const CounponItem = ({ info, isEnd, canUse, isChoose }) => {
  23. const { t } = useTranslation();
  24. const navigation = useNavigation();
  25. return (
  26. <Div mt={10} mx={5}>
  27. <TouchableRipple
  28. disabled={!canUse}
  29. onPress={() => navigation.navigate('Home', { screen: 'Home' })}
  30. >
  31. <Div row bg="white" alignItems="center" pt={15} pr={15}>
  32. <Div minW={80} alignItems="center">
  33. <Text color={!canUse ? 'gray400' : 'red500'} fontSize="xl">
  34. ¥{counpon.amount}
  35. </Text>
  36. {counpon.fullAmount > 0 && (
  37. <Text fontSize="xs" color="gray300" textAlign="left">
  38. {t('man')}
  39. {counpon.fullAmount}
  40. {t('yuan-ke-yong')}
  41. </Text>
  42. )}
  43. {counpon.fullAmount === 0 && (
  44. <Text fontSize="xs" color="gray300" textAlign="left">
  45. {t('wu-jinemen-jian')}
  46. </Text>
  47. )}
  48. </Div>
  49. <Div flex={1}>
  50. <Text
  51. color={!canUse ? 'gray400' : 'black'}
  52. fontSize="xl"
  53. fontWeight="bold"
  54. >
  55. {counpon.name}
  56. </Text>
  57. <Text fontSize="xs" color="gray300" textAlign="left">
  58. {t('xian')}
  59. {counpon.startDate}
  60. {t('zhi')}
  61. {counpon.endDate}
  62. {t('shi-yong')}
  63. </Text>
  64. </Div>
  65. {canUse && (
  66. <Icon
  67. name="checkcircle"
  68. color={isChoose ? 'brand500' : 'gray200'}
  69. size={16}
  70. />
  71. )}
  72. </Div>
  73. <Div pb={15}>
  74. {isEnd && <Text mt={10}>{t('you-hui-quan-yi-guo-qi')}</Text>}
  75. {!isEnd && !canUse && <Text mt={10}>{t('dian-pu-bu-ke-yong')}</Text>}
  76. </Div>
  77. </TouchableRipple>
  78. </Div>
  79. );
  80. };
  81. export default function OrderCouponScreen() {
  82. const {
  83. userCouponList,
  84. userCouponListHis,
  85. init,
  86. getBadList,
  87. } = useModel(userCoupon, ['userCouponList', 'userCouponListHis']);
  88. useRequest(init, {});
  89. useRequest(getBadList, {});
  90. const { t } = useTranslation();
  91. return (
  92. <>
  93. <Header title={t('xuan-ze-you-hui-quan')} />
  94. <ScrollView
  95. contentContainerStyle={{ flexGrow: 1, backgroundColor: '#eee' }}
  96. >
  97. {userCouponList.map((item) => {
  98. return <CounponItem key={item.id} info={item} canUse />;
  99. })}
  100. {userCouponList.length === 0 && (
  101. <Div p={10} alignItems="center">
  102. <Text textAlign="center">{t('wu-ke-yong-you-hui-quan')}</Text>
  103. </Div>
  104. )}
  105. {userCouponListHis.map((item) => {
  106. return <CounponItem key={item.id} info={item} isEnd canUse={false} />;
  107. })}
  108. </ScrollView>
  109. </>
  110. );
  111. }