GoodsCard.js 6.8 KB

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