OrderCouponScreen.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 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, canUse, isChoose }) => {
  22. const navigation = useNavigation();
  23. return (
  24. <Div mt={10} mx={5}>
  25. <TouchableRipple
  26. disabled={!canUse}
  27. onPress={() => navigation.navigate('Home', { screen: 'Home' })}
  28. >
  29. <Div row bg="white" alignItems="center" pt={15} pr={15}>
  30. <Div minW={80} alignItems="center">
  31. <Text color={!canUse ? '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={!canUse ? '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. {canUse && (
  58. <Icon
  59. name="checkcircle"
  60. color={isChoose ? 'brand500' : 'gray200'}
  61. size={16}
  62. />
  63. )}
  64. </Div>
  65. <Div pb={15}>
  66. {isEnd && <Text mt={10}>优惠券已过期</Text>}
  67. {!isEnd && !canUse && <Text mt={10}>店铺不可用</Text>}
  68. </Div>
  69. </TouchableRipple>
  70. </Div>
  71. );
  72. };
  73. export default function OrderCouponScreen() {
  74. const {
  75. userCouponList,
  76. userCouponListHis,
  77. init,
  78. getBadList,
  79. } = useModel(userCoupon, ['userCouponList', 'userCouponListHis']);
  80. useRequest(init, {});
  81. useRequest(getBadList, {});
  82. return (
  83. <>
  84. <Header title="选择优惠券" />
  85. <ScrollView
  86. contentContainerStyle={{ flexGrow: 1, backgroundColor: '#eee' }}
  87. >
  88. {userCouponList.map((item) => {
  89. return <CounponItem key={item.id} info={item} canUse />;
  90. })}
  91. {userCouponList.length === 0 && (
  92. <Div p={10} alignItems="center">
  93. <Text textAlign="center">无可用优惠券</Text>
  94. </Div>
  95. )}
  96. {userCouponListHis.map((item) => {
  97. return <CounponItem key={item.id} info={item} isEnd canUse={false} />;
  98. })}
  99. </ScrollView>
  100. </>
  101. );
  102. }