RegisterV3.js 18 KB

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