EditGoods.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* eslint-disable no-underscore-dangle */
  2. import * as WebBrowser from "expo-web-browser";
  3. import * as React from "react";
  4. import { StyleSheet } from "react-native";
  5. import { Layout, useTheme, Button, List } from "@ui-kitten/components";
  6. import { useModel } from "flooks";
  7. import { useFocusEffect } from "@react-navigation/native";
  8. import NavHeaderBar from "../components/NavHeaderBar";
  9. import GoodsCardLarge from "../components/GoodsCard";
  10. import EmptyComponent from "../components/EmptyComponent";
  11. const styles = StyleSheet.create({
  12. container: {
  13. flex: 1,
  14. },
  15. bntLay: {
  16. paddingVertical: 5,
  17. flexDirection: "row",
  18. alignItems: "center",
  19. justifyContent: "center",
  20. backgroundColor: "#EEEEEE",
  21. flexShrink: 0,
  22. },
  23. list: {
  24. flex: 1,
  25. backgroundColor: "#EEEEEE",
  26. paddingTop: 10,
  27. paddingHorizontal: 15,
  28. },
  29. });
  30. export default function EditGoods({ navigation }) {
  31. const theme = useTheme();
  32. const { changeBackground } = useModel("barModel");
  33. // const { } = useModel("userModel");
  34. const { httpGet } = useModel("httpModel");
  35. const [goods, changeGoods] = React.useState("");
  36. const { userTitle3, addGoods2 } = useModel("wordsModel");
  37. function getAllGoods() {
  38. httpGet("/goods/my").then(res => {
  39. changeGoods(res);
  40. });
  41. }
  42. useFocusEffect(
  43. React.useCallback(() => {
  44. changeBackground(theme["color-primary-500"]);
  45. getAllGoods();
  46. }, [])
  47. );
  48. const goodsItem = ({ item, index }) => (
  49. <GoodsCardLarge
  50. appearance="classification"
  51. type="goodsList"
  52. key={item.id}
  53. info={item}
  54. canEdit
  55. style={{ marginBottom: 7 }}
  56. onPress={() => {
  57. navigation.navigate("GoodsDetailMore", {
  58. goodsId: item.id,
  59. });
  60. }}
  61. changeInfo={info => {
  62. const _goods = [...goods];
  63. _goods.splice(index, 1, info);
  64. changeGoods(_goods);
  65. }}
  66. />
  67. );
  68. return (
  69. <>
  70. <NavHeaderBar title={userTitle3} />
  71. <Layout style={styles.container}>
  72. <Layout style={styles.bntLay}>
  73. <Button
  74. onPress={() => {
  75. navigation.navigate("AddGoods");
  76. }}
  77. >
  78. {addGoods2}
  79. </Button>
  80. </Layout>
  81. <List
  82. style={styles.list}
  83. data={goods}
  84. renderItem={goodsItem}
  85. ListEmptyComponent={EmptyComponent}
  86. />
  87. </Layout>
  88. </>
  89. );
  90. }