Comment.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import * as WebBrowser from "expo-web-browser";
  2. import * as React from "react";
  3. import { Div, Image, Text, Icon, Tag } from "react-native-magnus";
  4. import { useRequest } from "@umijs/hooks";
  5. import { useModel } from "flooks";
  6. const AppraisalSortMap = new Map([
  7. [
  8. "ALL",
  9. {
  10. name: "全部",
  11. },
  12. ],
  13. [
  14. "LATEST",
  15. {
  16. name: "最新",
  17. },
  18. ],
  19. [
  20. "PRAISE",
  21. {
  22. name: "好评",
  23. },
  24. ],
  25. [
  26. "BAD_REVIEW",
  27. {
  28. name: "差评",
  29. isBad: true,
  30. },
  31. ],
  32. [
  33. "HAVE_PIC",
  34. {
  35. name: "有图",
  36. },
  37. ],
  38. ]);
  39. const CommentItem = ({ info }) => {
  40. const imgs = info.img ? info.img.split(",") : [];
  41. const imageSize = imgs.length > 1 ? 80 : 167;
  42. return (
  43. <Div row py={10} px={15} bg="white" mt={10}>
  44. <Image source={{ uri: info.avatar }} w={33} h={33} />
  45. <Div flex={1} ml={5}>
  46. <Div row>
  47. <Div flex={1}>
  48. <Text fontSize="sm" textAlign="left">
  49. {info.nickname}
  50. </Text>
  51. <Div row>
  52. <Icon name="like1" color="yellow500" />
  53. <Text fontSize="sm" color="yellow500" textAlign="left">
  54. {info.likes || 0}
  55. </Text>
  56. </Div>
  57. </Div>
  58. <Text fontSize="sm" color="gray400" textAlign="left">
  59. {info.appraiseTime}
  60. </Text>
  61. </Div>
  62. <Text my={5} textAlign="left">
  63. {info.goodsAppraise}
  64. </Text>
  65. <Div row>
  66. {imgs.map((item, index) => {
  67. return (
  68. <Image
  69. key={index}
  70. mt={5}
  71. mr={5}
  72. source={{ uri: item }}
  73. w={imageSize}
  74. h={imageSize}
  75. rounded={3}
  76. />
  77. );
  78. })}
  79. </Div>
  80. </Div>
  81. </Div>
  82. );
  83. };
  84. export default function Comment() {
  85. const { mid } = useModel("userModel");
  86. const { httpGet } = useModel("httpModel");
  87. const [comments, setcomments] = React.useState([]);
  88. const [appraisalSort, setappraisalSort] = React.useState("ALL");
  89. useRequest(
  90. () => {
  91. return httpGet(
  92. `/appraisal/my?merchantId=${mid}&appraisalSort=${appraisalSort}`
  93. );
  94. },
  95. {
  96. refreshDeps: [mid, appraisalSort],
  97. onSuccess: result => {
  98. setcomments(result);
  99. },
  100. }
  101. );
  102. return (
  103. <Div flex={1} bg="gray100">
  104. <Div row p={15}>
  105. {[...AppraisalSortMap.keys()].map(item => {
  106. const info = AppraisalSortMap.get(item);
  107. const isChoose = appraisalSort === item;
  108. return (
  109. <Tag
  110. key={item}
  111. bg={isChoose ? "yellow500" : info.isBad ? "gray200" : "yellow100"}
  112. color={isChoose ? "white" : info.isBad ? "gray500" : "yellow500"}
  113. fontSize="sm"
  114. mr={5}
  115. mb={5}
  116. onPress={() => setappraisalSort(item)}
  117. >
  118. {info.name}
  119. </Tag>
  120. );
  121. })}
  122. </Div>
  123. {comments.map(item => {
  124. return <CommentItem info={item} key={item.goodsAppraise} />;
  125. })}
  126. {comments.length === 0 && (
  127. <Div px={10} py={20}>
  128. <Text color="gray300" textAlign="center">
  129. 暂无数据
  130. </Text>
  131. </Div>
  132. )}
  133. </Div>
  134. );
  135. }