ApplyMember.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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.selectView}
  125. textStyle={styles.selectText}
  126. title={$t('members.membership')}
  127. list={this.state.groupList}
  128. value={this.state.memberForm.groupPk}
  129. valueKey='groupPk'
  130. nameKey='groupName'
  131. onChange={(value, index)=> {
  132. this.changeForm("groupPk", value);
  133. }}/>
  134. </View>
  135. <View style={styles.formItem}>
  136. <Text style={styles.inputLabel}>{$t('members.membershipNo')}</Text>
  137. <TextInput
  138. style={styles.inputView}
  139. placeholder={$t('members.membershipNo')}
  140. placeholderTextColor={textPlacehoder}
  141. maxLength={50}
  142. keyboardType='phone-pad'
  143. onChangeText={v => this.changeForm('membershipNo', v)}
  144. />
  145. </View>
  146. <View style={styles.formItem}>
  147. <Text style={styles.inputLabel}>{$t('members.labelUpload')}</Text>
  148. <View style={styles.uploadGroup}>
  149. <UploadView
  150. style={styles.uploadView}
  151. imageStyle={styles.uploadImage}
  152. onPress={() => this.uploadImage()}
  153. url={this.state.memberForm.cardFront}/>
  154. </View>
  155. </View>
  156. </View>
  157. <View style={styles.agreeView}>
  158. <View style={styles.formItem}>
  159. <CheckBoxText
  160. value={this.state.agree}
  161. text={$t('sign.agreePDVInfoAccurate')}
  162. textStyle={styles.agreeText}
  163. onValueChange={v => this.changeAgree(v)}
  164. />
  165. </View>
  166. <Button
  167. style={styles.submitButton}
  168. elevation={1.5}
  169. disabled={!this.state.agree}
  170. text={$t('nav.submit')}
  171. fontSize={14}
  172. onClick={() => {
  173. this.onApplyMember();
  174. }}
  175. />
  176. </View>
  177. </View>
  178. );
  179. }
  180. }
  181. const styles = StyleSheet.create({
  182. container: {
  183. flex: 1,
  184. backgroundColor: colorLight
  185. },
  186. applyForm: {
  187. flex: 1,
  188. paddingLeft: 16,
  189. paddingRight: 16
  190. },
  191. formItem: {
  192. marginTop: 16,
  193. alignItems: 'center',
  194. flexDirection: 'row'
  195. },
  196. inputLabel: {
  197. flex: 1,
  198. color: textPrimary,
  199. fontSize: 14,
  200. marginRight: 4
  201. },
  202. inputView: {
  203. flex: 2,
  204. color: textPrimary,
  205. fontSize: 14,
  206. borderRadius: 5,
  207. minHeight: 40,
  208. paddingTop: 6,
  209. paddingLeft: 12,
  210. paddingRight: 12,
  211. paddingBottom: 6,
  212. backgroundColor: '#F5F5F5'
  213. },
  214. selectView: {
  215. flex: 2,
  216. borderRadius: 5,
  217. minHeight: 40,
  218. paddingLeft: 12,
  219. paddingRight: 12,
  220. alignItems: 'center',
  221. flexDirection: 'row',
  222. backgroundColor: '#F5F5F5'
  223. },
  224. selectText: {
  225. flex: 1,
  226. color: textPrimary,
  227. fontSize: 14
  228. },
  229. uploadGroup: {
  230. flex: 2,
  231. marginLeft: -16,
  232. alignItems: 'center',
  233. flexDirection: 'row'
  234. },
  235. uploadView: {
  236. //flex: 1,
  237. alignItems: 'center'
  238. },
  239. uploadImage: {
  240. width: $vw(28),
  241. height: $vw(18.7),
  242. borderRadius: 6
  243. },
  244. agreeView: {
  245. padding: 16,
  246. },
  247. agreeText: {
  248. flex: 1,
  249. color: textPrimary,
  250. fontSize: 14,
  251. paddingTop: 2,
  252. paddingLeft: 4,
  253. paddingBottom: 2
  254. },
  255. submitButton: {
  256. marginTop: 16,
  257. marginBottom: 8
  258. }
  259. })