RegisterV2.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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. maxLength={50}
  267. onChangeText={v => this.changeInfo('nickName', v)}
  268. />
  269. </View>
  270. <View style={styles.signInput}>
  271. <Text style={styles.inputLabel}>Email Address</Text>
  272. <TextInput
  273. style={styles.inputView}
  274. placeholder='Email Address'
  275. maxLength={50}
  276. onChangeText={v => this.changeInfo('email', v)}
  277. />
  278. </View>
  279. <View style={styles.signInput}>
  280. <Text style={styles.inputLabel}>Phone Number</Text>
  281. <View style={styles.mobileView}>
  282. <View style={styles.dropView}>
  283. <TextInput style={styles.dropInput} editable={false}/>
  284. <Text style={styles.countryText}>{"+" + this.state.countryNum}</Text>
  285. <MaterialIcons name={'arrow-drop-down'} size={24} color={colorDark}/>
  286. <Dropdown
  287. style={styles.dropLayer}
  288. title='Country'
  289. prefixText="+"
  290. list={this.state.countryNums}
  291. value={this.state.countryNum}
  292. nameKey='countryNum'
  293. valueKey='countryNum'
  294. onChange={(value, index)=> {
  295. this.setState({
  296. countryNum: value
  297. })
  298. }}
  299. customerItemView={
  300. (item, index, onClick) =>
  301. <CountryDropNum
  302. key={index}
  303. country={item}
  304. value={this.state.countryNum}
  305. onClick={onClick}/>
  306. }/>
  307. </View>
  308. <TextInput
  309. style={styles.contactView}
  310. placeholder='Mobile Number'
  311. keyboardType='phone-pad'
  312. maxLength={15}
  313. onChangeText={v => this.changeInfo('phone', v)}
  314. />
  315. </View>
  316. </View>
  317. <View style={styles.signInput}>
  318. <Text style={styles.inputLabel}>Create Password</Text>
  319. <TextInput
  320. secureTextEntry={this.state.wrongCount < 3}
  321. style={styles.inputView}
  322. placeholder='Password'
  323. maxLength={20}
  324. onChangeText={(value) => {
  325. this.applyStrength(value);
  326. }}
  327. />
  328. </View>
  329. <View style={styles.signInput}>
  330. <Text style={styles.inputLabel}></Text>
  331. <View style={styles.passwordView}>
  332. <StrengthView.V4.VIEW {...this.state}/>
  333. </View>
  334. </View>
  335. <View style={styles.signInput}>
  336. <Text style={styles.inputLabel}>Confirm Password</Text>
  337. <TextInput
  338. secureTextEntry={this.state.wrongCount < 3}
  339. style={styles.inputView}
  340. placeholder='Password'
  341. maxLength={20}
  342. onChangeText={v => this.changeInfo('password', v)}
  343. />
  344. </View>
  345. { this.state.isFleetDriver &&
  346. <>
  347. <View style={styles.signInput}>
  348. <Text style={styles.inputLabel}>Your Company</Text>
  349. <Dropdown
  350. style={[styles.inputView, ui.flexc]}
  351. title='Company'
  352. list={this.state.companyList}
  353. value={this.state.fleetCompanyId}
  354. valueKey='fleetCompanyId'
  355. nameKey='fleetCompanyName'
  356. onChange={(value, index)=> {
  357. this.setState({
  358. fleetCompanyId: value
  359. })
  360. }}/>
  361. </View>
  362. <View style={styles.signInput}>
  363. <Text style={styles.inputLabel}>{'PDV Licence'}</Text>
  364. <TextInput
  365. style={styles.inputView}
  366. placeholder='PH Driver Vocational Licence'
  367. maxLength={20}
  368. onChangeText={v => this.changeInfo('pdvLicence', v)}
  369. />
  370. </View>
  371. <View style={styles.signInput}>
  372. <Text style={styles.inputLabel}>{' PDV Photos\n(Front & Back)'}</Text>
  373. <View style={styles.uploadGroup}>
  374. { this.state.pdvImages.map((item, index) => (
  375. <UploadView
  376. key={index}
  377. onPress={() => this.uploadImage(index)}
  378. url={item}/>
  379. ))
  380. }
  381. </View>
  382. </View>
  383. </>
  384. }
  385. <View style={styles.referView}>
  386. <Text style={styles.referTitle}>Have a referral code?</Text>
  387. <View style={styles.referText}>
  388. <Text>You'll get</Text>
  389. <Text style={styles.weight}>$5</Text>
  390. <Text>Credit as registration bonus!</Text>
  391. </View>
  392. <View style={styles.codeView}>
  393. <Text style={{ color: textPrimary, fontSize: 16 }}>Referral Code</Text>
  394. <TextInput
  395. style={styles.codeText}
  396. maxLength={6}
  397. placeholder='Referral Code'
  398. onChangeText={v => this.changeInfo('referralCode', v)}
  399. />
  400. </View>
  401. </View>
  402. <View style={styles.agreeView}>
  403. <CheckBox
  404. value={this.state.agree}
  405. onValueChange={v => this.changeAgree(v)}
  406. />
  407. <View style={styles.agreeTextRow}>
  408. <Text style={styles.agreeText} onPress={() => this.changeAgree(!this.state.agree)}>
  409. {'I have read and I agree with the '}
  410. </Text>
  411. <Text style={styles.agreeLink} onPress={() => startPage(PageList.condition)}>Terms of Use</Text>
  412. <Text style={styles.agreeText}>{' '}</Text>
  413. <Text style={styles.agreeText}>{'and '}</Text>
  414. <Text style={styles.agreeLink} onPress={() => startPage(PageList.privacy)}>Privacy Policy</Text>
  415. <Text style={styles.agreeText}>.</Text>
  416. </View>
  417. </View>
  418. <Button
  419. style={styles.signButton}
  420. elevation={1.5}
  421. disabled={!this.state.agree}
  422. text='SIGN UP'
  423. fontSize={14}
  424. onClick={() => {
  425. this.onRegister();
  426. }}
  427. />
  428. </View>
  429. </ScrollView>
  430. <Modal
  431. isVisible={this.state.visible}
  432. onBackButtonPress={() => this.hideDialog()}
  433. {...ModalProps}>
  434. <RegisterDialog
  435. address={this.state.email}
  436. onClose={() => this.hideDialog()}
  437. />
  438. </Modal>
  439. </View>
  440. );
  441. }
  442. }
  443. const UploadView = ({url, onPress}) => (
  444. <Pressable
  445. style={styles.uploadView}
  446. onPress={onPress}>
  447. { url == ''
  448. ? <Image
  449. style={styles.uploadIcon}
  450. source={require('../../images/icon/ic-add-photo.png')}/>
  451. : <Image
  452. style={styles.uploadIcon}
  453. defaultSource={require('../../images/icon/icon-upload-default.png')}
  454. source={{uri: host + url}}/>
  455. }
  456. </Pressable>
  457. )
  458. const styles = StyleSheet.create({
  459. header: {
  460. paddingTop: 56,
  461. backgroundColor: colorThemes
  462. },
  463. backView: {
  464. top: 12,
  465. zIndex: 5,
  466. padding: 16,
  467. position: 'absolute',
  468. flexDirection: 'row'
  469. },
  470. backButton: {
  471. borderRadius: 60,
  472. backgroundColor: colorLight
  473. },
  474. backButtonView: {
  475. height: 43,
  476. paddingLeft: 16,
  477. paddingRight: 16,
  478. alignItems: 'center',
  479. flexDirection: 'row'
  480. },
  481. scollView: {
  482. flex: 1
  483. },
  484. logoView: {
  485. flex: 1,
  486. paddingRight: 48,
  487. alignItems: 'center',
  488. justifyContent: 'center'
  489. },
  490. logoImg: {
  491. width:165.09,
  492. height: 51.94,
  493. },
  494. signView: {
  495. flex: 1,
  496. padding: 16,
  497. marginTop: 0,
  498. borderTopLeftRadius: 20,
  499. borderTopRightRadius: 20,
  500. backgroundColor: colorLight
  501. },
  502. tabView: {
  503. marginBottom: 4,
  504. borderWidth: 1,
  505. borderRadius: 60,
  506. overflow: 'hidden',
  507. alignItems: 'center',
  508. flexDirection: 'row',
  509. borderColor: colorPrimary,
  510. },
  511. tabText: {
  512. flex: 1,
  513. color: textPrimary,
  514. fontSize: 15,
  515. textAlign: 'center',
  516. ...$padding(10, 0),
  517. },
  518. tabActive: {
  519. color: textLight,
  520. fontWeight: 'bold',
  521. backgroundColor: colorPrimary
  522. },
  523. title: {
  524. color: textPrimary,
  525. fontSize: 18,
  526. fontWeight: '700',
  527. paddingTop: 4,
  528. paddingBottom: 6,
  529. },
  530. signInput: {
  531. marginTop: 16,
  532. alignItems: 'center',
  533. flexDirection: 'row'
  534. },
  535. inputLabel: {
  536. flex: 1,
  537. color: textPrimary,
  538. fontSize: 14,
  539. marginRight: 4
  540. },
  541. inputView: {
  542. flex: 2,
  543. color: textPrimary,
  544. fontSize: 14,
  545. borderRadius: 5,
  546. minHeight: 40,
  547. paddingTop: 6,
  548. paddingLeft: 12,
  549. paddingRight: 12,
  550. paddingBottom: 6,
  551. backgroundColor: '#F5F5F5'
  552. },
  553. mobileView: {
  554. flex: 2,
  555. marginLeft: -12,
  556. alignItems: 'center',
  557. flexDirection: 'row'
  558. },
  559. dropView: {
  560. fontSize: 16,
  561. borderRadius: 4,
  562. paddingRight: 4,
  563. flexDirection: 'row',
  564. alignItems: 'center',
  565. backgroundColor: '#F5F5F5'
  566. },
  567. dropInput: {
  568. width: 12,
  569. padding: 6,
  570. color: textPrimary,
  571. minHeight: 40,
  572. },
  573. countryText: {
  574. color: textPrimary,
  575. fontSize: 14,
  576. paddingRight: 4
  577. },
  578. dropLayer: {
  579. left: 0,
  580. right: 0,
  581. opacity: 0,
  582. position: 'absolute'
  583. },
  584. contactView: {
  585. flex: 1,
  586. color: textPrimary,
  587. fontSize: 15,
  588. borderRadius: 4,
  589. minHeight: 40,
  590. paddingTop: 6,
  591. paddingLeft: 12,
  592. paddingRight: 12,
  593. paddingBottom: 6,
  594. marginLeft: 10,
  595. backgroundColor: '#F5F5F5'
  596. },
  597. passwordView: {
  598. flex: 2,
  599. marginTop: -8,
  600. },
  601. strengthView: {
  602. marginTop: -4,
  603. alignItems: 'center',
  604. paddingBottom: 4,
  605. flexDirection: 'row'
  606. },
  607. passwordRole: {
  608. color: '#999',
  609. fontSize: 10,
  610. lineHeight: 13
  611. },
  612. strengthItem: {
  613. width: 14,
  614. height: 2.5,
  615. marginLeft: 8,
  616. borderRadius: 3,
  617. backgroundColor: '#CCC'
  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. });