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. import utils from '../../utils/utils';
  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 RegisterPublic extends React.Component {
  36. constructor(props) {
  37. super(props);
  38. this.StrengthView = StrengthView.V1
  39. this.state = {
  40. agree: true,
  41. strength: 0,
  42. countryNum: '65',
  43. countryShow: false,
  44. userInfo: {},
  45. countryNums: [],
  46. wrongCount: 0,
  47. params: {...this.props.route.params},
  48. email: '',
  49. password: '',
  50. fleetCompanyId: '',
  51. visible: false,
  52. isFleetDriver: false,
  53. pdvImages: ['', ''],
  54. companyList: []
  55. };
  56. }
  57. componentDidMount() {
  58. //console.log(this.state.params);
  59. this.getCountryList();
  60. this.getCompanyList();
  61. }
  62. applyStrength(text) {
  63. this.StrengthView.apply(text, strength => {
  64. if (this.state.strength != strength) {
  65. this.setState({
  66. password: text,
  67. strength: strength
  68. });
  69. } else {
  70. this.setState({
  71. password: text
  72. });
  73. }
  74. });
  75. }
  76. changeInfo(key, value) {
  77. var info = this.state.userInfo;
  78. info[key] = value;
  79. this.setState({
  80. 'userInfo': info
  81. });
  82. }
  83. getCountryList() {
  84. GetCountryList(list => {
  85. this.setState({
  86. countryNums: list
  87. })
  88. })
  89. }
  90. getCompanyList() {
  91. apiUser.getConmpany().then(res => {
  92. if (res.data) {
  93. this.setState({
  94. companyList: res.data
  95. })
  96. }
  97. }).catch(err => [
  98. toastShort(err)
  99. ])
  100. }
  101. onRegister() {
  102. //console.log('sign up', this.state);
  103. var info = this.state.userInfo;
  104. if (!info.nickName) {
  105. toastShort('Please enter display name');
  106. return;
  107. }
  108. if (!info.email) {
  109. toastShort('Please enter email address');
  110. return;
  111. }
  112. if (!utils.isValidEmail(info.email)) {
  113. toastShort('Email is incorrect format');
  114. return;
  115. }
  116. if (!info.phone) {
  117. toastShort('Please enter contact number');
  118. return;
  119. }
  120. if (!/^\d{6,15}$/.test(info.phone)) {
  121. toastShort('Phone Number is incorrect format');
  122. return;
  123. }
  124. if (!this.state.password) {
  125. toastShort('Please enter password');
  126. return;
  127. }
  128. if (this.state.strength < this.StrengthView.maxStrength) {
  129. toastShort('Password is not strong');
  130. return;
  131. }
  132. if (!info.password) {
  133. toastShort('Please enter confirm password');
  134. return;
  135. }
  136. if (info.password != this.state.password) {
  137. toastShort('The twice passwords are inconsistent');
  138. if (this.state.wrongCount < 3) {
  139. this.setState({
  140. wrongCount: this.state.wrongCount + 1
  141. })
  142. }
  143. return;
  144. }
  145. if (this.state.isFleetDriver) {
  146. if (!info.pdvLicence) {
  147. toastShort('Please enter PDV Licence');
  148. return;
  149. }
  150. if (this.state.pdvImages[0] == '' || this.state.pdvImages[1] == '') {
  151. toastShort('Please upload PDV Licence Photos');
  152. return;
  153. }
  154. }
  155. let param = Object.assign({}, info);
  156. //param.phone = this.state.countryNum + info.phone
  157. param.callingCode = this.state.countryNum;
  158. if (this.state.isFleetDriver) {
  159. param.userType = 'Driver';
  160. param.pdvLicencePictures = this.state.pdvImages;
  161. param.fleetCompanyId = this.state.fleetCompanyId;
  162. } else {
  163. param.userType = 'Public';
  164. }
  165. console.log('params', param);
  166. Dialog.showProgressDialog();
  167. apiUser.register(param).then(res => {
  168. Dialog.dismissLoading();
  169. //toastShort('Sign up successfully!');
  170. this.setState({
  171. email: param.email,
  172. visible: true
  173. });
  174. //this.backToLogin();
  175. }).catch(err => {
  176. toastShort(err);
  177. Dialog.dismissLoading();
  178. });
  179. }
  180. getBackTopPosition() {
  181. return isIOS ? statusHeight - 16 : 8;
  182. }
  183. backToLogin() {
  184. if (this.state.params.actionLogin) {
  185. goBack()
  186. startPage(PageList.login);
  187. } else {
  188. goBack();
  189. }
  190. }
  191. uploadImage(index) {
  192. ImagePicker.openPicker(options).then(image => {
  193. if (image.path) {
  194. apiUpload.uploadImage(image.path, image.mime, 'PDVL').then(res => {
  195. if (res.success && res.data.picturePath) {
  196. let imageUrl = this.state.pdvImages;
  197. imageUrl[index] = res.data.picturePath;
  198. this.setState({
  199. pdvImages: imageUrl
  200. });
  201. } else {
  202. toastShort('Upload failed, please retry');
  203. }
  204. }).catch(err => {
  205. toastShort(err);
  206. });
  207. }
  208. }).catch(err => {
  209. //console.log(err);
  210. });
  211. }
  212. changeAgree(ag) {
  213. this.setState({
  214. agree: ag
  215. })
  216. }
  217. hideDialog() {
  218. this.setState({
  219. visible: false
  220. });
  221. this.backToLogin();
  222. }
  223. render() {
  224. return (
  225. <View style={styles.container}>
  226. <ScrollView
  227. style={styles.scollView}
  228. keyboardShouldPersistTaps={isIOS ? 'never' : 'handled'}>
  229. <View style={styles.signView}>
  230. {/* <View style={styles.tabView}>
  231. <Text
  232. style={[
  233. styles.tabText,
  234. this.state.isFleetDriver ? {} : styles.tabActive
  235. ]}
  236. onPress={() => this.changeTab(false)}
  237. >Public Users</Text>
  238. <Text
  239. style={[
  240. styles.tabText,
  241. this.state.isFleetDriver ? styles.tabActive: {}
  242. ]}
  243. onPress={() => this.changeTab(true)}
  244. >Fleet/PH Drivers</Text>
  245. </View> */}
  246. <View style={styles.signInput}>
  247. <Text style={styles.inputLabel}>Display Name</Text>
  248. <TextInput
  249. style={styles.inputView}
  250. placeholder='Display Name'
  251. placeholderTextColor={textPlacehoder}
  252. maxLength={50}
  253. onChangeText={v => this.changeInfo('nickName', v)}
  254. />
  255. </View>
  256. <View style={styles.signInput}>
  257. <Text style={styles.inputLabel}>Email Address</Text>
  258. <TextInput
  259. style={styles.inputView}
  260. placeholder='Email Address'
  261. placeholderTextColor={textPlacehoder}
  262. maxLength={50}
  263. keyboardType="email-address"
  264. textContentType='emailAddress'
  265. onChangeText={v => this.changeInfo('email', v)}
  266. />
  267. </View>
  268. <View style={styles.signInput}>
  269. <Text style={styles.inputLabel}>Phone Number</Text>
  270. <View style={styles.mobileView}>
  271. <View style={styles.dropView}>
  272. <TextInput style={styles.dropInput} editable={false}/>
  273. <Text style={styles.countryText}>{"+" + this.state.countryNum}</Text>
  274. <MaterialIcons name={'arrow-drop-down'} size={24} color={colorDark}/>
  275. <Dropdown
  276. style={styles.dropLayer}
  277. title='Country'
  278. prefixText="+"
  279. list={this.state.countryNums}
  280. value={this.state.countryNum}
  281. nameKey='countryNum'
  282. valueKey='countryNum'
  283. onChange={(value, index)=> {
  284. this.setState({
  285. countryNum: value
  286. })
  287. }}
  288. customerItemView={
  289. (item, index, onClick) =>
  290. <CountryDropNum
  291. key={index}
  292. country={item}
  293. value={this.state.countryNum}
  294. onClick={onClick}/>
  295. }/>
  296. </View>
  297. <TextInput
  298. style={styles.contactView}
  299. placeholder='Mobile Number'
  300. placeholderTextColor={textPlacehoder}
  301. keyboardType='phone-pad'
  302. maxLength={15}
  303. onChangeText={v => this.changeInfo('phone', v)}
  304. />
  305. </View>
  306. </View>
  307. <View style={styles.signInput}>
  308. <Text style={styles.inputLabel}>Create Password</Text>
  309. <TextInput
  310. secureTextEntry={this.state.wrongCount < 3}
  311. style={styles.inputView}
  312. placeholder='Password'
  313. placeholderTextColor={textPlacehoder}
  314. maxLength={20}
  315. onChangeText={(value) => {
  316. this.applyStrength(value);
  317. }}
  318. />
  319. </View>
  320. <View style={styles.signInput}>
  321. <Text style={styles.inputLabel}></Text>
  322. <View style={styles.passwordView}>
  323. <this.StrengthView.VIEW strength={this.state.strength}/>
  324. </View>
  325. </View>
  326. <View style={styles.signInput}>
  327. <Text style={styles.inputLabel}>Confirm Password</Text>
  328. <TextInput
  329. secureTextEntry={this.state.wrongCount < 3}
  330. style={styles.inputView}
  331. placeholder='Password'
  332. placeholderTextColor={textPlacehoder}
  333. maxLength={20}
  334. onChangeText={v => this.changeInfo('password', v)}
  335. />
  336. </View>
  337. { this.state.isFleetDriver &&
  338. <>
  339. <View style={styles.signInput}>
  340. <Text style={styles.inputLabel}>Your Company</Text>
  341. <Dropdown
  342. style={[styles.inputView, ui.flexc]}
  343. title='Company'
  344. list={this.state.companyList}
  345. value={this.state.fleetCompanyId}
  346. valueKey='fleetCompanyId'
  347. nameKey='fleetCompanyName'
  348. onChange={(value, index)=> {
  349. this.setState({
  350. fleetCompanyId: value
  351. })
  352. }}/>
  353. </View>
  354. <View style={styles.signInput}>
  355. <Text style={styles.inputLabel}>{'PDV Licence'}</Text>
  356. <TextInput
  357. style={styles.inputView}
  358. placeholder='PH Driver Vocational Licence'
  359. placeholderTextColor={textPlacehoder}
  360. maxLength={20}
  361. onChangeText={v => this.changeInfo('pdvLicence', v)}
  362. />
  363. </View>
  364. <View style={styles.signInput}>
  365. <Text style={styles.inputLabel}>{' PDV Photos\n(Front & Back)'}</Text>
  366. <View style={styles.uploadGroup}>
  367. { this.state.pdvImages.map((item, index) => (
  368. <UploadView
  369. key={index}
  370. onPress={() => this.uploadImage(index)}
  371. url={item}/>
  372. ))
  373. }
  374. </View>
  375. </View>
  376. </>
  377. }
  378. {/* <View style={styles.referView}>
  379. <Text style={styles.referTitle}>Have a referral code?</Text>
  380. <View style={styles.referText}>
  381. <Text>You'll get</Text>
  382. <Text style={styles.weight}>$5</Text>
  383. <Text>Credit as registration bonus!</Text>
  384. </View>
  385. <View style={styles.codeView}>
  386. <Text style={{ color: textPrimary, fontSize: 16 }}>Referral Code</Text>
  387. <TextInput
  388. style={styles.codeText}
  389. maxLength={6}
  390. placeholder='Referral Code'
  391. placeholderTextColor={textPlacehoder}
  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. 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. });