RegisterDriver.js 18 KB

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