RegisterDriver.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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, backgroundColor: "#F0F0F0"}}
  429. resizeMode="cover"
  430. source={{uri: utils.getImageUrl(url)}}/>
  431. }
  432. </Pressable>
  433. )
  434. const styles = StyleSheet.create({
  435. container: {
  436. flex: 1,
  437. backgroundColor: colorLight
  438. },
  439. header: {
  440. paddingTop: 56,
  441. backgroundColor: colorAccent
  442. },
  443. backView: {
  444. top: 12,
  445. zIndex: 5,
  446. padding: 16,
  447. position: 'absolute',
  448. flexDirection: 'row'
  449. },
  450. backButton: {
  451. borderRadius: 60,
  452. backgroundColor: colorLight
  453. },
  454. backButtonView: {
  455. height: 43,
  456. paddingLeft: 16,
  457. paddingRight: 16,
  458. alignItems: 'center',
  459. flexDirection: 'row'
  460. },
  461. scollView: {
  462. flex: 1
  463. },
  464. logoView: {
  465. paddingTop: 32,
  466. paddingBottom: 56,
  467. alignItems: 'center'
  468. },
  469. logoImg: {
  470. width:165.09,
  471. height: 51.94,
  472. },
  473. signView: {
  474. flex: 1,
  475. padding: 16,
  476. //marginTop: -30,
  477. borderTopLeftRadius: 20,
  478. borderTopRightRadius: 20,
  479. backgroundColor: colorLight
  480. },
  481. tabView: {
  482. marginBottom: 4,
  483. borderWidth: 1,
  484. borderRadius: 6,
  485. overflow: 'hidden',
  486. alignItems: 'center',
  487. flexDirection: 'row',
  488. borderColor: colorAccent,
  489. },
  490. tabText: {
  491. flex: 1,
  492. color: textPrimary,
  493. fontSize: 15,
  494. textAlign: 'center',
  495. ...$padding(10, 0),
  496. },
  497. tabActive: {
  498. fontWeight: 'bold',
  499. backgroundColor: colorAccent
  500. },
  501. title: {
  502. color: textPrimary,
  503. fontSize: 18,
  504. fontWeight: '700',
  505. paddingTop: 4,
  506. paddingBottom: 6,
  507. },
  508. signInput: {
  509. marginTop: 16,
  510. alignItems: 'center',
  511. flexDirection: 'row'
  512. },
  513. inputLabel: {
  514. flex: 1,
  515. color: textPrimary,
  516. fontSize: 14,
  517. marginRight: 4
  518. },
  519. inputView: {
  520. flex: 2,
  521. color: textPrimary,
  522. fontSize: 14,
  523. borderRadius: 5,
  524. minHeight: 40,
  525. paddingTop: 6,
  526. paddingLeft: 12,
  527. paddingRight: 12,
  528. paddingBottom: 6,
  529. backgroundColor: '#F5F5F5'
  530. },
  531. mobileView: {
  532. flex: 2,
  533. marginLeft: -12,
  534. alignItems: 'center',
  535. flexDirection: 'row'
  536. },
  537. dropView: {
  538. fontSize: 16,
  539. borderRadius: 4,
  540. paddingRight: 4,
  541. flexDirection: 'row',
  542. alignItems: 'center',
  543. backgroundColor: '#F5F5F5'
  544. },
  545. dropInput: {
  546. width: 12,
  547. padding: 6,
  548. color: textPrimary,
  549. minHeight: 40,
  550. },
  551. countryText: {
  552. color: textPrimary,
  553. fontSize: 14,
  554. paddingRight: 4
  555. },
  556. dropLayer: {
  557. left: 0,
  558. right: 0,
  559. opacity: 0,
  560. position: 'absolute'
  561. },
  562. contactView: {
  563. flex: 1,
  564. color: textPrimary,
  565. fontSize: 15,
  566. borderRadius: 4,
  567. minHeight: 40,
  568. paddingTop: 6,
  569. paddingLeft: 12,
  570. paddingRight: 12,
  571. paddingBottom: 6,
  572. marginLeft: 10,
  573. backgroundColor: '#F5F5F5'
  574. },
  575. passwordView: {
  576. flex: 2,
  577. marginTop: -8,
  578. },
  579. referView: {
  580. padding: 16,
  581. marginTop: 24,
  582. borderRadius: 6,
  583. alignItems: 'center',
  584. backgroundColor: '#F5F5F5'
  585. },
  586. referTitle: {
  587. color: textPrimary,
  588. fontSize: 18,
  589. fontWeight: 'bold'
  590. },
  591. referText: {
  592. color: textPrimary,
  593. paddingTop: 4,
  594. alignItems: 'flex-end',
  595. flexDirection: 'row'
  596. },
  597. weight: {
  598. fontSize: 18,
  599. paddingLeft: 4,
  600. paddingRight: 4,
  601. color: colorAccent,
  602. fontWeight: 'bold'
  603. },
  604. codeView: {
  605. paddingTop: 16,
  606. alignItems: 'center',
  607. flexDirection: 'row'
  608. },
  609. codeText: {
  610. color: textPrimary,
  611. fontSize: 16,
  612. paddingTop: 6,
  613. paddingLeft: 12,
  614. paddingRight: 12,
  615. paddingBottom: 6,
  616. minHeight: 40,
  617. marginLeft: 16,
  618. borderRadius: 6,
  619. textAlign: 'center',
  620. backgroundColor: colorLight
  621. },
  622. signButton: {
  623. marginTop: 24,
  624. marginBottom: 8,
  625. },
  626. uploadGroup: {
  627. flex: 2,
  628. alignItems: 'center',
  629. flexDirection: 'row',
  630. justifyContent: 'center'
  631. },
  632. uploadView: {
  633. flex: 1,
  634. alignItems: 'center'
  635. },
  636. uploadIcon: {
  637. width: $vw(28),
  638. height: $vw(28),
  639. borderRadius: 6
  640. },
  641. agreeView: {
  642. marginTop: 24,
  643. marginBottom: 16,
  644. flexDirection: 'row',
  645. alignItems: 'flex-start',
  646. },
  647. agreeTextRow: {
  648. flex: 1,
  649. paddingTop: 4,
  650. paddingLeft: 8,
  651. flexWrap: 'wrap',
  652. flexDirection: 'row'
  653. },
  654. agreeText: {
  655. color: textPrimary,
  656. fontSize: 14,
  657. paddingTop: 2,
  658. paddingBottom: 2
  659. },
  660. agreeLink: {
  661. ...ui.link,
  662. fontSize: 14,
  663. paddingTop: 2,
  664. paddingBottom: 2,
  665. textDecorationLine: 'underline'
  666. }
  667. });