ClassificationList.jsx 3.3 KB

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