SearchScreen.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* eslint-disable no-console */
  2. /* eslint-disable no-underscore-dangle */
  3. import * as WebBrowser from "expo-web-browser";
  4. import * as React from "react";
  5. import { StyleSheet } from "react-native";
  6. import { useModel } from "flooks";
  7. import { Layout, useTheme } from "@ui-kitten/components";
  8. import { SearchBar } from "@ant-design/react-native";
  9. import { useFocusEffect } from "@react-navigation/native";
  10. import NavHeaderBar from "../../components/NavHeaderBar";
  11. import GoodsCardLarge from "../../components/GoodsCard";
  12. import ListComponent from "../../components/ListComponent";
  13. const styles = StyleSheet.create({
  14. container: {
  15. flex: 1,
  16. },
  17. bntLay: {
  18. paddingVertical: 5,
  19. flexDirection: "row",
  20. alignItems: "center",
  21. justifyContent: "center",
  22. backgroundColor: "#EEEEEE",
  23. flexShrink: 0,
  24. },
  25. list: {
  26. flex: 1,
  27. backgroundColor: "#EEEEEE",
  28. paddingHorizontal: 10,
  29. },
  30. });
  31. export default function SearchScreen({ navigation }) {
  32. const theme = useTheme();
  33. const { changeBackground } = useModel("barModel");
  34. const { mid } = useModel("userModel");
  35. const { httpGet } = useModel("httpModel");
  36. const { SHKVCV, cancel, XZOCQU } = useModel("wordsModel");
  37. const [startState, changeStart] = React.useState(false);
  38. const [searchKey, setSearchKey] = React.useState("");
  39. const [inputVal, setVal] = React.useState("");
  40. function getAllGoods(page, size) {
  41. return httpGet("/goods/all", {
  42. size,
  43. page,
  44. search: searchKey,
  45. query: {
  46. merchantId: mid,
  47. },
  48. sort: "id,desc",
  49. }).then(res => {
  50. changeStart(false);
  51. return Promise.resolve(res);
  52. });
  53. }
  54. useFocusEffect(
  55. React.useCallback(() => {
  56. changeBackground(theme["color-primary-500"]);
  57. // changeStart(true);
  58. }, [])
  59. );
  60. const goodsItem = ({ item }) => (
  61. <GoodsCardLarge
  62. appearance="classification"
  63. type="goodsList"
  64. key={item.id}
  65. info={item}
  66. canEdit
  67. style={{ marginBottom: 7 }}
  68. onPress={() => {
  69. navigation.navigate("GoodsDetailMore", {
  70. goodsId: item.id,
  71. });
  72. }}
  73. changeInfo={info => {
  74. // eslint-disable-next-line no-console
  75. console.log(info);
  76. changeStart(true);
  77. }}
  78. />
  79. );
  80. return (
  81. <>
  82. <NavHeaderBar title={SHKVCV} />
  83. <Layout style={styles.container}>
  84. <SearchBar
  85. placeholder={XZOCQU}
  86. value={inputVal}
  87. onChange={setVal}
  88. onSubmit={value => {
  89. setSearchKey(value);
  90. changeStart(true);
  91. }}
  92. onCancel={() => {
  93. if (inputVal) {
  94. setVal("");
  95. setSearchKey("");
  96. changeStart(true);
  97. } else {
  98. navigation.goBack();
  99. }
  100. }}
  101. cancelText={inputVal ? cancel : "返回"}
  102. showCancelButton
  103. />
  104. <ListComponent
  105. startState={startState}
  106. renderItem={goodsItem}
  107. getInfo={getAllGoods}
  108. showEmpty
  109. style={styles.list}
  110. saveList
  111. />
  112. </Layout>
  113. </>
  114. );
  115. }