RegisterPublic.js 19 KB

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