userCenter.js 8.6 KB

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