GoodsCard.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import React from "react";
  2. import { StyleSheet } from "react-native";
  3. import {
  4. Modal,
  5. Card,
  6. Text,
  7. Button,
  8. Layout,
  9. Avatar,
  10. Icon,
  11. } from "@ui-kitten/components";
  12. import { useModel } from "flooks";
  13. export default function GoodsCard(props) {
  14. const { add, remove } = useModel("wordsModel");
  15. const { info } = props;
  16. const { id, img, name, introduction, totalSales, discountAmount, amount } =
  17. info || {};
  18. return (
  19. <Card
  20. style={[!props.appearance && styles.card, props.style]}
  21. appearance={props.appearance || "goodsCard"}
  22. disabled={!props.canEdit}
  23. onPress={props.onPress}
  24. >
  25. {!!id ? (
  26. <Layout style={styles.layout}>
  27. <Avatar
  28. style={styles.avatar}
  29. shape='rounded'
  30. source={{
  31. uri: img,
  32. }}
  33. />
  34. <Layout style={styles.main}>
  35. <Text
  36. category='s1'
  37. ellipsizeMode='tail'
  38. numberOfLines={1}
  39. >
  40. {name || ""}
  41. </Text>
  42. <Text
  43. category='c1'
  44. status='info'
  45. ellipsizeMode='tail'
  46. numberOfLines={1}
  47. >
  48. {introduction || ""}
  49. </Text>
  50. <Text category='c1' status='info'>
  51. 月售 {totalSales || 0}
  52. </Text>
  53. <Layout style={styles.flex1} />
  54. <Text category='h6' status='danger'>
  55. ¥{discountAmount}{" "}
  56. <Text
  57. category='h1'
  58. status='info'
  59. style={{ textDecorationLine: "line-through" }}
  60. >
  61. ¥{amount}
  62. </Text>
  63. </Text>
  64. </Layout>
  65. {!props.appearance && !props.isAdd && (
  66. <Layout style={styles.butContent}>
  67. <Button
  68. status='primary'
  69. size='tiny'
  70. onPress={props.addEvent}
  71. >
  72. {add}
  73. </Button>
  74. </Layout>
  75. )}
  76. {!props.appearance && props.isAdd && (
  77. <Layout style={styles.butContent}>
  78. <Button
  79. status='danger'
  80. onPress={props.removeEvent}
  81. size='tiny'
  82. >
  83. {remove}
  84. </Button>
  85. </Layout>
  86. )}
  87. {props.appearance == "classification" &&
  88. props.type != "goodsList" && (
  89. <Button
  90. style={styles.miniButton}
  91. status='danger'
  92. accessoryLeft={StarIcon}
  93. />
  94. )}
  95. </Layout>
  96. ) : (
  97. <Layout style={styles.layout} />
  98. )}
  99. </Card>
  100. );
  101. }
  102. const StarIcon = (props) => <Icon {...props} name='minus-outline' />;
  103. const styles = StyleSheet.create({
  104. card: { marginTop: 10 },
  105. layout: {
  106. flexDirection: "row",
  107. height: 80,
  108. },
  109. avatar: {
  110. width: 80,
  111. height: 80,
  112. marginRight: 10,
  113. },
  114. main: {
  115. flex: 1,
  116. },
  117. flex1: {
  118. flex: 1,
  119. },
  120. butContent: {
  121. marginLeft: 6,
  122. },
  123. fontColor: {
  124. color: "#B5B5B5",
  125. },
  126. miniButton: {
  127. minWidth: 18,
  128. minHeight: 18,
  129. width: 18,
  130. height: 18,
  131. position: "absolute",
  132. right: 10,
  133. bottom: 5,
  134. },
  135. });