RegisterV2.js 19 KB

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