ApplyMember.js 6.2 KB

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