RegisterV3.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. /**
  2. * 公共用户和司机用户注册页面
  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 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 { ModalProps } from '../../components/BottomModal';
  17. import { CountryDropNum, GetCountryList } from '../../components/CountryIcon';
  18. import StrengthView from './StrengthView';
  19. import CheckBox from '../../components/CheckBox';
  20. import { UploadThemes } from '../../components/ThemesConfig';
  21. import TextView from '../../components/TextView';
  22. import utils from '../../utils/utils';
  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 (!utils.isValidEmail(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={isIOS ? 'never' : '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. source={{uri: utils.getImageUrl(url)}}/>
  471. }
  472. </Pressable>
  473. )
  474. const styles = StyleSheet.create({
  475. container: {
  476. flex: 1,
  477. backgroundColor: colorLight
  478. },
  479. header: {
  480. paddingTop: 56,
  481. backgroundColor: colorAccent
  482. },
  483. backView: {
  484. top: 12,
  485. zIndex: 5,
  486. padding: 16,
  487. position: 'absolute',
  488. flexDirection: 'row'
  489. },
  490. backButton: {
  491. borderRadius: 60,
  492. backgroundColor: colorLight
  493. },
  494. backButtonView: {
  495. height: 43,
  496. paddingLeft: 16,
  497. paddingRight: 16,
  498. alignItems: 'center',
  499. flexDirection: 'row'
  500. },
  501. scollView: {
  502. flex: 1
  503. },
  504. logoView: {
  505. paddingTop: 32,
  506. paddingBottom: 56,
  507. alignItems: 'center'
  508. },
  509. logoImg: {
  510. width:165.09,
  511. height: 51.94,
  512. },
  513. signView: {
  514. flex: 1,
  515. padding: 16,
  516. //marginTop: -30,
  517. borderTopLeftRadius: 20,
  518. borderTopRightRadius: 20,
  519. backgroundColor: colorLight
  520. },
  521. tabView: {
  522. marginBottom: 4,
  523. borderWidth: 1,
  524. borderRadius: 6,
  525. overflow: 'hidden',
  526. alignItems: 'center',
  527. flexDirection: 'row',
  528. borderColor: colorAccent,
  529. },
  530. tabText: {
  531. flex: 1,
  532. color: textPrimary,
  533. fontSize: 15,
  534. textAlign: 'center',
  535. ...$padding(10, 0),
  536. },
  537. tabActive: {
  538. fontWeight: 'bold',
  539. backgroundColor: colorAccent
  540. },
  541. title: {
  542. color: textPrimary,
  543. fontSize: 18,
  544. fontWeight: '700',
  545. paddingTop: 4,
  546. paddingBottom: 6,
  547. },
  548. signInput: {
  549. marginTop: 16,
  550. alignItems: 'center',
  551. flexDirection: 'row'
  552. },
  553. inputLabel: {
  554. flex: 1,
  555. color: textPrimary,
  556. fontSize: 14,
  557. marginRight: 4
  558. },
  559. inputView: {
  560. flex: 2,
  561. color: textPrimary,
  562. fontSize: 14,
  563. borderRadius: 5,
  564. minHeight: 40,
  565. paddingTop: 6,
  566. paddingLeft: 12,
  567. paddingRight: 12,
  568. paddingBottom: 6,
  569. backgroundColor: '#F5F5F5'
  570. },
  571. mobileView: {
  572. flex: 2,
  573. marginLeft: -12,
  574. alignItems: 'center',
  575. flexDirection: 'row'
  576. },
  577. dropView: {
  578. fontSize: 16,
  579. borderRadius: 4,
  580. paddingRight: 4,
  581. flexDirection: 'row',
  582. alignItems: 'center',
  583. backgroundColor: '#F5F5F5'
  584. },
  585. dropInput: {
  586. width: 12,
  587. padding: 6,
  588. color: textPrimary,
  589. minHeight: 40,
  590. },
  591. countryText: {
  592. color: textPrimary,
  593. fontSize: 14,
  594. paddingRight: 4
  595. },
  596. dropLayer: {
  597. left: 0,
  598. right: 0,
  599. opacity: 0,
  600. position: 'absolute'
  601. },
  602. contactView: {
  603. flex: 1,
  604. color: textPrimary,
  605. fontSize: 15,
  606. borderRadius: 4,
  607. minHeight: 40,
  608. paddingTop: 6,
  609. paddingLeft: 12,
  610. paddingRight: 12,
  611. paddingBottom: 6,
  612. marginLeft: 10,
  613. backgroundColor: '#F5F5F5'
  614. },
  615. passwordView: {
  616. flex: 2,
  617. marginTop: -8,
  618. },
  619. referView: {
  620. padding: 16,
  621. marginTop: 24,
  622. borderRadius: 6,
  623. alignItems: 'center',
  624. backgroundColor: '#F5F5F5'
  625. },
  626. referTitle: {
  627. color: textPrimary,
  628. fontSize: 18,
  629. fontWeight: 'bold'
  630. },
  631. referText: {
  632. color: textPrimary,
  633. paddingTop: 4,
  634. alignItems: 'flex-end',
  635. flexDirection: 'row'
  636. },
  637. weight: {
  638. fontSize: 18,
  639. paddingLeft: 4,
  640. paddingRight: 4,
  641. color: colorAccent,
  642. fontWeight: 'bold'
  643. },
  644. codeView: {
  645. paddingTop: 16,
  646. alignItems: 'center',
  647. flexDirection: 'row'
  648. },
  649. codeText: {
  650. color: textPrimary,
  651. fontSize: 16,
  652. paddingTop: 6,
  653. paddingLeft: 12,
  654. paddingRight: 12,
  655. paddingBottom: 6,
  656. minHeight: 40,
  657. marginLeft: 16,
  658. borderRadius: 6,
  659. textAlign: 'center',
  660. backgroundColor: colorLight
  661. },
  662. signButton: {
  663. marginTop: 24,
  664. marginBottom: 8,
  665. },
  666. uploadGroup: {
  667. flex: 2,
  668. alignItems: 'center',
  669. flexDirection: 'row',
  670. justifyContent: 'center'
  671. },
  672. uploadView: {
  673. flex: 1,
  674. alignItems: 'center'
  675. },
  676. uploadIcon: {
  677. width: $vw(28),
  678. height: $vw(28),
  679. borderRadius: 6
  680. },
  681. agreeView: {
  682. marginTop: 24,
  683. marginBottom: 16,
  684. flexDirection: 'row',
  685. alignItems: 'flex-start',
  686. },
  687. agreeTextRow: {
  688. flex: 1,
  689. paddingTop: 4,
  690. paddingLeft: 8,
  691. flexWrap: 'wrap',
  692. flexDirection: 'row'
  693. },
  694. agreeText: {
  695. color: textPrimary,
  696. fontSize: 14,
  697. paddingTop: 2,
  698. paddingBottom: 2
  699. },
  700. agreeLink: {
  701. ...ui.link,
  702. fontSize: 14,
  703. paddingTop: 2,
  704. paddingBottom: 2,
  705. textDecorationLine: 'underline'
  706. }
  707. });