ApplyMember.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /**
  2. * 申请会员页面
  3. * @邠心vbe on 2023/07/14
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, TextInput, ScrollView } from 'react-native';
  7. import apiMember from '../../api/apiMember';
  8. import apiUpload from '../../api/apiUpload';
  9. import { GetCountryList } from '../../components/CountryIcon';
  10. import Dropdown from '../../components/Dropdown';
  11. import { UploadThemes } from '../../components/ThemesConfig';
  12. import { UploadView } from '../sign/RegisterDriver';
  13. import ImagePicker from 'react-native-image-crop-picker';
  14. import CheckBoxText from '../../components/CheckBoxText';
  15. import Button from '../../components/Button';
  16. import TextView from '../../components/TextView';
  17. const options = {
  18. width: 300,
  19. height: 200,
  20. cropping: true,
  21. multiple: false,
  22. mediaType: 'photo',
  23. writeTempFile: false,
  24. compressImageQuality: 0.8,
  25. compressImageMaxWidth: 720,
  26. compressImageMaxHeight: 1280,
  27. ...UploadThemes
  28. }
  29. export default class ApplyMember extends Component {
  30. constructor(props) {
  31. super(props);
  32. this.state = {
  33. agree: true,
  34. groupList: [],
  35. memberForm: {
  36. groupPk: "",
  37. membershipNo: "",
  38. cardFront: ""
  39. },
  40. isFleet: false
  41. };
  42. }
  43. componentDidMount() {
  44. //console.log(this.state.params);
  45. //this.getCountryList();
  46. this.getGroupList();
  47. }
  48. changeForm(key, value) {
  49. const form = {...this.state.memberForm};
  50. form[key] = value;
  51. this.setState({
  52. memberForm: form
  53. })
  54. }
  55. changeGroup(value, index) {
  56. const group = this.state.groupList[index];
  57. this.setState({
  58. isFleet: group?.groupType == "FLEET"
  59. })
  60. this.changeForm("groupPk", value);
  61. }
  62. getCountryList() {
  63. GetCountryList(list => {
  64. this.setState({
  65. countryNums: list
  66. })
  67. })
  68. }
  69. getGroupList() {
  70. apiMember.getMembersOption().then(res => {
  71. if (res.data) {
  72. this.setState({
  73. groupList: res.data
  74. })
  75. }
  76. }).catch(err => [
  77. toastShort(err)
  78. ])
  79. }
  80. uploadImage() {
  81. ImagePicker.openPicker({
  82. ...options,
  83. cropperToolbarTitle: $t('common.cropperTitle')
  84. }).then(image => {
  85. if (image.path) {
  86. apiUpload.uploadImage(image.path, image.mime, 'MEMBERSHIP').then(res => {
  87. if (res.success && res.data.picturePath) {
  88. this.changeForm("cardFront", res.data.picturePath)
  89. toastShort($t('common.uploadSuccess'));
  90. } else {
  91. toastShort($t('common.uploadFailed'));
  92. }
  93. }).catch(err => {
  94. toastShort(err);
  95. });
  96. }
  97. }).catch(err1 => {
  98. //console.log(err1);
  99. });
  100. }
  101. changeAgree(ag) {
  102. this.setState({
  103. agree: ag
  104. })
  105. }
  106. onApplyMember() {
  107. if (!this.state.memberForm.membershipNo) {
  108. toastShort($t('members.errMembershipNo'));
  109. return;
  110. }
  111. if (!this.state.memberForm.cardFront) {
  112. toastShort($t('members.errUploadCard'));
  113. return;
  114. }
  115. console.log('params', this.state.memberForm);
  116. Dialog.showProgressDialog();
  117. apiMember.applyMembers(this.state.memberForm).then(res => {
  118. Dialog.dismissLoading();
  119. toastLong(res.msg ?? $t('common.submitSuccess'));
  120. goBack();
  121. }).catch(err => {
  122. toastLong(err);
  123. Dialog.dismissLoading();
  124. })
  125. }
  126. render() {
  127. return (
  128. <View style={styles.container}>
  129. <ScrollView style={styles.applyForm}>
  130. <View style={styles.formItem}>
  131. <TextView style={styles.inputLabel}>{$t('members.membership')}</TextView>
  132. <Dropdown
  133. style={styles.selectView}
  134. textStyle={styles.selectText}
  135. title={$t('members.membership')}
  136. list={this.state.groupList}
  137. value={this.state.memberForm.groupPk}
  138. valueKey='groupPk'
  139. nameKey='groupName'
  140. onChange={(value, index)=> this.changeGroup(value, index)}/>
  141. </View>
  142. <View style={styles.formItem}>
  143. <TextView style={styles.inputLabel}>{$t("members.labelMemberLicenceNo")}
  144. {/*this.state.isFleet ? $t('members.labelPHVNo') : $t('members.membershipNo')*/}
  145. </TextView>
  146. <TextInput
  147. style={styles.inputView}
  148. allowFontScaling={false}
  149. placeholder={$t('members.placeLast4Digits')}
  150. placeholderTextColor={textPlacehoder}
  151. maxLength={4}
  152. //keyboardType='phone-pad'
  153. onChangeText={v => this.changeForm('membershipNo', v)}
  154. />
  155. </View>
  156. <View style={styles.formItem}>
  157. <TextView style={styles.inputLabel}>
  158. {this.state.isFleet ? $t('members.labelPDVPhotos') : $t('members.labelUpload')}
  159. </TextView>
  160. <View style={styles.uploadGroup}>
  161. <UploadView
  162. style={styles.uploadView}
  163. imageStyle={styles.uploadImage}
  164. onPress={() => this.uploadImage()}
  165. url={this.state.memberForm.cardFront}/>
  166. </View>
  167. </View>
  168. <View style={styles.formItem}>
  169. <TextView style={styles.inputLabel}>{$t('members.labelRequirement')}</TextView>
  170. <TextView style={styles.contentView}>{$t('members.contentRequirement')}</TextView>
  171. </View>
  172. </ScrollView>
  173. <View style={styles.agreeView}>
  174. <View style={ui.flex}>
  175. <CheckBoxText
  176. value={this.state.agree}
  177. text={$t('sign.agreePDVInfoAccurate')}
  178. textStyle={styles.agreeText}
  179. onValueChange={v => this.changeAgree(v)}
  180. />
  181. </View>
  182. <Button
  183. style={styles.submitButton}
  184. elevation={1.5}
  185. disabled={!this.state.agree}
  186. text={$t('nav.submit')}
  187. fontSize={14}
  188. onClick={() => {
  189. this.onApplyMember();
  190. }}
  191. />
  192. </View>
  193. </View>
  194. );
  195. }
  196. }
  197. const styles = StyleSheet.create({
  198. container: {
  199. flex: 1,
  200. backgroundColor: colorLight
  201. },
  202. applyForm: {
  203. flex: 1,
  204. paddingLeft: 16,
  205. paddingRight: 16
  206. },
  207. formItem: {
  208. marginTop: 16,
  209. alignItems: 'center',
  210. flexDirection: 'row'
  211. },
  212. inputLabel: {
  213. flex: 1,
  214. color: textPrimary,
  215. fontSize: 14,
  216. marginRight: 4
  217. },
  218. inputView: {
  219. flex: 2,
  220. color: textPrimary,
  221. fontSize: 14,
  222. borderRadius: 5,
  223. minHeight: 40,
  224. paddingTop: 6,
  225. paddingLeft: 12,
  226. paddingRight: 12,
  227. paddingBottom: 6,
  228. backgroundColor: '#F5F5F5'
  229. },
  230. selectView: {
  231. flex: 2,
  232. borderRadius: 5,
  233. minHeight: 40,
  234. paddingLeft: 12,
  235. paddingRight: 12,
  236. alignItems: 'center',
  237. flexDirection: 'row',
  238. backgroundColor: '#F5F5F5'
  239. },
  240. contentView: {
  241. flex: 2,
  242. color: textPrimary,
  243. fontSize: 14
  244. },
  245. selectText: {
  246. flex: 1,
  247. color: textPrimary,
  248. fontSize: 14
  249. },
  250. uploadGroup: {
  251. flex: 2,
  252. marginLeft: -16,
  253. alignItems: 'center',
  254. flexDirection: 'row'
  255. },
  256. uploadView: {
  257. //flex: 1,
  258. alignItems: 'center'
  259. },
  260. uploadImage: {
  261. width: $vw(28),
  262. height: $vw(18.7),
  263. borderRadius: 6
  264. },
  265. agreeView: {
  266. padding: 16,
  267. },
  268. agreeText: {
  269. flex: 1,
  270. color: textPrimary,
  271. fontSize: 14,
  272. paddingTop: 2,
  273. paddingLeft: 4,
  274. paddingBottom: 2
  275. },
  276. submitButton: {
  277. marginTop: 16,
  278. marginBottom: 8
  279. }
  280. })