RegisterV2.js 20 KB

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