ClassificationList.jsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { Div, Image, Text, Button } from 'react-native-magnus';
  4. import { useRequest, useCreation } from '@umijs/hooks';
  5. import { useNavigation } from '@react-navigation/native';
  6. import useModel from 'flooks';
  7. import Detail from './model';
  8. import Plus from '../../components/Plus';
  9. function Item({ info, cartMap, checkgoodsSpecification, changeNum, goDetail }) {
  10. return (
  11. <Button bg="hide" p={0} onPress={goDetail} block>
  12. <Div py={5} px={10} row bg="white" flex={1}>
  13. <Image
  14. w={70}
  15. h={70}
  16. bg="gray200"
  17. rounded="sm"
  18. source={{ uri: info.img }}
  19. />
  20. <Div flex={1} ml={5}>
  21. <Text textAlign="left">{info.name}</Text>
  22. <Text color="gray300" fontSize="xs" textAlign="left">
  23. {info.introduction}
  24. </Text>
  25. <Text color="gray300" fontSize="xs" textAlign="left">
  26. 月售{info.inventory || 0}
  27. </Text>
  28. <Div flex={1} />
  29. <Div row alignItems="center">
  30. <Text color="red500" textAlign="left">
  31. ¥{info.discountAmount || info.amount}
  32. </Text>
  33. {!!info.discountAmount && (
  34. <Text
  35. color="gray300"
  36. ml={5}
  37. fontSize="xs"
  38. textDecorLine="line-through"
  39. textDecorColor="gray300"
  40. textAlign="left"
  41. >
  42. ¥{info.amount}
  43. </Text>
  44. )}
  45. <Div flex={1} />
  46. <Plus
  47. num={cartMap.has(info.id) ? cartMap.get(info.id).num : 0}
  48. minus={() => {
  49. changeNum(
  50. cartMap.get(info.id).specIds,
  51. cartMap.get(info.id).num - 1
  52. );
  53. }}
  54. plusEvent={() => checkgoodsSpecification(info)}
  55. />
  56. </Div>
  57. </Div>
  58. </Div>
  59. </Button>
  60. );
  61. }
  62. export default function ClassificationList() {
  63. const navigation = useNavigation();
  64. const {
  65. selectClass,
  66. cartMap,
  67. checkgoodsSpecification,
  68. changeNum,
  69. goodsList,
  70. } = useModel(Detail, ['selectClass', 'cartMap', 'goodsList']);
  71. const [typegoodsList, setgoodsList] = React.useState([]);
  72. const classificationRequest = useRequest(
  73. `/classification/allGoods?classificationId=${selectClass}`,
  74. {
  75. manual: true,
  76. onSuccess: (result) => {
  77. // scroll.scrollToOffset(0);
  78. setgoodsList(
  79. result.filter((item) => {
  80. return item;
  81. }) || []
  82. );
  83. },
  84. }
  85. );
  86. const showList = useCreation(() => {
  87. return typegoodsList.filter((item) => {
  88. return goodsList.find((goods) => {
  89. return goods.id === item.id;
  90. });
  91. });
  92. }, [goodsList, typegoodsList]);
  93. React.useEffect(() => {
  94. if (selectClass) {
  95. classificationRequest.run();
  96. }
  97. }, [selectClass]);
  98. // classification;
  99. return (
  100. <Div flex={1} bg="white" pb={100}>
  101. {showList.map((item) => {
  102. return (
  103. <Item
  104. key={item.id}
  105. info={item}
  106. cartMap={cartMap}
  107. checkgoodsSpecification={checkgoodsSpecification}
  108. changeNum={changeNum}
  109. goDetail={() =>
  110. navigation.navigate('GoodsDetail', {
  111. goodsId: item.id,
  112. })
  113. }
  114. />
  115. );
  116. })}
  117. {showList.length === 0 && (
  118. <Div px={10} py={20}>
  119. <Text color="gray300" textAlign="center">
  120. 暂无数据
  121. </Text>
  122. </Div>
  123. )}
  124. </Div>
  125. );
  126. }