MainScreen.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import * as WebBrowser from "expo-web-browser";
  2. import * as React from "react";
  3. import { StyleSheet } from "react-native";
  4. import { useModel } from "flooks";
  5. import { useFocusEffect } from "@react-navigation/native";
  6. import {
  7. Layout,
  8. Button,
  9. useTheme,
  10. TopNavigationAction,
  11. Icon,
  12. Divider,
  13. } from "@ui-kitten/components";
  14. import NavHeaderBar from "../../components/NavHeaderBar";
  15. import ListComponent from "../../components/ListComponent";
  16. import BankCard from "../../components/BankCard";
  17. const PlusIcon = props => <Icon {...props} fill="#fff" name="plus" />;
  18. const styles = StyleSheet.create({
  19. list: {
  20. flex: 1,
  21. backgroundColor: "#EEEEEE",
  22. paddingVertical: 7,
  23. },
  24. separatorStyle: {
  25. height: 6,
  26. backgroundColor: "#EEEEEE",
  27. },
  28. subBtn: {
  29. paddingHorizontal: 15,
  30. paddingVertical: 20,
  31. width: "100%",
  32. position: "absolute",
  33. bottom: 90,
  34. left: 0,
  35. backgroundColor: "transparent",
  36. },
  37. });
  38. export default function BankScreen({ navigation, route }) {
  39. const theme = useTheme();
  40. const { changeBackground } = useModel("barModel");
  41. const { userTitle62, CWNZNO, ALI_PAY, bankMainTitle, next } = useModel(
  42. "wordsModel"
  43. );
  44. const { aliAccount } = useModel("userModel");
  45. // const { } = useModel("dialogModel");
  46. const { httpGet } = useModel("httpModel", true);
  47. const [pageName, setPageName] = React.useState("Bank");
  48. const [selectId, setSelectId] = React.useState();
  49. const [showList, changeShow] = React.useState(false);
  50. useFocusEffect(
  51. React.useCallback(() => {
  52. changeBackground(theme["color-primary-500"]);
  53. const { name } = route;
  54. setPageName(name);
  55. }, [])
  56. );
  57. function getList(page, size) {
  58. return httpGet("/bankCard/my", { page, size }, true);
  59. }
  60. const renderItem = ({ item, index }) => (
  61. <BankCard
  62. key={index}
  63. info={item}
  64. type={pageName === "Bank" ? "edit" : "choose"}
  65. selectId={selectId}
  66. pressEvent={() => {
  67. if (pageName === "Bank") {
  68. navigation.navigate("AddBank", {
  69. id: item.id,
  70. pageName,
  71. });
  72. } else {
  73. setSelectId(item.id);
  74. }
  75. }}
  76. />
  77. );
  78. const aliAccountNo = React.useMemo(() => {
  79. if (aliAccount && aliAccount.length > 4) {
  80. return `${CWNZNO}${aliAccount.substr(aliAccount.length - 5, 4)}`;
  81. }
  82. if (aliAccount) {
  83. return `${CWNZNO}${aliAccount.substr(0, aliAccount.length)}`;
  84. }
  85. return "";
  86. }, [aliAccount]);
  87. const ListFooterComponent = () => (
  88. <>
  89. <Divider style={styles.separatorStyle} />
  90. <BankCard
  91. disabled
  92. info={{
  93. bankName: ALI_PAY,
  94. cardNo: aliAccountNo,
  95. avatar:
  96. "https://idingdong.oss-cn-hangzhou.aliyuncs.com/image/2020-05-21-19-10-04YaHrcXTX.png",
  97. }}
  98. />
  99. </>
  100. );
  101. const NextButton = () => (
  102. <Layout style={{ height: 100, backgroundColor: "transparent" }} />
  103. );
  104. const renderRightActions = () => (
  105. <TopNavigationAction
  106. icon={PlusIcon}
  107. onPress={() => {
  108. navigation.navigate("AddBank", {
  109. pageName,
  110. });
  111. }}
  112. />
  113. );
  114. const emptyEvent = isEmpty => {
  115. const { name } = route;
  116. if (name === "ChooseBank" && isEmpty) {
  117. navigation.replace("AddBank", {
  118. pageName: "Recharge",
  119. });
  120. } else {
  121. changeShow(true);
  122. }
  123. };
  124. return (
  125. <>
  126. {showList && (
  127. <NavHeaderBar
  128. title={pageName === "Bank" ? userTitle62 : bankMainTitle}
  129. accessoryRight={renderRightActions}
  130. />
  131. )}
  132. <ListComponent
  133. getInfo={getList}
  134. renderItem={renderItem}
  135. style={styles.list}
  136. separatorStyle={styles.separatorStyle}
  137. ListFooterComponent={
  138. pageName === "Bank" ? ListFooterComponent : NextButton
  139. }
  140. showEmpty={pageName === "ChooseBank"}
  141. emptyEvent={emptyEvent}
  142. showList={showList}
  143. extraData={{ selectId }}
  144. />
  145. {pageName === "ChooseBank" && showList && (
  146. <Layout style={styles.subBtn}>
  147. <Button
  148. disabled={!selectId}
  149. onPress={() => {
  150. navigation.navigate("Recharge", {
  151. selectId,
  152. });
  153. }}
  154. >
  155. {next}
  156. </Button>
  157. </Layout>
  158. )}
  159. </>
  160. );
  161. }