userCenter.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. DeviceEventEmitter.emit('indexInfo');
  117. //返回上一页
  118. this.props.navigation.goBack();
  119. }
  120. getUCENTER_RECOMMEND() {
  121. http_showcase.getUCENTER_RECOMMEND().then((res) => {
  122. console.log('====================================');
  123. console.log('res', res.data[0].boothContent);
  124. console.log('====================================');
  125. this.setState({
  126. discount: {
  127. title: res.data[0].title,
  128. icon: { uri: res.data[0].boothContent }
  129. }
  130. });
  131. });
  132. }
  133. render() {
  134. return (
  135. <ScrollView style={{ height: 1100, overflow: 'scroll', backgroundColor: '#fff' }}>
  136. <View style={styles.topSection}>
  137. <ImageBackground
  138. source={require('./images/userCenter/top-bg.png')}
  139. style={{ width: '100%', height: 203 }}
  140. >
  141. <StatusBar
  142. backgroundColor={'transparent'}
  143. barStyle={'dark-content'}
  144. // backgroundColor={"white"}
  145. translucent={true}
  146. hidden={false}
  147. />
  148. <View
  149. style={{
  150. height: 30,
  151. // backgroundColor: "white"
  152. marginTop: 20
  153. }}
  154. >
  155. <CourseTitle
  156. width={this.getWindowWidth()}
  157. title="个人中心"
  158. lefttype={2}
  159. righttype={2}
  160. textcolor={'#fff'}
  161. backPress={() => this.goBack()}
  162. // backgroundColor={"transparent"}
  163. rightPress={() => this.toNextPage('PersonalInfo')}
  164. />
  165. </View>
  166. <View style={styles.userInfo}>
  167. <TouchableOpacity onPress={() => this.goTo(`PersonalInfo`)}>
  168. <Image style={styles.userAvatar} source={{ uri: this.state.user.avatar }} />
  169. </TouchableOpacity>
  170. <View style={styles.userRight}>
  171. <View style={styles.userName}>
  172. <Text style={styles.userNameText}>{this.state.user.nickName}</Text>
  173. {this.state.vip ? (
  174. <Image style={styles.vipTag} source={require('./images/common/vip.png')} />
  175. ) : null}
  176. </View>
  177. {this.state.vip ? null : (
  178. <View style={styles.userName}>
  179. <Text style={styles.vipSologan}>开通vip</Text>
  180. </View>
  181. )}
  182. </View>
  183. </View>
  184. <View style={styles.btnBoxWrapper}>
  185. <View style={styles.btnBox}>
  186. {this.state.btnArr.map((item, index) => this.renderBtn(item, index))}
  187. </View>
  188. </View>
  189. </ImageBackground>
  190. </View>
  191. <View style={styles.discountSection}>
  192. <ShopBox
  193. data={this.state.shopData}
  194. discount={this.state.discount}
  195. nav={this.props.navigation.navigate}
  196. />
  197. </View>
  198. <View style={styles.recordSection}>
  199. <TopicTitle title={'观看记录'} ifTubeShow={true} />
  200. <ScrollRow itemWidth={106} itemHeight={153} data={this.state.playLogList} />
  201. </View>
  202. <View style={styles.collectSection}>
  203. <TopicTitle title={'我的收藏'} ifTubeShow={true} />
  204. <ScrollRow itemWidth={106} itemHeight={150} data={this.state.favoritesList} />
  205. </View>
  206. </ScrollView>
  207. );
  208. }
  209. goTo(index) {
  210. if (index === 'Phone') {
  211. commonUtil.callPhone('.......');
  212. } else {
  213. this.toNextPage(index);
  214. }
  215. }
  216. }
  217. const styles = StyleSheet.create({
  218. topSection: {
  219. height: 250,
  220. width: Dimensions.width
  221. // backgroundColor: 'red'
  222. },
  223. userInfo: {
  224. width: Dimensions.width,
  225. height: 70,
  226. flexDirection: 'row',
  227. justifyContent: 'flex-start',
  228. alignItems: 'center'
  229. },
  230. userAvatar: {
  231. width: 67,
  232. height: 67,
  233. borderRadius: 55,
  234. marginHorizontal: 12
  235. },
  236. userRight: {
  237. flexDirection: 'column'
  238. },
  239. userName: {
  240. flexDirection: 'row',
  241. alignItems: 'center'
  242. },
  243. userNameText: {
  244. fontSize: 18,
  245. color: '#fff',
  246. fontWeight: '500',
  247. marginRight: 9
  248. },
  249. vipSologan: {
  250. fontSize: 14,
  251. color: '#fff'
  252. },
  253. btnBoxWrapper: {
  254. width: Dimensions.width,
  255. alignItems: 'center',
  256. marginTop: 16
  257. },
  258. btnBox: {
  259. width: Dimensions.width * 343 / 375,
  260. height: 100,
  261. borderRadius: 10,
  262. shadowColor: '#000',
  263. // shadowOffset: 1,
  264. shadowOpacity: 2,
  265. shadowRadius: 5,
  266. elevation: 4,
  267. backgroundColor: '#fff',
  268. justifyContent: 'space-around',
  269. flexDirection: 'row'
  270. },
  271. btnItem: {
  272. height: '100%',
  273. flexDirection: 'column',
  274. justifyContent: 'center',
  275. alignItems: 'center'
  276. },
  277. btnIcon: {
  278. width: 36,
  279. height: 24,
  280. marginBottom: 7
  281. },
  282. btnTitle: {
  283. color: '#3f3f3f',
  284. fontSize: 16
  285. },
  286. discountSection: {
  287. width: Dimensions.width
  288. // height: 242,
  289. // backgroundColor: 'green'
  290. },
  291. recordSection: {
  292. width: Dimensions.width,
  293. height: 235
  294. // backgroundColor: 'blue'
  295. },
  296. collectSection: {
  297. width: Dimensions.width,
  298. height: 255,
  299. marginBottom: 20
  300. // backgroundColor: 'yellow'
  301. }
  302. });