RegisterDriver.js 18 KB

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