RegisterV3.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /**
  2. * 公共用户和司机用户注册页面
  3. * @邠心vbe on 2023/02/01
  4. */
  5. import React from 'react';
  6. import { View, Text, ScrollView, StyleSheet, TextInput, Pressable, Image } from 'react-native';
  7. import apiUser from '../../api/apiUser';
  8. import Button from '../../components/Button';
  9. import { PageList } from '../Router';
  10. import Dialog from '../../components/Dialog';
  11. import Modal from 'react-native-modal';
  12. import { RegisterDialog } from '../charge/InfoDialog';
  13. import Dropdown from '../../components/Dropdown';
  14. import ImagePicker from 'react-native-image-crop-picker';
  15. import apiUpload from '../../api/apiUpload';
  16. import { host } from '../../api/http';
  17. import { ModalProps } from '../../components/BottomModal';
  18. import { CountryDropNum, GetCountryList } from '../../components/CountryIcon';
  19. import StrengthView from './StrengthView';
  20. import CheckBox from '../../components/CheckBox';
  21. import { UploadThemes } from '../../components/ThemesConfig';
  22. import TextView from '../../components/TextView';
  23. const options = {
  24. width: 300,
  25. height: 200,
  26. cropping: true,
  27. multiple: false,
  28. mediaType: 'photo',
  29. writeTempFile: false,
  30. compressImageQuality: 0.8,
  31. compressImageMaxWidth: 720,
  32. compressImageMaxHeight: 1280,
  33. ...UploadThemes
  34. }
  35. export default class RegisterV3 extends React.Component {
  36. constructor(props) {
  37. super(props);
  38. this.StrengthView = StrengthView.V1
  39. this.state = {
  40. agree: true,
  41. strength: 0,
  42. countryNum: '65',
  43. countryShow: false,
  44. userInfo: {
  45. email: ""
  46. },
  47. countryNums: [],
  48. wrongCount: 0,
  49. params: {...this.props.route.params},
  50. email: '',
  51. password: '',
  52. fleetCompanyId: '',
  53. visible: false,
  54. isFleetDriver: false,
  55. pdvImages: ['', ''],
  56. companyList: []
  57. };
  58. }
  59. componentDidMount() {
  60. //console.log(this.state.params);
  61. if (this.state.params.isFleetUser) {
  62. this.setState({
  63. isFleetDriver: true
  64. })
  65. this.props.navigation.setOptions({
  66. headerTitle: $t('route.driverRegister')
  67. })
  68. }
  69. this.getCountryList();
  70. this.getCompanyList();
  71. }
  72. applyStrength(text) {
  73. this.StrengthView.apply(text, strength => {
  74. if (this.state.strength != strength) {
  75. this.setState({
  76. password: text,
  77. strength: strength
  78. });
  79. } else {
  80. this.setState({
  81. password: text
  82. });
  83. }
  84. });
  85. }
  86. changeInfo(key, value) {
  87. var info = this.state.userInfo;
  88. info[key] = value;
  89. this.setState({
  90. 'userInfo': info
  91. });
  92. }
  93. getCountryList() {
  94. GetCountryList(list => {
  95. this.setState({
  96. countryNums: list
  97. })
  98. })
  99. }
  100. getCompanyList() {
  101. apiUser.getConmpany().then(res => {
  102. if (res.data) {
  103. this.setState({
  104. companyList: res.data
  105. })
  106. }
  107. }).catch(err => [
  108. toastShort(err)
  109. ])
  110. }
  111. onRegister() {
  112. //console.log('sign up', this.state);
  113. var info = this.state.userInfo;
  114. if (!info.nickName) {
  115. toastShort($t('sign.plsInputDiaplayName'));
  116. return;
  117. }
  118. if (!info.email) {
  119. toastShort($t('sign.plsInputEmail'));
  120. return;
  121. }
  122. if (!/^[a-zA-Z0-9]+[\S]+@[a-zA-Z0-9_-]+[\.][\Sa-zA-Z]+$/.test(info.email)) {
  123. toastShort($t('sign.errEmailFormat'));
  124. return;
  125. }
  126. if (!info.phone) {
  127. toastShort($t('sign.plsInputContactNo'));
  128. return;
  129. }
  130. if (!/^\d{6,15}$/.test(info.phone)) {
  131. toastShort($t('sign.errContactNoFormat'));
  132. return;
  133. }
  134. if (!this.state.password) {
  135. toastShort($t('sign.plsInputPassword'));
  136. return;
  137. }
  138. if (this.state.strength < this.StrengthView.maxStrength) {
  139. toastShort($t('sign.errPasswordStrong'));
  140. return;
  141. }
  142. if (!info.password) {
  143. toastShort($t('sign.plsInputPassword2'));
  144. return;
  145. }
  146. if (info.password != this.state.password) {
  147. toastShort($t('sign.errPasswordConfirm'));
  148. if (this.state.wrongCount < 3) {
  149. this.setState({
  150. wrongCount: this.state.wrongCount + 1
  151. })
  152. }
  153. return;
  154. }
  155. if (this.state.isFleetDriver) {
  156. if (!info.pdvLicence) {
  157. toastShort($t('sign.plsInputPDVLicence'));
  158. return;
  159. }
  160. if (this.state.pdvImages[0] == '' || this.state.pdvImages[1] == '') {
  161. toastShort($t('sign.plsUploadLicencePhotos'));
  162. return;
  163. }
  164. }
  165. let param = Object.assign({}, info);
  166. //param.phone = this.state.countryNum + info.phone
  167. param.callingCode = this.state.countryNum;
  168. if (this.state.isFleetDriver) {
  169. param.userType = 'Driver';
  170. param.pdvLicencePictures = this.state.pdvImages;
  171. param.fleetCompanyId = this.state.fleetCompanyId;
  172. } else {
  173. param.userType = 'Public';
  174. }
  175. console.log('params', param);
  176. Dialog.showProgressDialog();
  177. apiUser.register(param).then(res => {
  178. Dialog.dismissLoading();
  179. //toastShort('Sign up successfully!');
  180. if (isIOS) {
  181. setTimeout(() => {
  182. this.setState({
  183. email: param.email,
  184. visible: true
  185. });
  186. }, 500);
  187. } else {
  188. this.setState({
  189. email: param.email,
  190. visible: true
  191. });
  192. }
  193. //this.backToLogin();
  194. }).catch(err => {
  195. toastShort(err);
  196. Dialog.dismissLoading();
  197. });
  198. }
  199. getBackTopPosition() {
  200. return isIOS ? statusHeight - 16 : 8;
  201. }
  202. backToLogin() {
  203. if (this.state.params.actionLogin) {
  204. goBack()
  205. startPage(PageList.login);
  206. } else {
  207. goBack();
  208. }
  209. }
  210. uploadImage(index) {
  211. ImagePicker.openPicker({
  212. ...options,
  213. cropperToolbarTitle: $t('common.cropperTitle')
  214. }).then(image => {
  215. if (image.path) {
  216. apiUpload.uploadImage(image.path, image.mime, 'PDVL').then(res => {
  217. if (res.success && res.data.picturePath) {
  218. let imageUrl = this.state.pdvImages;
  219. imageUrl[index] = res.data.picturePath;
  220. this.setState({
  221. pdvImages: imageUrl
  222. });
  223. toastShort($t('common.uploadSuccess'));
  224. } else {
  225. toastShort($t('common.updateFailed'));
  226. }
  227. }).catch(err => {
  228. toastShort(err);
  229. });
  230. }
  231. }).catch(err1 => {
  232. //console.log(err1);
  233. });
  234. }
  235. changeAgree(ag) {
  236. this.setState({
  237. agree: ag
  238. })
  239. }
  240. hideDialog() {
  241. this.setState({
  242. visible: false
  243. });
  244. this.backToLogin();
  245. }
  246. render() {
  247. return (
  248. <View style={styles.container}>
  249. <ScrollView
  250. style={styles.scollView}
  251. keyboardShouldPersistTaps={'handled'}>
  252. <View style={styles.signView}>
  253. {/* <View style={styles.tabView}>
  254. <Text
  255. style={[
  256. styles.tabText,
  257. this.state.isFleetDriver ? {} : styles.tabActive
  258. ]}
  259. onPress={() => this.changeTab(false)}
  260. >Public Users</Text>
  261. <Text
  262. style={[
  263. styles.tabText,
  264. this.state.isFleetDriver ? styles.tabActive: {}
  265. ]}
  266. onPress={() => this.changeTab(true)}
  267. >Fleet/PH Drivers</Text>
  268. </View> */}
  269. <View style={styles.signInput}>
  270. <TextView style={styles.inputLabel}>{$t('sign.labelDisplayName')}</TextView>
  271. <TextInput
  272. style={styles.inputView}
  273. placeholder={$t('sign.labelDisplayName')}
  274. placeholderTextColor={textPlacehoder}
  275. maxLength={50}
  276. onChangeText={v => this.changeInfo('nickName', v)}
  277. />
  278. </View>
  279. <View style={styles.signInput}>
  280. <TextView style={styles.inputLabel}>{$t('sign.labelEmail')}</TextView>
  281. <TextInput
  282. style={styles.inputView}
  283. placeholder={$t('sign.labelEmail')}
  284. placeholderTextColor={textPlacehoder}
  285. maxLength={50}
  286. keyboardType="email-address"
  287. textContentType='emailAddress'
  288. onChangeText={v => this.changeInfo('email', v)}
  289. />
  290. </View>
  291. <View style={styles.signInput}>
  292. <TextView style={styles.inputLabel}>{$t('sign.labelPhoneNumber')}</TextView>
  293. <View style={styles.mobileView}>
  294. <View style={styles.dropView}>
  295. <TextInput style={styles.dropInput} editable={false}/>
  296. <TextView style={styles.countryText}>{"+" + this.state.countryNum}</TextView>
  297. <MaterialIcons name={'arrow-drop-down'} size={24} color={colorDark}/>
  298. <Dropdown
  299. style={styles.dropLayer}
  300. title={$t('sign.labelCountry')}
  301. prefixText="+"
  302. list={this.state.countryNums}
  303. value={this.state.countryNum}
  304. nameKey='countryNum'
  305. valueKey='countryNum'
  306. onChange={(value, index)=> {
  307. this.setState({
  308. countryNum: value
  309. })
  310. }}
  311. customerItemView={
  312. (item, index, onClick) =>
  313. <CountryDropNum
  314. key={index}
  315. country={item}
  316. value={this.state.countryNum}
  317. onClick={onClick}/>
  318. }/>
  319. </View>
  320. <TextInput
  321. style={styles.contactView}
  322. placeholder={$t('sign.labelMobileNumber')}
  323. placeholderTextColor={textPlacehoder}
  324. keyboardType='phone-pad'
  325. maxLength={15}
  326. onChangeText={v => this.changeInfo('phone', v)}
  327. />
  328. </View>
  329. </View>
  330. <View style={styles.signInput}>
  331. <TextView style={styles.inputLabel}>{$t('sign.labelCreatePassword')}</TextView>
  332. <TextInput
  333. secureTextEntry={this.state.wrongCount < 3}
  334. style={styles.inputView}
  335. placeholder={$t('sign.labelPassword')}
  336. placeholderTextColor={textPlacehoder}
  337. maxLength={20}
  338. onChangeText={(value) => {
  339. this.applyStrength(value);
  340. }}
  341. />
  342. </View>
  343. <View style={styles.signInput}>
  344. <TextView style={styles.inputLabel}></TextView>
  345. <View style={styles.passwordView}>
  346. <this.StrengthView.VIEW strength={this.state.strength}/>
  347. </View>
  348. </View>
  349. <View style={styles.signInput}>
  350. <TextView style={styles.inputLabel}>{$t('sign.labelConfirmPassword')}</TextView>
  351. <TextInput
  352. secureTextEntry={this.state.wrongCount < 3}
  353. style={styles.inputView}
  354. placeholder={$t('sign.labelPassword')}
  355. placeholderTextColor={textPlacehoder}
  356. maxLength={20}
  357. onChangeText={v => this.changeInfo('password', v)}
  358. />
  359. </View>
  360. { this.state.isFleetDriver &&
  361. <>
  362. <View style={styles.signInput}>
  363. <TextView style={styles.inputLabel}>{$t('sign.labelYourCompany')}</TextView>
  364. <Dropdown
  365. style={[styles.inputView, ui.flexc]}
  366. title={$t('sign.labelCompany')}
  367. list={this.state.companyList}
  368. value={this.state.fleetCompanyId}
  369. valueKey='fleetCompanyId'
  370. nameKey='fleetCompanyName'
  371. onChange={(value, index)=> {
  372. this.setState({
  373. fleetCompanyId: value
  374. })
  375. }}/>
  376. </View>
  377. <View style={styles.signInput}>
  378. <TextView style={styles.inputLabel}>{$t('sign.labelPDVLicence')}</TextView>
  379. <TextInput
  380. style={styles.inputView}
  381. placeholder={$t('sign.hintPDVLicence')}
  382. placeholderTextColor={textPlacehoder}
  383. maxLength={20}
  384. onChangeText={v => this.changeInfo('pdvLicence', v)}
  385. />
  386. </View>
  387. <View style={styles.signInput}>
  388. <TextView style={styles.inputLabel}>{$t('sign.labelPDVPhotos')}</TextView>
  389. <View style={styles.uploadGroup}>
  390. { this.state.pdvImages.map((item, index) => (
  391. <UploadView
  392. key={index}
  393. onPress={() => this.uploadImage(index)}
  394. url={item}/>
  395. ))
  396. }
  397. </View>
  398. </View>
  399. </>
  400. }
  401. {/* <View style={styles.referView}>
  402. <Text style={styles.referTitle}>Have a referral code?</Text>
  403. <View style={styles.referText}>
  404. <Text>You'll get</Text>
  405. <Text style={styles.weight}>$5</Text>
  406. <Text>Credit as registration bonus!</Text>
  407. </View>
  408. <View style={styles.codeView}>
  409. <Text style={{ color: textPrimary, fontSize: 16 }}>Referral Code</Text>
  410. <TextInput
  411. style={styles.codeText}
  412. maxLength={6}
  413. placeholder='Referral Code'
  414. placeholderTextColor={textPlacehoder}
  415. onChangeText={v => this.changeInfo('referralCode', v)}
  416. />
  417. </View>
  418. </View> */}
  419. <View style={styles.agreeView}>
  420. <CheckBox
  421. value={this.state.agree}
  422. onValueChange={v => this.changeAgree(v)}
  423. />
  424. <View style={styles.agreeTextRow}>
  425. <TextView style={styles.agreeText} onPress={() => this.changeAgree(!this.state.agree)}>
  426. {$t('sign.iHaveReadAndAgree')}
  427. </TextView>
  428. <TextView style={styles.agreeLink} onPress={() => startPage(PageList.condition)}>{$t('drawer.termsOfUse')}</TextView>
  429. <TextView style={styles.agreeText}>{' '}</TextView>
  430. <TextView style={styles.agreeText}>{$t('sign.linkAndLink')}</TextView>
  431. <TextView style={styles.agreeLink} onPress={() => startPage(PageList.privacy)}>{$t('drawer.privacyPolicy')}</TextView>
  432. <TextView style={styles.agreeText}>{$t('sign.linkAndLinkEnd')}</TextView>
  433. </View>
  434. </View>
  435. <Button
  436. style={styles.signButton}
  437. elevation={1.5}
  438. disabled={!this.state.agree}
  439. text={$t('sign.btnSignUp')}
  440. fontSize={14}
  441. onClick={() => {
  442. this.onRegister();
  443. }}
  444. />
  445. </View>
  446. </ScrollView>
  447. <Modal
  448. isVisible={this.state.visible}
  449. onBackButtonPress={() => this.hideDialog()}
  450. {...ModalProps}>
  451. <RegisterDialog
  452. address={this.state.email}
  453. onClose={() => this.hideDialog()}
  454. />
  455. </Modal>
  456. </View>
  457. );
  458. }
  459. }
  460. const UploadView = ({url, onPress}) => (
  461. <Pressable
  462. style={styles.uploadView}
  463. onPress={onPress}>
  464. { url == ''
  465. ? <Image
  466. style={styles.uploadIcon}
  467. source={require('../../images/icon/ic-add-photo.png')}/>
  468. : <Image
  469. style={styles.uploadIcon}
  470. defaultSource={require('../../images/icon/icon-upload-default.png')}
  471. source={{uri: host + url}}/>
  472. }
  473. </Pressable>
  474. )
  475. const styles = StyleSheet.create({
  476. container: {
  477. flex: 1,
  478. backgroundColor: colorLight
  479. },
  480. header: {
  481. paddingTop: 56,
  482. backgroundColor: colorAccent
  483. },
  484. backView: {
  485. top: 12,
  486. zIndex: 5,
  487. padding: 16,
  488. position: 'absolute',
  489. flexDirection: 'row'
  490. },
  491. backButton: {
  492. borderRadius: 60,
  493. backgroundColor: colorLight
  494. },
  495. backButtonView: {
  496. height: 43,
  497. paddingLeft: 16,
  498. paddingRight: 16,
  499. alignItems: 'center',
  500. flexDirection: 'row'
  501. },
  502. scollView: {
  503. flex: 1
  504. },
  505. logoView: {
  506. paddingTop: 32,
  507. paddingBottom: 56,
  508. alignItems: 'center'
  509. },
  510. logoImg: {
  511. width:165.09,
  512. height: 51.94,
  513. },
  514. signView: {
  515. flex: 1,
  516. padding: 16,
  517. //marginTop: -30,
  518. borderTopLeftRadius: 20,
  519. borderTopRightRadius: 20,
  520. backgroundColor: colorLight
  521. },
  522. tabView: {
  523. marginBottom: 4,
  524. borderWidth: 1,
  525. borderRadius: 6,
  526. overflow: 'hidden',
  527. alignItems: 'center',
  528. flexDirection: 'row',
  529. borderColor: colorAccent,
  530. },
  531. tabText: {
  532. flex: 1,
  533. color: textPrimary,
  534. fontSize: 15,
  535. textAlign: 'center',
  536. ...$padding(10, 0),
  537. },
  538. tabActive: {
  539. fontWeight: 'bold',
  540. backgroundColor: colorAccent
  541. },
  542. title: {
  543. color: textPrimary,
  544. fontSize: 18,
  545. fontWeight: '700',
  546. paddingTop: 4,
  547. paddingBottom: 6,
  548. },
  549. signInput: {
  550. marginTop: 16,
  551. alignItems: 'center',
  552. flexDirection: 'row'
  553. },
  554. inputLabel: {
  555. flex: 1,
  556. color: textPrimary,
  557. fontSize: 14,
  558. marginRight: 4
  559. },
  560. inputView: {
  561. flex: 2,
  562. color: textPrimary,
  563. fontSize: 14,
  564. borderRadius: 5,
  565. minHeight: 40,
  566. paddingTop: 6,
  567. paddingLeft: 12,
  568. paddingRight: 12,
  569. paddingBottom: 6,
  570. backgroundColor: '#F5F5F5'
  571. },
  572. mobileView: {
  573. flex: 2,
  574. marginLeft: -12,
  575. alignItems: 'center',
  576. flexDirection: 'row'
  577. },
  578. dropView: {
  579. fontSize: 16,
  580. borderRadius: 4,
  581. paddingRight: 4,
  582. flexDirection: 'row',
  583. alignItems: 'center',
  584. backgroundColor: '#F5F5F5'
  585. },
  586. dropInput: {
  587. width: 12,
  588. padding: 6,
  589. color: textPrimary,
  590. minHeight: 40,
  591. },
  592. countryText: {
  593. color: textPrimary,
  594. fontSize: 14,
  595. paddingRight: 4
  596. },
  597. dropLayer: {
  598. left: 0,
  599. right: 0,
  600. opacity: 0,
  601. position: 'absolute'
  602. },
  603. contactView: {
  604. flex: 1,
  605. color: textPrimary,
  606. fontSize: 15,
  607. borderRadius: 4,
  608. minHeight: 40,
  609. paddingTop: 6,
  610. paddingLeft: 12,
  611. paddingRight: 12,
  612. paddingBottom: 6,
  613. marginLeft: 10,
  614. backgroundColor: '#F5F5F5'
  615. },
  616. passwordView: {
  617. flex: 2,
  618. marginTop: -8,
  619. },
  620. referView: {
  621. padding: 16,
  622. marginTop: 24,
  623. borderRadius: 6,
  624. alignItems: 'center',
  625. backgroundColor: '#F5F5F5'
  626. },
  627. referTitle: {
  628. color: textPrimary,
  629. fontSize: 18,
  630. fontWeight: 'bold'
  631. },
  632. referText: {
  633. color: textPrimary,
  634. paddingTop: 4,
  635. alignItems: 'flex-end',
  636. flexDirection: 'row'
  637. },
  638. weight: {
  639. fontSize: 18,
  640. paddingLeft: 4,
  641. paddingRight: 4,
  642. color: colorAccent,
  643. fontWeight: 'bold'
  644. },
  645. codeView: {
  646. paddingTop: 16,
  647. alignItems: 'center',
  648. flexDirection: 'row'
  649. },
  650. codeText: {
  651. color: textPrimary,
  652. fontSize: 16,
  653. paddingTop: 6,
  654. paddingLeft: 12,
  655. paddingRight: 12,
  656. paddingBottom: 6,
  657. minHeight: 40,
  658. marginLeft: 16,
  659. borderRadius: 6,
  660. textAlign: 'center',
  661. backgroundColor: colorLight
  662. },
  663. signButton: {
  664. marginTop: 24,
  665. marginBottom: 8,
  666. },
  667. uploadGroup: {
  668. flex: 2,
  669. alignItems: 'center',
  670. flexDirection: 'row',
  671. justifyContent: 'center'
  672. },
  673. uploadView: {
  674. flex: 1,
  675. alignItems: 'center'
  676. },
  677. uploadIcon: {
  678. width: $vw(28),
  679. height: $vw(28),
  680. borderRadius: 6
  681. },
  682. agreeView: {
  683. marginTop: 24,
  684. marginBottom: 16,
  685. flexDirection: 'row',
  686. alignItems: 'flex-start',
  687. },
  688. agreeTextRow: {
  689. flex: 1,
  690. paddingTop: 4,
  691. paddingLeft: 8,
  692. flexWrap: 'wrap',
  693. flexDirection: 'row'
  694. },
  695. agreeText: {
  696. color: textPrimary,
  697. fontSize: 14,
  698. paddingTop: 2,
  699. paddingBottom: 2
  700. },
  701. agreeLink: {
  702. ...ui.link,
  703. fontSize: 14,
  704. paddingTop: 2,
  705. paddingBottom: 2,
  706. textDecorationLine: 'underline'
  707. }
  708. });