userCenter.js 7.2 KB

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