ApplyMember.js 7.4 KB

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