CertificationScreen.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 { TextInputMask } from 'react-native-masked-text';
  5. import { ScrollView } from 'react-native-gesture-handler';
  6. import ImagePicker from '../components/ImagePicker';
  7. import { useTranslation } from 'react-i18next';
  8. import { useMap, useCreation, useRequest } from 'ahooks';
  9. import { connect } from '../utils/SystemUtils';
  10. import useModel from 'flooks';
  11. import Login from './model';
  12. export default function CertificationScreen({ navigation }: StackScreenProps) {
  13. const { t } = useTranslation();
  14. const { data } = useRequest('/verified/my');
  15. const [realName, setRealName] = React.useState<string>('');
  16. const [idNo, setIdNo] = React.useState<string>('');
  17. const [idNoImgMap, idNoImgMapEvent] = useMap<string, string>([
  18. ['证件正面', ''],
  19. ['证件反面', ''],
  20. ]);
  21. const [handheldIdNo, setHandheldIdNo] = React.useState<string>('');
  22. const { verifiedSave } = useModel(Login, []);
  23. const canSubmit = useCreation(() => {
  24. if (
  25. realName &&
  26. idNo &&
  27. handheldIdNo &&
  28. idNoImgMapEvent.get('证件正面') !== '' &&
  29. idNoImgMapEvent.get('证件反面') !== ''
  30. ) {
  31. return true;
  32. } else {
  33. return false;
  34. }
  35. }, [realName, idNo, idNoImgMap, handheldIdNo]);
  36. React.useEffect(() => {
  37. if (data && data.id) {
  38. setRealName(data.realName);
  39. setIdNo(data.idNo);
  40. setHandheldIdNo(data.handheldIdNo);
  41. idNoImgMapEvent.setAll([
  42. ['证件正面', data.idNoImg.split(',')[0]],
  43. ['证件反面', data.idNoImg.split(',')[1]],
  44. ]);
  45. }
  46. }, [data]);
  47. return (
  48. <Div bg="#fff" flex={1}>
  49. <ScrollView
  50. contentContainerStyle={{
  51. flexGrow: 1,
  52. backgroundColor: '#fff',
  53. }}
  54. >
  55. <Div borderTopWidth={10} borderColor="gray100" px={15}>
  56. <Div row alignItems="center" py={10}>
  57. <Text w={120} textAlign="right">
  58. {t('zhen-shi-xing-ming')}:
  59. </Text>
  60. <Div
  61. flex={1}
  62. bg="gray100"
  63. rounded="sm"
  64. ml={5}
  65. h={30}
  66. alignItems="stretch"
  67. >
  68. <Input
  69. flex={1}
  70. bg="gray100"
  71. rounded="sm"
  72. px={12}
  73. ml={5}
  74. h={30}
  75. value={realName}
  76. borderWidth={0}
  77. fontSize="sm"
  78. opacity={1}
  79. loaderColor="gray400"
  80. color="gray900"
  81. opacity={1}
  82. placeholder={t('shu-ru-xing-ming')}
  83. onChangeText={(text) => {
  84. setRealName(text);
  85. }}
  86. style={{ flex: 1 }}
  87. />
  88. </Div>
  89. </Div>
  90. <Div row alignItems="center" py={10}>
  91. <Text w={120} textAlign="right">
  92. {t('shen-fen-zheng-hao')}:
  93. </Text>
  94. <Div
  95. flex={1}
  96. bg="gray100"
  97. rounded="sm"
  98. px={19}
  99. ml={5}
  100. h={30}
  101. alignItems="stretch"
  102. >
  103. <TextInputMask
  104. type={'custom'}
  105. value={idNo}
  106. keyboardType="numeric"
  107. options={{
  108. mask: '999999999999999999',
  109. }}
  110. onChangeText={(text) => {
  111. setIdNo(text);
  112. }}
  113. placeholderTextColor="#a6a6a6"
  114. style={{ flex: 1, fontSize: 12, height: 31 }}
  115. placeholder={t('shu-ru-zheng-jian-hao-ma')}
  116. />
  117. </Div>
  118. </Div>
  119. <Div row py={10}>
  120. <Text w={120} textAlign="right">
  121. {t('shen-fen-zheng-zheng-fan-mian')}:
  122. </Text>
  123. <Div flex={1} row pt={30}>
  124. {[...idNoImgMap.keys()].map((item, index) => {
  125. return (
  126. <Div w="50%" key={index} alignItems="center">
  127. <ImagePicker
  128. img={idNoImgMapEvent.get(item)}
  129. setImg={(img) => idNoImgMapEvent.set(item, img)}
  130. />
  131. <Text textAlign="center" color="gray200" fontSize="sm">
  132. {item}
  133. </Text>
  134. </Div>
  135. );
  136. })}
  137. </Div>
  138. </Div>
  139. <Div row py={10}>
  140. <Text w={120} textAlign="right">
  141. {t('shou-chi-shen-fen-zheng')}:
  142. </Text>
  143. <Div flex={1} row pt={30}>
  144. <Div w="50%" alignItems="center">
  145. <ImagePicker
  146. img={handheldIdNo}
  147. setImg={(img) => setHandheldIdNo(img)}
  148. />
  149. </Div>
  150. </Div>
  151. </Div>
  152. <Button
  153. w={112}
  154. bg="yellow500"
  155. alignSelf="center"
  156. fontSize="sm"
  157. my={20}
  158. disabled={!canSubmit}
  159. onPress={() =>
  160. verifiedSave(
  161. realName,
  162. idNo,
  163. idNoImgMapEvent.get('证件正面') +
  164. ',' +
  165. idNoImgMapEvent.get('证件反面'),
  166. handheldIdNo,
  167. data ? data.id || '' : ''
  168. )
  169. }
  170. >
  171. {t('xia-yi-bu')}
  172. </Button>
  173. <Button
  174. w={112}
  175. color="yellow500"
  176. bg="none"
  177. borderColor="gray100"
  178. borderWidth={1}
  179. alignSelf="center"
  180. fontSize="sm"
  181. my={20}
  182. onPress={() => connect(navigation)}
  183. >
  184. {t('lian-xi-ke-fu')}
  185. </Button>
  186. </Div>
  187. </ScrollView>
  188. </Div>
  189. );
  190. }