listScreen.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import * as WebBrowser from "expo-web-browser";
  2. import * as React from "react";
  3. import { StyleSheet, View } from "react-native";
  4. import { useModel } from "flooks";
  5. import { useTheme, Button } from "@ui-kitten/components";
  6. import { useFocusEffect } from "@react-navigation/native";
  7. import NavHeaderBar from "../../components/NavHeaderBar";
  8. import Coupon from "../../components/Coupon";
  9. import ListComponent from "../../components/ListComponent";
  10. const styles = StyleSheet.create({
  11. top: {
  12. alignItems: "center",
  13. paddingVertical: 10,
  14. marginBottom: 10,
  15. },
  16. list: {
  17. flex: 1,
  18. backgroundColor: "rgb(242, 242, 242)",
  19. paddingHorizontal: 15,
  20. },
  21. separatorStyle: {
  22. marginHorizontal: 13,
  23. },
  24. });
  25. export default function CouponListScreen({ navigation }) {
  26. const theme = useTheme();
  27. const { changeBackground } = useModel("barModel");
  28. // const {} = useModel("wordsModel");
  29. const { getMyList, delCoupon } = useModel("couponModel");
  30. const [startState, changeStart] = React.useState(false);
  31. useFocusEffect(
  32. React.useCallback(() => {
  33. changeBackground(theme["color-primary-500"]);
  34. changeStart(true);
  35. }, [])
  36. );
  37. function getList(page, size) {
  38. return getMyList(page, size).then(res => {
  39. changeStart(false);
  40. return Promise.resolve(res);
  41. });
  42. }
  43. const walletItem = ({ item, index }) => (
  44. <Coupon
  45. key={index}
  46. info={item}
  47. delEvent={() => {
  48. delCoupon(item.id, () => {
  49. changeStart(true);
  50. });
  51. }}
  52. onPress={() => {
  53. navigation.navigate("CouponAdd", {
  54. id: item.id,
  55. });
  56. }}
  57. />
  58. );
  59. return (
  60. <>
  61. <NavHeaderBar title="优惠券管理" />
  62. <View style={styles.top}>
  63. <Button
  64. appearance="outline"
  65. onPress={() => {
  66. navigation.navigate("CouponAdd");
  67. }}
  68. >
  69. 新增优惠券
  70. </Button>
  71. </View>
  72. <ListComponent
  73. getInfo={getList}
  74. renderItem={walletItem}
  75. style={styles.list}
  76. separatorStyle={styles.separatorStyle}
  77. showEmpty
  78. startState={startState}
  79. />
  80. </>
  81. );
  82. }