userCenter.js 6.9 KB

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