RegisterV3.js 19 KB

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