/** * 注册页面 * @邠心vbe on 2021/03/23 */ import React from 'react'; import { View, Text, ScrollView, StyleSheet, TextInput, Pressable, Image } from 'react-native'; import { BackIcon } from '../../components/Toolbar'; import apiUser from '../../api/apiUser'; import Button from '../../components/Button'; import { PageList } from '../Router'; import Dialog from '../../components/Dialog'; import Modal from 'react-native-modal'; import { RegisterDialog } from '../charge/InfoDialog'; import Dropdown from '../../components/Dropdown'; import ImagePicker from 'react-native-image-crop-picker'; import apiUpload from '../../api/apiUpload'; import { host } from '../../api/http'; import CheckBox from '@react-native-community/checkbox'; import { ModalProps } from '../../components/BottomModal'; import { CountryDropNum, GetCountryList } from '../../components/CountryIcon'; const options = { width: 300, height: 200, cropping: true, multiple: false, mediaType: 'photo', writeTempFile: false, compressImageQuality: 0.8, compressImageMaxWidth: 720, compressImageMaxHeight: 1280, cropperStatusBarColor: colorAccent, cropperToolbarColor: colorAccent, cropperActiveWidgetColor: colorAccent } export const StrengthView = ({strength}) => { const getStyle = (num) => { if (strength >= num) { return {...styles.strengthItem, backgroundColor: colorAccent}; } else { return styles.strengthItem; } } return ( <> {/* */} {/* */} ); }; export default class Register extends React.Component { constructor(props) { super(props); this.state = { agree: true, strength: 0, countryNum: '65', countryShow: false, userInfo: {}, countryNums: [], wrongCount: 0, params: {...this.props.route.params}, email: '', password: '', fleetCompanyId: '', visible: false, isFleetDriver: false, pdvImages: ['', ''], companyList: [] }; } componentDidMount() { //console.log(this.state.params); this.getCountryList(); this.getCompanyList(); } applyStrength(text) { var strength = 0; if (text.length >= 8) { strength += 1; } if (/\d{1,}/.test(text)) { strength += 1; } if (/[A-z]{1,}/.test(text)) { strength += 1; } /*if (/[A-Z]{1,}/.test(text)) { strength += 1; } /*if (/\W{1,}/.test(text)) { strength += 1; }*/ if (this.state.strength != strength) { this.setState({ password: text, strength: strength }); } else { this.setState({ password: text }); } } changeInfo(key, value) { var info = this.state.userInfo; info[key] = value; this.setState({ 'userInfo': info }); } changeTab(type) { this.setState({ isFleetDriver: type }) } getCountryList() { GetCountryList(list => { this.setState({ countryNums: list }) }) } getCompanyList() { apiUser.getConmpany().then(res => { if (res.data) { this.setState({ companyList: res.data }) } }).catch(err => [ toastShort(err) ]) } onRegister() { //console.log('sign up', this.state); var info = this.state.userInfo; if (!info.nickName) { toastShort('Please enter display name'); return; } if (!info.email) { toastShort('Please enter email address'); return; } if (!/^[a-zA-Z0-9]+[\S]+@[a-zA-Z0-9_-]+[\.][\Sa-zA-Z]+$/.test(info.email)) { toastShort('Email is incorrect format'); return; } if (!info.phone) { toastShort('Please enter contact number'); return; } if (!/^\d{6,15}$/.test(info.phone)) { toastShort('Phone Number is incorrect format'); return; } if (!this.state.password) { toastShort('Please enter password'); return; } if (this.state.strength < 3) { toastShort('Password is not strong'); return; } if (!info.password) { toastShort('Please enter confirm password'); return; } if (info.password != this.state.password) { toastShort('The twice passwords are inconsistent'); if (this.state.wrongCount < 3) { this.setState({ wrongCount: this.state.wrongCount + 1 }) } return; } if (this.state.isFleetDriver) { if (!info.pdvLicence) { toastShort('Please enter PDV Licence'); return; } if (this.state.pdvImages[0] == '' || this.state.pdvImages[1] == '') { toastShort('Please upload PDV Licence Photos'); return; } } let param = Object.assign({}, info); //param.phone = this.state.countryNum + info.phone param.callingCode = this.state.countryNum; if (this.state.isFleetDriver) { param.userType = 'Driver'; param.pdvLicencePictures = this.state.pdvImages; param.fleetCompanyId = this.state.fleetCompanyId; } else { param.userType = 'Public'; } console.log('params', param); Dialog.showProgressDialog(); apiUser.register(param).then(res => { Dialog.dismissLoading(); //toastShort('Sign up successfully!'); this.setState({ email: param.email, visible: true }); //this.backToLogin(); }).catch(err => { toastShort(err); Dialog.dismissLoading(); }); } getBackTopPosition() { return isIOS ? statusHeight - 16 : 8; } backToLogin() { if (this.state.params.actionLogin) { goBack() startPage(PageList.login); } else { goBack(); } } uploadImage(index) { ImagePicker.openPicker(options).then(image => { if (image.path) { apiUpload.uploadImage(image.path, image.mime, 'PDVL').then(res => { if (res.success && res.data.picturePath) { let imageUrl = this.state.pdvImages; imageUrl[index] = res.data.picturePath; this.setState({ pdvImages: imageUrl }); } else { toastShort('Upload failed, please retry'); } }).catch(err => { toastShort(err); }); } }).catch(err => { //console.log(err); }); } changeAgree(ag) { this.setState({ agree: ag }) } hideDialog() { this.setState({ visible: false }); this.backToLogin(); } render() { return ( this.changeTab(false)} >Public Users this.changeTab(true)} >Fleet/PH Drivers Registration Display Name this.changeInfo('nickName', v)} /> Email Address this.changeInfo('email', v)} /> Phone Number {"+" + this.state.countryNum} { this.setState({ countryNum: value }) }} customerItemView={ (item, index, onClick) => }/> this.changeInfo('phone', v)} /> Create Password { this.applyStrength(value); }} /> Password Strength Your Password Must Have: - 8 or more characters {/* - upper and lower case letters */} - at least one number Confirm Password this.changeInfo('password', v)} /> { this.state.isFleetDriver && <> Your Company { this.setState({ fleetCompanyId: value }) }}/> {'PDV Licence'} this.changeInfo('pdvLicence', v)} /> {' PDV Photos\n(Front & Back)'} { this.state.pdvImages.map((item, index) => ( this.uploadImage(index)} url={item}/> )) } } Have a referral code? You'll get $5 Credit as registration bonus! Referral Code this.changeInfo('referralCode', v)} /> this.changeAgree(v)} /> this.changeAgree(!this.state.agree)}> {'I have read and I agree with the '} startPage(PageList.condition)}>Terms of Use {' '} {'and '} startPage(PageList.privacy)}>Privacy Policy .