userCenter.js 6.5 KB

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