MembersList.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /**
  2. * 我的会员列表页面
  3. * @邠心vbe on 2023/07/14
  4. */
  5. import React, { Component } from 'react';
  6. import { View, Text, StyleSheet, Pressable, Image } from 'react-native';
  7. import apiMember from '../../api/apiMember';
  8. import { ElevationObject } from '../../components/Button';
  9. import Dialog from '../../components/Dialog';
  10. import TextView from '../../components/TextView';
  11. import utils from '../../utils/utils';
  12. import VbeSkeleton from '../../components/VbeSkeleton';
  13. export default class MembersList extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. loading: true,
  18. memberList: [],
  19. loadingList: ["", "", "", ""]
  20. };
  21. }
  22. componentDidMount() {
  23. this.props.navigation.addListener('focus', () => {
  24. if (!this.state.loading) {
  25. this.getMyMemberList();
  26. }
  27. })
  28. setTimeout(() => {
  29. this.getMyMemberList();
  30. }, 500);
  31. }
  32. getMyMemberList() {
  33. apiMember.getMyMemberList().then(res => {
  34. if (res.data) {
  35. this.setState({
  36. memberList: res.data
  37. });
  38. } else {
  39. this.setState({
  40. memberList: []
  41. });
  42. }
  43. }).catch(err => {
  44. this.setState({
  45. memberList: []
  46. });
  47. toastShort(err)
  48. }).finally(() => {
  49. this.setState({
  50. loading: false
  51. });
  52. });
  53. }
  54. getMembershipStatus(status) {
  55. switch (status) {
  56. case "Pending":
  57. return $t("members.statusPending");
  58. case "Approved":
  59. return $t("members.statusApproved");
  60. case "Pass":
  61. return $t("members.statusApproved");
  62. case "Rejected":
  63. return $t("members.statusRejected");
  64. default:
  65. return $t("charging.statusUnavailable");
  66. }
  67. }
  68. onDeleteMember(item) {
  69. Dialog.showDialog({
  70. title: $t("members.deleteMember"),
  71. message: $t("members.confirmDelete"),
  72. ok: $t("nav.yes"),
  73. cancel: $t("nav.no"),
  74. callback: btn => {
  75. if (btn == Dialog.BUTTON_OK) {
  76. this.deleteMembers(item.membershipId)
  77. }
  78. }
  79. })
  80. }
  81. deleteMembers(id) {
  82. //Dialog.showProgressDialog();
  83. apiMember.delMembers(id).then(res => {
  84. toastShort($t("common.deleteSuccess"))
  85. this.getMyMemberList();
  86. }).catch(err => {
  87. toastShort(err)
  88. })
  89. }
  90. render() {
  91. if (this.state.loading) {
  92. return (
  93. <View style={styles.container}>
  94. { this.state.loadingList.map((item, index) =>
  95. <View style={styles.loadingView} key={index}>
  96. <VbeSkeleton
  97. style={ui.flex1}
  98. layout={[
  99. {width: '50%', height: 20},
  100. {width: '100%', height: 15, marginTop: 6},
  101. {width: '60%', height: 15, marginTop: 6}
  102. ]}
  103. animationDirection={"horizontalRight"}
  104. />
  105. <VbeSkeleton
  106. style={styles.loadingIcon}
  107. layout={[
  108. {width: 48, height: 48, borderRadius: 6}
  109. ]}
  110. animationDirection={"horizontalRight"}
  111. />
  112. </View>
  113. )}
  114. </View>
  115. )
  116. }
  117. return (
  118. <View style={styles.container}>
  119. { this.state.memberList.length > 0
  120. ? this.state.memberList.map((item, index) => (
  121. <Pressable
  122. key={index}
  123. style={styles.memberView}
  124. onPress={() => {
  125. if (item.membershipStatus == "Rejected") {
  126. this.onDeleteMember(item)
  127. }
  128. //startPage(PageList.editVehicle, {id: item.vehiclePk});
  129. }}>
  130. <View style={styles.itemBackground}>
  131. { utils.isNotEmpty(item.groupLogo)
  132. ? <Image
  133. source={{uri: utils.getImageUrl(item.groupLogo)}}
  134. resizeMode="contain"
  135. style={styles.groupLogo}/>
  136. : <MaterialIcons
  137. name="card-membership"
  138. color={colorAccent}
  139. style={styles.groupIcon}
  140. size={52}/>
  141. }
  142. </View>
  143. <View style={styles.memberItem}>
  144. { utils.isEmpty(item.groupType)
  145. ? <TextView style={styles.textLabel2}>{$t('members.membership')}:</TextView>
  146. : <TextView style={styles.textType}>{item.groupType}</TextView>
  147. }
  148. <TextView
  149. style={styles.textValue2}
  150. numberOfLines={1}>{item.membership}</TextView>
  151. </View>
  152. <View style={styles.memberItem}>
  153. <TextView style={styles.textLabel}>{$t('members.membershipNo')}:</TextView>
  154. <TextView style={styles.textValue}>{item.membershipNo}</TextView>
  155. </View>
  156. <View style={styles.memberItem}>
  157. <TextView style={styles.textLabel}>{$t('members.status')}:</TextView>
  158. { item.membershipStatus == "Rejected"
  159. ? <TextView style={[styles.textValue, styles.statusRed]}>{this.getMembershipStatus(item.membershipStatus)}</TextView>
  160. : <TextView style={styles.textValue}>{this.getMembershipStatus(item.membershipStatus)}</TextView>
  161. }
  162. </View>
  163. </Pressable>
  164. ))
  165. : <Text style={ui.noData}>{$t('members.noData')}</Text>
  166. }
  167. </View>
  168. );
  169. }
  170. }
  171. const styles = StyleSheet.create({
  172. container: {
  173. flex: 1,
  174. backgroundColor: pageBackground
  175. },
  176. loadingView: {
  177. padding: 16,
  178. borderRadius: 8,
  179. borderColor: '#F0F0F0',
  180. borderWidth: 1,
  181. alignItems: 'flex-end',
  182. backgroundColor: colorLight,
  183. flexDirection: 'row',
  184. ...$margin(16, 16, 0)
  185. },
  186. memberView: {
  187. borderRadius: 8,
  188. overflow: 'hidden',
  189. ...ElevationObject(5),
  190. ...$margin(16, 16, 0),
  191. ...$padding(16),
  192. backgroundColor: colorLight
  193. },
  194. memberItem: {
  195. paddingTop: 1,
  196. paddingBottom: 1,
  197. alignItems: 'center',
  198. flexDirection: 'row'
  199. },
  200. textLabel: {
  201. color: textPrimary,
  202. fontSize: 14,
  203. paddingRight: 6,
  204. fontWeight: 'bold'
  205. },
  206. textValue: {
  207. flex: 1,
  208. color: textPrimary,
  209. fontSize: 14
  210. },
  211. textLabel2: {
  212. color: textPrimary,
  213. fontSize: 16,
  214. paddingRight: 5,
  215. marginBottom: 2,
  216. fontWeight: 'bold'
  217. },
  218. textValue2: {
  219. flex: 1,
  220. color: textPrimary,
  221. fontSize: 16,
  222. fontWeight: 'bold',
  223. marginBottom: 2
  224. },
  225. statusRed: {
  226. color: "#FF2222"
  227. },
  228. textType: {
  229. color: textLight,
  230. fontSize: 10,
  231. marginRight: 4,
  232. borderRadius: 2,
  233. ...$padding(1, 4),
  234. backgroundColor: colorAccent
  235. },
  236. itemBackground: {
  237. right: 0,
  238. bottom: 0,
  239. position: 'absolute'
  240. },
  241. groupIcon: {
  242. margin: 4,
  243. opacity: 0.08
  244. },
  245. groupLogo: {
  246. width: 48,
  247. height: 48,
  248. margin: 8,
  249. opacity: .8,
  250. borderRadius: 6
  251. },
  252. loadingIcon: {
  253. width: 48,
  254. height: 48,
  255. marginLeft: 16
  256. }
  257. })