AddBankCardScreen.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import { StackScreenProps } from '@react-navigation/stack';
  2. import * as React from 'react';
  3. import {
  4. Div,
  5. Button,
  6. Image,
  7. Text,
  8. Avatar,
  9. Input,
  10. Icon,
  11. } from 'react-native-magnus';
  12. import { ScrollView } from 'react-native-gesture-handler';
  13. import { TextInputMask } from 'react-native-masked-text';
  14. import { useTranslation } from 'react-i18next';
  15. import { useCreation, useRequest } from 'ahooks';
  16. import useModel from 'flooks';
  17. import User from '../stores/User';
  18. import request from '../utils/RequestUtils';
  19. import { toastShow, toastSuccess, toastInfo } from '../utils/SystemUtils';
  20. function saveBank(userId, realName, phone, idNo, bankName, cardNo) {
  21. return request.post('/bankCard/save', {
  22. data: {
  23. userId,
  24. realName,
  25. phone,
  26. idNo,
  27. bankName,
  28. cardNo,
  29. },
  30. });
  31. }
  32. export default function AddBankCardScreen({ navigation }: StackScreenProps) {
  33. const { t } = useTranslation();
  34. const { userInfo } = useModel(User, ['userInfo']);
  35. const [bankName, setbankName] = React.useState<string>('');
  36. const [cardNo, setcardNo] = React.useState<string>('');
  37. const [idNo, setidNo] = React.useState<string>('');
  38. const [phone, setphone] = React.useState<string>('');
  39. const [realName, setrealName] = React.useState<string>('');
  40. const [code, setCode] = React.useState<string>('');
  41. const [sure, setsure] = React.useState<boolean>(false);
  42. const canSub = useCreation(() => {
  43. if (bankName && cardNo && idNo && phone && realName && code && sure) {
  44. return true;
  45. } else {
  46. return false;
  47. }
  48. }, [bankName, cardNo, idNo, phone, realName, code, sure]);
  49. return (
  50. <Div bg="gray100">
  51. <ScrollView
  52. contentContainerStyle={{
  53. flexGrow: 1,
  54. backgroundColor: '#f2f2f2',
  55. }}
  56. >
  57. <Div bg="white" px={12} mt={7}>
  58. <Div
  59. row
  60. alignItems="center"
  61. borderBottomColor="gray100"
  62. borderBottomWidth={1}
  63. >
  64. <Text fontSize="sm" w={75}>
  65. {t('yin-hang-ming-cheng')}
  66. </Text>
  67. <Input
  68. flex={1}
  69. value={bankName}
  70. borderWidth={0}
  71. fontSize="sm"
  72. px={0}
  73. loaderColor="gray400"
  74. color="gray900"
  75. opacity={1}
  76. h={31}
  77. placeholder={t('shu-ru-yin-hang-ming-cheng')}
  78. onChangeText={(val) => setbankName(val)}
  79. />
  80. </Div>
  81. <Div
  82. row
  83. alignItems="center"
  84. borderBottomColor="gray100"
  85. borderBottomWidth={1}
  86. >
  87. <Text fontSize="sm" w={75}>
  88. {t('ka-hao')}
  89. </Text>
  90. <TextInputMask
  91. type={'custom'}
  92. value={cardNo}
  93. keyboardType="numeric"
  94. options={{
  95. mask: '9999 9999 9999 9999 999',
  96. }}
  97. onChangeText={(text) => {
  98. setcardNo(text);
  99. }}
  100. placeholderTextColor="#a6a6a6"
  101. style={{ flex: 1, fontSize: 12, height: 31 }}
  102. placeholder={t('shu-ru-yin-hang-ka-hao')}
  103. />
  104. </Div>
  105. <Div
  106. row
  107. alignItems="center"
  108. borderBottomColor="gray100"
  109. borderBottomWidth={1}
  110. >
  111. <Text fontSize="sm" w={75}>
  112. {t('xing-ming')}
  113. </Text>
  114. <Input
  115. flex={1}
  116. value={realName}
  117. borderWidth={0}
  118. fontSize="sm"
  119. px={0}
  120. h={31}
  121. loaderColor="gray400"
  122. color="gray900"
  123. opacity={1}
  124. placeholder={t('shu-ru-zhen-shi-xing-ming')}
  125. onChangeText={(val) => setrealName(val)}
  126. />
  127. </Div>
  128. <Div
  129. row
  130. alignItems="center"
  131. borderBottomColor="gray100"
  132. borderBottomWidth={1}
  133. >
  134. <Text fontSize="sm" w={75}>
  135. {t('shen-fen-zheng-hao')}
  136. </Text>
  137. <TextInputMask
  138. type={'custom'}
  139. value={idNo}
  140. keyboardType="email-address"
  141. options={{
  142. mask: '99999999999999999S',
  143. }}
  144. onChangeText={(text) => {
  145. setidNo(text);
  146. }}
  147. placeholderTextColor="#a6a6a6"
  148. style={{ flex: 1, fontSize: 12, height: 31 }}
  149. placeholder={t('shu-ru-shen-fen-zheng-hao')}
  150. />
  151. </Div>
  152. <Div
  153. row
  154. alignItems="center"
  155. borderBottomColor="gray100"
  156. borderBottomWidth={1}
  157. >
  158. <Text fontSize="sm" w={75}>
  159. {t('shou-ji-hao')}
  160. </Text>
  161. <TextInputMask
  162. type={'custom'}
  163. value={phone}
  164. keyboardType="numeric"
  165. options={{
  166. mask: '999 9999 9999',
  167. }}
  168. onChangeText={(text) => {
  169. setphone(text);
  170. }}
  171. placeholderTextColor="#a6a6a6"
  172. style={{ flex: 1, fontSize: 12, height: 31 }}
  173. placeholder={t('shu-ru-shou-ji-hao')}
  174. />
  175. </Div>
  176. <Div row alignItems="center">
  177. <Text fontSize="sm" w={75}>
  178. {t('yan-zheng-ma')}
  179. </Text>
  180. <TextInputMask
  181. type={'custom'}
  182. value={code}
  183. keyboardType="numeric"
  184. options={{
  185. mask: '999999',
  186. }}
  187. onChangeText={(text) => {
  188. setCode(text);
  189. }}
  190. placeholderTextColor="#a6a6a6"
  191. style={{ flex: 1, fontSize: 12, height: 31 }}
  192. placeholder={t('shu-ru-yan-zheng-ma')}
  193. />
  194. </Div>
  195. </Div>
  196. <Button
  197. bg="transparent"
  198. p={0}
  199. block
  200. mt={10}
  201. onPress={() => setsure(!sure)}
  202. >
  203. <Div row alignItems="center" flex={1} justifyContent="center">
  204. <Icon
  205. fontFamily="Ionicons"
  206. ml={20}
  207. color={sure ? 'yellow500' : 'gray400'}
  208. name={sure ? 'ios-radio-button-on' : 'ios-radio-button-off'}
  209. />
  210. <Div row flexWrap="wrap" ml={15} flex={1}>
  211. <Text color="gray500" fontSize="xs">
  212. {t('yi-jing-yue-du-bing-tong-yi')}
  213. </Text>
  214. <Button bg="none" color="yellow500" fontSize="sm" p={0}>
  215. {t('ding-dong-wai-mai-kuai-jie-zhi-fu-fu-wu-xie-yi')}
  216. </Button>
  217. </Div>
  218. </Div>
  219. </Button>
  220. <Button
  221. block
  222. bg="yellow500"
  223. m={15}
  224. fontSize="sm"
  225. disabled={!canSub}
  226. onPress={() => {
  227. toastShow();
  228. saveBank(userInfo.id, realName, phone, idNo, bankName, cardNo)
  229. .then((res) => {
  230. toastSuccess(t('ti-jiao-cheng-gong'));
  231. navigation.goBack();
  232. })
  233. .catch((e) => {
  234. toastInfo(e.error);
  235. });
  236. }}
  237. >
  238. 下一步
  239. </Button>
  240. </ScrollView>
  241. </Div>
  242. );
  243. }