RegisterPublic.js 18 KB

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