userCenter.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * 个人中心页面
  3. */
  4. import React, { Component } from 'react';
  5. import {
  6. Platform,
  7. StyleSheet,
  8. Text,
  9. View,
  10. Image,
  11. TouchableOpacity,
  12. ImageBackground,
  13. Button,
  14. StatusBar,
  15. Modal,
  16. TouchableHighlight,
  17. DeviceEventEmitter,
  18. ScrollView,
  19. BackHandler
  20. } from 'react-native';
  21. import BasePage from './BasePage';
  22. import Dimensions from './utils/dimensions';
  23. import ShopBox from './components/ShopBox';
  24. import TopicTitle from './components/TopicTitle';
  25. import ScrollRow from './components/ScrollRow';
  26. import CourseTitle from './components/CourseTitle';
  27. import user from './services/user';
  28. import commonUtil from './utils/commonutil';
  29. import http_showcase from '../pages/services/showcase';
  30. export default class userCenter extends BasePage {
  31. componentDidMount() {
  32. this.getUCENTER_RECOMMEND();
  33. //触发更新
  34. this.refreshSubScription = DeviceEventEmitter.addListener('infoback', () => {
  35. user.userMember().then((res) => {
  36. console.log('个人列表', res);
  37. // 收藏
  38. const favoritesList = res.data.favoritesList;
  39. //观看记录
  40. const playLogList = res.data.playLogList;
  41. // 用户消息
  42. const user = res.data.user;
  43. // VIP
  44. const vip = res.data.vip;
  45. this.setState({
  46. favoritesList,
  47. playLogList,
  48. user,
  49. vip
  50. });
  51. });
  52. });
  53. BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
  54. DeviceEventEmitter.emit('infoback');
  55. }
  56. componentWillUnmount() {
  57. this.refreshSubScription.remove();
  58. }
  59. state = {
  60. nickName: '初始昵称',
  61. user: {},
  62. ifDiscount: true,
  63. isVIP: false,
  64. btnArr: [
  65. {
  66. title: '订单',
  67. icon: require('./images/userCenter/order.png'),
  68. goTo: 'Order'
  69. },
  70. {
  71. title: '抵用券',
  72. icon: require('./images/userCenter/discount.png'),
  73. goTo: 'Ticket'
  74. },
  75. {
  76. title: '客服',
  77. icon: require('./images/userCenter/service.png'),
  78. goTo: 'Phone'
  79. }
  80. ],
  81. shopData: [
  82. {
  83. title: '1个月',
  84. originPrice: '199',
  85. price: '49',
  86. background: require('./images/shopBox/left.png')
  87. },
  88. {
  89. title: '12个月',
  90. originPrice: '499',
  91. price: '199',
  92. background: require('./images/shopBox/right.png')
  93. }
  94. ],
  95. discount: {
  96. title: '限时秒杀',
  97. icon: { uri: 'null' }
  98. },
  99. favoritesList: [],
  100. playLogList: [],
  101. vip: false
  102. };
  103. renderBtn = (item, index) => {
  104. return (
  105. <TouchableOpacity
  106. key={index}
  107. onPress={() => this.goTo(`${item.goTo}`)}
  108. style={{ display: 'flex', justifyContent: 'space-between' }}
  109. >
  110. <View style={styles.btnItem}>
  111. <Image source={item.icon} style={styles.btnIcon} />
  112. <Text style={styles.btnTitle}>{item.title}</Text>
  113. </View>
  114. </TouchableOpacity>
  115. );
  116. };
  117. goBack() {
  118. DeviceEventEmitter.emit('indexInfo');
  119. //返回上一页
  120. this.props.navigation.goBack();
  121. }
  122. getUCENTER_RECOMMEND() {
  123. http_showcase.getUCENTER_RECOMMEND().then((res) => {
  124. console.log('====================================');
  125. console.log('res', res.data[0].boothContent);
  126. console.log('====================================');
  127. this.setState({
  128. discount: {
  129. title: res.data[0].title,
  130. icon: { uri: res.data[0].boothContent }
  131. }
  132. });
  133. });
  134. }
  135. render() {
  136. return (
  137. <ScrollView style={{ height: 1100, overflow: 'scroll', backgroundColor: '#fff' }}>
  138. <View style={styles.topSection}>
  139. <ImageBackground
  140. source={require('./images/userCenter/top-bg.png')}
  141. style={{ width: '100%', height: 203 }}
  142. >
  143. <StatusBar
  144. backgroundColor={'transparent'}
  145. barStyle={'dark-content'}
  146. // backgroundColor={"white"}
  147. translucent={true}
  148. hidden={false}
  149. />
  150. <View
  151. style={{
  152. height: 30,
  153. // backgroundColor: "white"
  154. marginTop: 20
  155. }}
  156. >
  157. <CourseTitle
  158. width={this.getWindowWidth()}
  159. title="个人中心"
  160. lefttype={2}
  161. righttype={2}
  162. textcolor={'#fff'}
  163. backPress={() => this.goBack()}
  164. // backgroundColor={"transparent"}
  165. rightPress={() => this.toNextPage('PersonalInfo')}
  166. />
  167. </View>
  168. <View style={styles.userInfo}>
  169. <TouchableOpacity onPress={() => this.goTo(`PersonalInfo`)}>
  170. <Image style={styles.userAvatar} source={{ uri: this.state.user.avatar }} />
  171. </TouchableOpacity>
  172. <View style={styles.userRight}>
  173. <View style={styles.userName}>
  174. <Text style={styles.userNameText}>{this.state.user.nickName}</Text>
  175. {this.state.vip ? (
  176. <Image style={styles.vipTag} source={require('./images/common/vip.png')} />
  177. ) : null}
  178. </View>
  179. {this.state.vip ? null : (
  180. <View style={styles.userName}>
  181. <Text style={styles.vipSologan}>开通vip</Text>
  182. </View>
  183. )}
  184. </View>
  185. </View>
  186. <View style={styles.btnBoxWrapper}>
  187. <View style={styles.btnBox}>
  188. {this.state.btnArr.map((item, index) => this.renderBtn(item, index))}
  189. </View>
  190. </View>
  191. </ImageBackground>
  192. </View>
  193. <View style={styles.discountSection}>
  194. <ShopBox
  195. data={this.state.shopData}
  196. discount={this.state.discount}
  197. nav={this.props.navigation.navigate}
  198. />
  199. </View>
  200. <View style={styles.recordSection}>
  201. <TopicTitle title={'观看记录'} ifTubeShow={true} />
  202. <ScrollRow itemWidth={106} itemHeight={153} data={this.state.playLogList} />
  203. </View>
  204. <View style={styles.collectSection}>
  205. <TopicTitle title={'我的收藏'} ifTubeShow={true} />
  206. <ScrollRow itemWidth={106} itemHeight={150} data={this.state.favoritesList} />
  207. </View>
  208. </ScrollView>
  209. );
  210. }
  211. goTo(index) {
  212. if (index === 'Phone') {
  213. commonUtil.callPhone('.......');
  214. } else {
  215. this.toNextPage(index);
  216. }
  217. }
  218. componentWillUnmount() {
  219. BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
  220. }
  221. onBackAndroid = () => {
  222. this.goBack();
  223. return true;
  224. };
  225. }
  226. const styles = StyleSheet.create({
  227. topSection: {
  228. height: 250,
  229. width: Dimensions.width
  230. // backgroundColor: 'red'
  231. },
  232. userInfo: {
  233. width: Dimensions.width,
  234. height: 70,
  235. flexDirection: 'row',
  236. justifyContent: 'flex-start',
  237. alignItems: 'center'
  238. },
  239. userAvatar: {
  240. width: 67,
  241. height: 67,
  242. borderRadius: 55,
  243. marginHorizontal: 12
  244. },
  245. userRight: {
  246. flexDirection: 'column'
  247. },
  248. userName: {
  249. flexDirection: 'row',
  250. alignItems: 'center'
  251. },
  252. userNameText: {
  253. fontSize: 18,
  254. color: '#fff',
  255. fontWeight: '500',
  256. marginRight: 9
  257. },
  258. vipSologan: {
  259. fontSize: 14,
  260. color: '#fff'
  261. },
  262. btnBoxWrapper: {
  263. width: Dimensions.width,
  264. alignItems: 'center',
  265. marginTop: 16
  266. },
  267. btnBox: {
  268. width: Dimensions.width * 343 / 375,
  269. height: 100,
  270. borderRadius: 10,
  271. shadowColor: '#000',
  272. // shadowOffset: 1,
  273. shadowOpacity: 2,
  274. shadowRadius: 5,
  275. elevation: 4,
  276. backgroundColor: '#fff',
  277. justifyContent: 'space-around',
  278. flexDirection: 'row'
  279. },
  280. btnItem: {
  281. height: '100%',
  282. flexDirection: 'column',
  283. justifyContent: 'center',
  284. alignItems: 'center'
  285. },
  286. btnIcon: {
  287. width: 36,
  288. height: 24,
  289. marginBottom: 7
  290. },
  291. btnTitle: {
  292. color: '#3f3f3f',
  293. fontSize: 16
  294. },
  295. discountSection: {
  296. width: Dimensions.width
  297. // height: 242,
  298. // backgroundColor: 'green'
  299. },
  300. recordSection: {
  301. width: Dimensions.width,
  302. height: 235
  303. // backgroundColor: 'blue'
  304. },
  305. collectSection: {
  306. width: Dimensions.width,
  307. height: 255,
  308. marginBottom: 20
  309. // backgroundColor: 'yellow'
  310. }
  311. });