WithdrawApplyScreen.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { StackScreenProps } from '@react-navigation/stack';
  2. import * as React from 'react';
  3. import { Div, Button, Image, Text, Avatar, Input } from 'react-native-magnus';
  4. import { ScrollView } from 'react-native-gesture-handler';
  5. import useModel from 'flooks';
  6. import { useCreation } from 'ahooks';
  7. import Wallet from './model';
  8. import User from '../stores/User';
  9. import BankCom from './BankCom';
  10. import { getMoney } from '../utils/SystemUtils';
  11. import request from '../utils/RequestUtils';
  12. import { toastShow, toastSuccess, toastInfo } from '../utils/SystemUtils';
  13. import { useTranslation } from 'react-i18next';
  14. function saveApply(amount, bankCardId) {
  15. return request.post('/withdrawApply/apply', {
  16. data: {
  17. amount,
  18. bankCardId,
  19. },
  20. requestType: 'form',
  21. });
  22. }
  23. export default function WithdrawApplyScreen({ navigation }: StackScreenProps) {
  24. const { t } = useTranslation();
  25. const { chooseCardId, chooseInfo } = useModel(Wallet, [
  26. 'chooseInfo',
  27. 'chooseCardId',
  28. ]);
  29. const [money, setmoney] = React.useState<string>('');
  30. const { userInfo } = useModel(User, ['userInfo']);
  31. const error = useCreation(() => {
  32. if (Number(money) > Number(userInfo.money)) {
  33. return true;
  34. } else {
  35. return false;
  36. }
  37. }, [money, userInfo]);
  38. const canNext = useCreation(() => {
  39. if (chooseCardId && Number(money) && !error) {
  40. return true;
  41. } else {
  42. return false;
  43. }
  44. }, [money, error, chooseCardId]);
  45. return (
  46. <Div bg="gray100" flex={1}>
  47. <ScrollView
  48. contentContainerStyle={{
  49. flexGrow: 1,
  50. backgroundColor: '#f2f2f2',
  51. }}
  52. >
  53. <BankCom
  54. info={chooseInfo}
  55. next
  56. onPress={() => navigation.navigate('BankCard')}
  57. />
  58. <Div bg="white" p={14} mt={10}>
  59. <Text color="gray500" fontSize="sm">
  60. {t('ti-xian-jin-e')}
  61. </Text>
  62. <Div
  63. row
  64. alignItems="center"
  65. borderBottomColor={error ? 'red300' : 'gray100'}
  66. borderBottomWidth={1}
  67. >
  68. <Text fontSize="6xl" color={error ? 'red300' : 'gray500'}>
  69. ¥
  70. </Text>
  71. <Input
  72. flex={1}
  73. autoFocus={true}
  74. keyboardType="numeric"
  75. value={money}
  76. ml={5}
  77. borderWidth={0}
  78. fontSize="6xl"
  79. px={0}
  80. loaderColor="gray400"
  81. color={error ? 'red500' : 'gray900'}
  82. opacity={1}
  83. onChangeText={(val) => {
  84. setmoney(val);
  85. }}
  86. onBlur={() => {
  87. setmoney(Number(money).toFixed(2));
  88. }}
  89. />
  90. </Div>
  91. <Text fontSize="xs" color={error ? 'red500' : 'gary500'} mt={6}>
  92. {t('ke-yong-yu-e')}
  93. {getMoney(userInfo.money)}
  94. {t('yuan')}
  95. </Text>
  96. </Div>
  97. <Button
  98. bg="yellow500"
  99. block
  100. m={15}
  101. disabled={!canNext}
  102. onPress={() => {
  103. toastShow();
  104. saveApply(Number(money), chooseCardId)
  105. .then((res) => {
  106. toastSuccess(t('ti-jiao-cheng-gong'));
  107. navigation.navigate('WithdrawResult', { id: res.id });
  108. })
  109. .catch((e) => {
  110. toastInfo(e.error);
  111. });
  112. }}
  113. >
  114. {t('yu-ji-liang-xiao-shi-nei-dao-zhang-que-ren-ti-xian')}
  115. </Button>
  116. </ScrollView>
  117. </Div>
  118. );
  119. }