RegisterDriver.js 18 KB

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