RechargeScreen.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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, useRoute } from "@react-navigation/native";
  6. import {
  7. Layout,
  8. Button,
  9. useTheme,
  10. Divider,
  11. Input,
  12. Text,
  13. } from "@ui-kitten/components";
  14. import NavHeaderBar from "../../components/NavHeaderBar";
  15. import BankCard from "../../components/BankCard";
  16. const styles = StyleSheet.create({
  17. list: {
  18. flex: 1,
  19. backgroundColor: "#EEEEEE",
  20. paddingVertical: 7,
  21. },
  22. separatorStyle: {
  23. height: 6,
  24. backgroundColor: "#EEEEEE",
  25. },
  26. subBtn: {
  27. paddingHorizontal: 15,
  28. paddingVertical: 20,
  29. width: "100%",
  30. position: "absolute",
  31. bottom: 90,
  32. left: 0,
  33. backgroundColor: "transparent",
  34. },
  35. input: {
  36. marginTop: 7,
  37. paddingTop: 10,
  38. paddingHorizontal: 13,
  39. paddingBottom: 28,
  40. },
  41. left: {
  42. fontWeight: "normal",
  43. marginRight: 18,
  44. },
  45. });
  46. export default function RechargeScreen({ navigation }) {
  47. const theme = useTheme();
  48. const { changeBackground } = useModel("barModel");
  49. const {
  50. rechargeBtnText,
  51. ORHSFG,
  52. WITHDRAW,
  53. applySuccess,
  54. BJGTHA,
  55. BIZQHZ,
  56. } = useModel("wordsModel");
  57. const { getUserInfo, money } = useModel("appUserModel");
  58. const { httpPost, httpGet } = useModel("httpModel", true);
  59. const { success } = useModel("loadingModel");
  60. const [bankCardId, setBankCardId] = React.useState();
  61. const [bankCradInfo, setBankCradInfo] = React.useState({});
  62. const [value, setVal] = React.useState("");
  63. const route = useRoute();
  64. useFocusEffect(
  65. React.useCallback(() => {
  66. changeBackground(theme["color-primary-500"]);
  67. const { params } = route;
  68. const { selectId } = params || {};
  69. if (selectId) {
  70. setBankCardId(selectId);
  71. }
  72. getUserInfo();
  73. }, [])
  74. );
  75. React.useEffect(() => {
  76. if (bankCardId) {
  77. httpGet(`/bankCard/get/${bankCardId}`).then(res => {
  78. setBankCradInfo(res);
  79. });
  80. } else {
  81. setBankCradInfo({});
  82. }
  83. }, [bankCardId]);
  84. const canSubmit = React.useMemo(() => {
  85. const value1 = Number(value);
  86. if (bankCardId && value1 && value1 <= (money || 0)) {
  87. return true;
  88. }
  89. return false;
  90. }, [value, bankCardId]);
  91. const showMoeny = React.useMemo(() => {
  92. if (money) {
  93. return money.toFixed(2);
  94. }
  95. return "0.00";
  96. }, [money]);
  97. function submit() {
  98. const value1 = Number(value);
  99. httpPost(
  100. "/withdrawApply/apply",
  101. {
  102. amount: value1,
  103. bankCardId,
  104. },
  105. {},
  106. true
  107. ).then(res => {
  108. success(applySuccess);
  109. navigation.replace("RechargeDetail", {
  110. id: res.id,
  111. });
  112. });
  113. }
  114. return (
  115. <>
  116. <NavHeaderBar title={WITHDRAW} />
  117. <Divider style={styles.separatorStyle} />
  118. <BankCard
  119. type="edit"
  120. pressEvent={() => {
  121. navigation.navigate("ChooseBank");
  122. }}
  123. info={bankCradInfo}
  124. />
  125. <Layout style={styles.input}>
  126. <Input
  127. appearance="reCharge"
  128. label={ORHSFG}
  129. value={value}
  130. accessoryLeft={() => (
  131. <Text category="h2" style={styles.left}>
  132. ¥
  133. </Text>
  134. )}
  135. caption={`${BIZQHZ}${showMoeny}${BJGTHA}`}
  136. keyboardType="numeric"
  137. onChangeText={text => {
  138. setVal(text);
  139. }}
  140. onBlur={() => {
  141. const value1 = Number(value);
  142. if (value1 > (money || 0)) {
  143. setVal(showMoeny);
  144. } else {
  145. setVal(value1.toFixed(2));
  146. }
  147. }}
  148. />
  149. </Layout>
  150. <Layout style={styles.subBtn}>
  151. <Button disabled={!canSubmit} onPress={submit}>
  152. {rechargeBtnText}
  153. </Button>
  154. </Layout>
  155. </>
  156. );
  157. }