GoodsCard.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import React from "react";
  2. import { StyleSheet, View } from "react-native";
  3. import { Card, Text, Button, Avatar } from "@ui-kitten/components";
  4. import { useModel } from "flooks";
  5. const styles = StyleSheet.create({
  6. card: { marginTop: 10 },
  7. layout: {
  8. flexDirection: "row",
  9. height: 80,
  10. backgroundColor: "transparent",
  11. },
  12. avatar: {
  13. width: 80,
  14. height: 80,
  15. marginRight: 10,
  16. },
  17. main: {
  18. flex: 1,
  19. backgroundColor: "transparent",
  20. },
  21. flex1: {
  22. flex: 1,
  23. },
  24. butContent: {
  25. marginLeft: 6,
  26. },
  27. fontColor: {
  28. color: "#B5B5B5",
  29. },
  30. miniButton: {
  31. minWidth: 22,
  32. minHeight: 22,
  33. width: 22,
  34. height: 22,
  35. position: "absolute",
  36. right: 10,
  37. bottom: 5,
  38. maxWidth: 22,
  39. },
  40. status: {
  41. position: "absolute",
  42. left: 0,
  43. width: 80,
  44. paddingVertical: 4,
  45. backgroundColor: "#F0F0F0",
  46. bottom: 0,
  47. textAlign: "center",
  48. },
  49. });
  50. export default function GoodsCard(props) {
  51. const { add, remove, getWordsStr } = useModel("wordsModel");
  52. const {
  53. info,
  54. changeInfo,
  55. type,
  56. removeEvent,
  57. addEvent,
  58. isAdd,
  59. appearance,
  60. style,
  61. canEdit,
  62. onPress,
  63. } = props;
  64. const {
  65. id,
  66. img,
  67. name,
  68. introduction,
  69. totalSales,
  70. discountAmount,
  71. amount,
  72. takeOff,
  73. status,
  74. } = info || {};
  75. const { takeOffInfo, ChangeTakeOff } = useModel("goodsModel", true);
  76. return (
  77. <Card
  78. style={[!appearance && styles.card, style]}
  79. appearance={appearance || "goodsCard"}
  80. disabled={!canEdit}
  81. onPress={onPress}
  82. >
  83. {id ? (
  84. <View style={styles.layout}>
  85. <Avatar
  86. style={styles.avatar}
  87. shape="rounded"
  88. source={{
  89. uri: img,
  90. }}
  91. />
  92. {status === "PENDING" && (
  93. <Text style={styles.status} category="h1">
  94. 待审核
  95. </Text>
  96. )}
  97. {status === "DENY" && (
  98. <Text style={styles.status} category="h1" status="danger">
  99. 审核未通过
  100. </Text>
  101. )}
  102. <View style={styles.main}>
  103. <Text category="s1" ellipsizeMode="tail" numberOfLines={1}>
  104. {name || ""}
  105. </Text>
  106. <Text
  107. category="c1"
  108. status="info"
  109. ellipsizeMode="tail"
  110. numberOfLines={1}
  111. >
  112. {introduction || ""}
  113. </Text>
  114. <Text category="c1" status="info">
  115. 月售 {totalSales || 0}
  116. </Text>
  117. <View style={styles.flex1} />
  118. <Text category="h6" status="danger">
  119. ¥{discountAmount}{" "}
  120. <Text
  121. category="h1"
  122. status="info"
  123. style={{ textDecorationLine: "line-through" }}
  124. >
  125. ¥{amount}
  126. </Text>
  127. </Text>
  128. </View>
  129. {appearance && type === "goodsList" && (
  130. <View style={styles.butContent}>
  131. <Button
  132. status="primary"
  133. size="small"
  134. appearance="outline"
  135. onPress={() => {
  136. if (!takeOff) {
  137. takeOffInfo(() => {
  138. ChangeTakeOff(info).then(res => {
  139. changeInfo(res);
  140. });
  141. });
  142. } else {
  143. ChangeTakeOff(info).then(res => {
  144. changeInfo(res);
  145. });
  146. }
  147. }}
  148. >
  149. {getWordsStr(takeOff ? "takeUp" : "takeOff")}
  150. </Button>
  151. </View>
  152. )}
  153. {!appearance && !isAdd && (
  154. <View style={styles.butContent}>
  155. <Button status="primary" size="tiny" onPress={addEvent}>
  156. {add}
  157. </Button>
  158. </View>
  159. )}
  160. {appearance && isAdd && (
  161. <View style={styles.butContent}>
  162. <Button status="danger" onPress={removeEvent} size="tiny">
  163. {remove}
  164. </Button>
  165. </View>
  166. )}
  167. {/* {props.appearance == "classification" &&
  168. props.type != "goodsList" && (
  169. <Button
  170. style={styles.miniButton}
  171. status='danger'
  172. onPress={props.removeEvent}
  173. accessoryLeft={StarIcon}
  174. />
  175. )} */}
  176. </View>
  177. ) : (
  178. <View style={styles.layout} />
  179. )}
  180. </Card>
  181. );
  182. }