ApplyMember.js 6.6 KB

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