MoneyListScreen.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import * as WebBrowser from "expo-web-browser";
  2. import * as React from "react";
  3. import {
  4. StyleSheet,
  5. } from "react-native";
  6. import { useModel } from "flooks";
  7. import {
  8. Layout,
  9. useTheme,
  10. Select,
  11. SelectItem,
  12. IndexPath,
  13. TopNavigation,
  14. TopNavigationAction,
  15. Icon,
  16. } from "@ui-kitten/components";
  17. import { useFocusEffect } from "@react-navigation/native";
  18. import MoneyRecord from "../../components/MoneyRecord";
  19. import ListComponent from "../../components/ListComponent";
  20. const BackIcon = props => <Icon {...props} fill='#fff' name='arrow-back' />;
  21. const styles = StyleSheet.create({
  22. container: {
  23. flex: 1,
  24. paddingBottom: 33,
  25. paddingVertical: 40,
  26. alignItems: "center",
  27. },
  28. icon: {
  29. width: 90,
  30. height: 80,
  31. marginBottom: 26,
  32. },
  33. text: {
  34. fontWeight: "500",
  35. marginBottom: 7,
  36. },
  37. button: {
  38. marginTop: 19,
  39. },
  40. lay: {
  41. flexDirection: "row",
  42. paddingHorizontal: 17,
  43. paddingBottom: 20,
  44. },
  45. flex1: {
  46. flex: 1,
  47. flexShrink: 0,
  48. },
  49. money: {
  50. textAlign: "center",
  51. fontWeight: "normal",
  52. },
  53. tiltle: {
  54. fontSize: 12,
  55. color: "#A43506",
  56. alignSelf: "center",
  57. flexShrink: 0,
  58. },
  59. selectMain: {
  60. backgroundColor: "transparent",
  61. },
  62. select: {
  63. paddingVertical: 10,
  64. paddingHorizontal: 20,
  65. backgroundColor: "transparent",
  66. flexShrink: 0,
  67. minWidth: 150,
  68. },
  69. list: {
  70. backgroundColor: "#fff",
  71. flex: 1,
  72. },
  73. separatorStyle: {
  74. marginHorizontal: 13,
  75. },
  76. });
  77. export default function MoneyListScreen({ navigation }) {
  78. const theme = useTheme();
  79. const { changeBackground } = useModel("barModel");
  80. const { getUserInfo } = useModel("appUserModel");
  81. const { selectTiltle1, selectTiltle2, selectTiltle3 } = useModel(
  82. "wordsModel"
  83. );
  84. const { moneyRecordList } = useModel("moenyRecordModel", true);
  85. const [selectedIndex, setSelectedIndex] = React.useState(new IndexPath(0));
  86. const data = [
  87. {
  88. title: selectTiltle1,
  89. type: "",
  90. },
  91. {
  92. title: selectTiltle2,
  93. type: "INCOME",
  94. },
  95. {
  96. title: selectTiltle3,
  97. type: "WITHDRAW",
  98. },
  99. ];
  100. const displayValue = data[selectedIndex.row].title;
  101. const [child, setChild] = React.useState();
  102. const [startState, changeStart] = React.useState(true);
  103. const renderOption = (item, index) => (
  104. <SelectItem key={index} title={item.title} />
  105. );
  106. const selectElement = TextProps => (
  107. <Layout style={[styles.select, TextProps.style]}>
  108. <Select
  109. value={displayValue}
  110. selectedIndex={selectedIndex}
  111. onSelect={index => {
  112. setSelectedIndex(index);
  113. changeStart(true);
  114. }}
  115. appearance='bar'
  116. state='primary'
  117. >
  118. {data.map(renderOption)}
  119. </Select>
  120. </Layout>
  121. );
  122. // const {} = useModel("wordsModel");
  123. useFocusEffect(
  124. React.useCallback(() => {
  125. changeBackground(theme["color-primary-500"]);
  126. getUserInfo();
  127. }, [])
  128. );
  129. // 获取列表
  130. function getList(page, size) {
  131. const type = data[selectedIndex.row].type || "";
  132. return moneyRecordList(page, size, { type }).then(res => {
  133. changeStart(false);
  134. return Promise.resolve(res);
  135. });
  136. }
  137. const renderBackAction = () => (
  138. <TopNavigationAction
  139. icon={BackIcon}
  140. onPress={() => navigation.goBack()}
  141. />
  142. );
  143. const walletItem = ({ item, index }) => (
  144. <MoneyRecord key={index} info={item} />
  145. );
  146. return (
  147. <>
  148. <TopNavigation
  149. alignment='center'
  150. title={selectElement}
  151. accessoryLeft={renderBackAction}
  152. />
  153. <ListComponent
  154. setChild={setChild}
  155. getInfo={getList}
  156. renderItem={walletItem}
  157. style={styles.list}
  158. separatorStyle={styles.separatorStyle}
  159. showEmpty
  160. extraData={{ child }}
  161. startState={startState}
  162. />
  163. </>
  164. );
  165. }